| 
									
										
										
										
											2006-08-17 05:42:55 +00:00
										 |  |  | /* Class object implementation (dead now except for methods) */ | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-02 03:12:38 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-07 23:51:28 -06:00
										 |  |  | #include "internal/mem.h"
 | 
					
						
							|  |  |  | #include "internal/pystate.h"
 | 
					
						
							| 
									
										
										
										
											1990-12-20 15:06:42 +00:00
										 |  |  | #include "structmember.h"
 | 
					
						
							| 
									
										
										
										
											1992-08-12 15:35:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-27 21:53:35 +00:00
										 |  |  | #define TP_DESCR_GET(t) ((t)->tp_descr_get)
 | 
					
						
							| 
									
										
										
										
											2001-10-17 20:26:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
  Increase debugging to investige failing tests on some build bots
........
  r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
  Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
  r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
  Correct quotes in NEWS file
........
  r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
  #1750076: Debugger did not step on every iteration of a while statement.
  The mapping between bytecode offsets and source lines (lnotab) did not contain
  an entry for the beginning of the loop.
  Now it does, and the lnotab can be a bit larger:
  in particular, several statements on the same line generate several entries.
  However, this does not bother the settrace function, which will trigger only
  one 'line' event.
  The lnotab seems to be exactly the same as with python2.4.
........
  r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
  Change r60575 broke test_compile:
  there is no need to emit co_lnotab item when both offsets are zeros.
........
  r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
  sync with most recent version from python-mode sf project
........
  r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
  Issue #2004: Use mode 0700 for temporary directories and default
  permissions for missing directories.
  (will backport to 2.5)
........
  r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
  Convert external links to internal links. Fixes #2010.
........
  r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
  Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
  r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
  Update PEP URL.
  (This code is duplicated between pydoc and DocXMLRPCServer; maybe it
  should be refactored as a GHOP project.)
  2.5.2 backport candidate.
........
  r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
  In the experimental 'Scanner' feature, the group count was set wrong.
........
  r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
  Issue 1951. Converts wave test cases to unittest.
........
  r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
  Actually run the test.
........
  r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
  correct object name
........
  r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
  * Use the same code to profile for test_profile and test_cprofile.
  * Convert both to unittest.
  * Use the same unit testing code.
  * Include the expected output in both test files.
  * Make it possible to regenerate the expected output by running
    the file as a script with an '-r' argument.
........
  r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
  Sync-up with Py3k work.
........
  r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
  Limit free list of method and builtin function objects to 256 entries each.
........
  r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
  Unified naming convention for free lists and their limits. All free lists
  in Object/ are named ``free_list``, the counter ``numfree`` and the upper
  limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
  The chances should make it easier to adjust Python for platforms with
  less memory, e.g. mobile phones.
........
											
										 
											2008-02-06 14:31:34 +00:00
										 |  |  | /* Free list for method objects to safe malloc/free overhead
 | 
					
						
							|  |  |  |  * The im_self element is used to chain the elements. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static PyMethodObject *free_list; | 
					
						
							|  |  |  | static int numfree = 0; | 
					
						
							|  |  |  | #ifndef PyMethod_MAXFREELIST
 | 
					
						
							|  |  |  | #define PyMethod_MAXFREELIST 256
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 10:20:37 +02:00
										 |  |  | _Py_IDENTIFIER(__name__); | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  | _Py_IDENTIFIER(__qualname__); | 
					
						
							| 
									
										
										
										
											2011-10-10 18:11:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-05 22:52:50 +00:00
										 |  |  | PyObject * | 
					
						
							|  |  |  | PyMethod_Function(PyObject *im) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (!PyMethod_Check(im)) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ((PyMethodObject *)im)->im_func; | 
					
						
							| 
									
										
										
										
											2001-09-05 22:52:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyMethod_Self(PyObject *im) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (!PyMethod_Check(im)) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ((PyMethodObject *)im)->im_self; | 
					
						
							| 
									
										
										
										
											2001-09-05 22:52:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-27 10:40:20 +00:00
										 |  |  | /* Method objects are used for bound instance methods returned by
 | 
					
						
							|  |  |  |    instancename.methodname. ClassName.methodname returns an ordinary | 
					
						
							|  |  |  |    function. | 
					
						
							| 
									
										
										
										
											1993-05-20 14:24:46 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-02 03:12:38 +00:00
										 |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											2007-11-27 10:40:20 +00:00
										 |  |  | PyMethod_New(PyObject *func, PyObject *self) | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-13 20:18:52 +02:00
										 |  |  |     PyMethodObject *im; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (self == NULL) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     im = free_list; | 
					
						
							|  |  |  |     if (im != NULL) { | 
					
						
							|  |  |  |         free_list = (PyMethodObject *)(im->im_self); | 
					
						
							| 
									
										
										
										
											2013-12-04 09:27:47 +01:00
										 |  |  |         (void)PyObject_INIT(im, &PyMethod_Type); | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |         numfree--; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); | 
					
						
							|  |  |  |         if (im == NULL) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     im->im_weakreflist = NULL; | 
					
						
							|  |  |  |     Py_INCREF(func); | 
					
						
							|  |  |  |     im->im_func = func; | 
					
						
							|  |  |  |     Py_XINCREF(self); | 
					
						
							|  |  |  |     im->im_self = self; | 
					
						
							|  |  |  |     _PyObject_GC_TRACK(im); | 
					
						
							|  |  |  |     return (PyObject *)im; | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-23 18:59:12 +01:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | method_reduce(PyMethodObject *im) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *self = PyMethod_GET_SELF(im); | 
					
						
							|  |  |  |     PyObject *func = PyMethod_GET_FUNCTION(im); | 
					
						
							|  |  |  |     PyObject *builtins; | 
					
						
							|  |  |  |     PyObject *getattr; | 
					
						
							|  |  |  |     PyObject *funcname; | 
					
						
							|  |  |  |     _Py_IDENTIFIER(getattr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     funcname = _PyObject_GetAttrId(func, &PyId___name__); | 
					
						
							|  |  |  |     if (funcname == NULL) { | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     builtins = PyEval_GetBuiltins(); | 
					
						
							|  |  |  |     getattr = _PyDict_GetItemId(builtins, &PyId_getattr); | 
					
						
							|  |  |  |     return Py_BuildValue("O(ON)", getattr, self, funcname); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMethodDef method_methods[] = { | 
					
						
							|  |  |  |     {"__reduce__", (PyCFunction)method_reduce, METH_NOARGS, NULL}, | 
					
						
							|  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-18 03:53:24 +00:00
										 |  |  | /* Descriptors for PyMethod attributes */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-27 10:40:20 +00:00
										 |  |  | /* im_func and im_self are stored in the PyMethod object */ | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | #define MO_OFF(x) offsetof(PyMethodObject, x)
 | 
					
						
							| 
									
										
										
										
											1990-12-20 15:06:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | static PyMemberDef method_memberlist[] = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     {"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED, | 
					
						
							|  |  |  |      "the function (or other callable) implementing a method"}, | 
					
						
							|  |  |  |     {"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED, | 
					
						
							|  |  |  |      "the instance to which a method is bound"}, | 
					
						
							|  |  |  |     {NULL}      /* Sentinel */ | 
					
						
							| 
									
										
										
										
											1990-12-20 15:06:42 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-22 23:55:50 +00:00
										 |  |  | /* Christian Tismer argued convincingly that method attributes should
 | 
					
						
							|  |  |  |    (nearly) always override function attributes. | 
					
						
							|  |  |  |    The one exception is __doc__; there's a default __doc__ which | 
					
						
							|  |  |  |    should only be used for the class, not for instances */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_get_doc(PyMethodObject *im, void *context) | 
					
						
							| 
									
										
										
										
											2003-11-22 23:55:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     static PyObject *docstr; | 
					
						
							|  |  |  |     if (docstr == NULL) { | 
					
						
							|  |  |  |         docstr= PyUnicode_InternFromString("__doc__"); | 
					
						
							|  |  |  |         if (docstr == NULL) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return PyObject_GetAttr(im->im_func, docstr); | 
					
						
							| 
									
										
										
										
											2003-11-22 23:55:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | static PyGetSetDef method_getset[] = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     {"__doc__", (getter)method_get_doc, NULL, NULL}, | 
					
						
							|  |  |  |     {0} | 
					
						
							| 
									
										
										
										
											2003-11-22 23:55:50 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2001-01-15 20:40:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-02 03:12:38 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_getattro(PyObject *obj, PyObject *name) | 
					
						
							| 
									
										
										
										
											1990-12-20 15:06:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyMethodObject *im = (PyMethodObject *)obj; | 
					
						
							|  |  |  |     PyTypeObject *tp = obj->ob_type; | 
					
						
							|  |  |  |     PyObject *descr = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (tp->tp_dict == NULL) { | 
					
						
							|  |  |  |             if (PyType_Ready(tp) < 0) | 
					
						
							|  |  |  |                 return NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         descr = _PyType_Lookup(tp, name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (descr != NULL) { | 
					
						
							|  |  |  |         descrgetfunc f = TP_DESCR_GET(descr->ob_type); | 
					
						
							|  |  |  |         if (f != NULL) | 
					
						
							|  |  |  |             return f(descr, obj, (PyObject *)obj->ob_type); | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             Py_INCREF(descr); | 
					
						
							|  |  |  |             return descr; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return PyObject_GetAttr(im->im_func, name); | 
					
						
							| 
									
										
										
										
											1990-12-20 15:06:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | PyDoc_STRVAR(method_doc, | 
					
						
							| 
									
										
										
										
											2007-11-27 10:40:20 +00:00
										 |  |  | "method(function, instance)\n\
 | 
					
						
							| 
									
										
										
										
											2002-06-14 20:41:17 +00:00
										 |  |  | \n\ | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | Create a bound instance method object."); | 
					
						
							| 
									
										
										
										
											2002-06-14 20:41:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_new(PyTypeObject* type, PyObject* args, PyObject *kw) | 
					
						
							| 
									
										
										
										
											2002-06-14 20:41:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyObject *func; | 
					
						
							|  |  |  |     PyObject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!_PyArg_NoKeywords("method", kw)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!PyArg_UnpackTuple(args, "method", 2, 2, | 
					
						
							|  |  |  |                           &func, &self)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!PyCallable_Check(func)) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                         "first argument must be callable"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (self == NULL || self == Py_None) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |             "self must not be None"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return PyMethod_New(func, self); | 
					
						
							| 
									
										
										
										
											2002-06-14 20:41:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2013-08-13 20:18:52 +02:00
										 |  |  | method_dealloc(PyMethodObject *im) | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     _PyObject_GC_UNTRACK(im); | 
					
						
							|  |  |  |     if (im->im_weakreflist != NULL) | 
					
						
							|  |  |  |         PyObject_ClearWeakRefs((PyObject *)im); | 
					
						
							|  |  |  |     Py_DECREF(im->im_func); | 
					
						
							|  |  |  |     Py_XDECREF(im->im_self); | 
					
						
							|  |  |  |     if (numfree < PyMethod_MAXFREELIST) { | 
					
						
							|  |  |  |         im->im_self = (PyObject *)free_list; | 
					
						
							|  |  |  |         free_list = im; | 
					
						
							|  |  |  |         numfree++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         PyObject_GC_Del(im); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | method_richcompare(PyObject *self, PyObject *other, int op) | 
					
						
							| 
									
										
										
										
											1992-09-03 20:39:51 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyMethodObject *a, *b; | 
					
						
							|  |  |  |     PyObject *res; | 
					
						
							|  |  |  |     int eq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((op != Py_EQ && op != Py_NE) || | 
					
						
							|  |  |  |         !PyMethod_Check(self) || | 
					
						
							|  |  |  |         !PyMethod_Check(other)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-08-10 20:28:54 -05:00
										 |  |  |         Py_RETURN_NOTIMPLEMENTED; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     a = (PyMethodObject *)self; | 
					
						
							|  |  |  |     b = (PyMethodObject *)other; | 
					
						
							|  |  |  |     eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); | 
					
						
							|  |  |  |     if (eq == 1) { | 
					
						
							|  |  |  |         if (a->im_self == NULL || b->im_self == NULL) | 
					
						
							|  |  |  |             eq = a->im_self == b->im_self; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             eq = PyObject_RichCompareBool(a->im_self, b->im_self, | 
					
						
							|  |  |  |                                           Py_EQ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (eq < 0) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (op == Py_EQ) | 
					
						
							|  |  |  |         res = eq ? Py_True : Py_False; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         res = eq ? Py_False : Py_True; | 
					
						
							|  |  |  |     Py_INCREF(res); | 
					
						
							|  |  |  |     return res; | 
					
						
							| 
									
										
										
										
											1992-09-03 20:39:51 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-02 03:12:38 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_repr(PyMethodObject *a) | 
					
						
							| 
									
										
										
										
											1993-05-19 14:50:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyObject *self = a->im_self; | 
					
						
							|  |  |  |     PyObject *func = a->im_func; | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |     PyObject *funcname = NULL, *result = NULL; | 
					
						
							|  |  |  |     const char *defname = "?"; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |     funcname = _PyObject_GetAttrId(func, &PyId___qualname__); | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (funcname == NULL) { | 
					
						
							|  |  |  |         if (!PyErr_ExceptionMatches(PyExc_AttributeError)) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |         PyErr_Clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |         funcname = _PyObject_GetAttrId(func, &PyId___name__); | 
					
						
							|  |  |  |         if (funcname == NULL) { | 
					
						
							|  |  |  |             if (!PyErr_ExceptionMatches(PyExc_AttributeError)) | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |                 return NULL; | 
					
						
							|  |  |  |             PyErr_Clear(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-03-18 21:53:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |     if (funcname != NULL && !PyUnicode_Check(funcname)) { | 
					
						
							|  |  |  |         Py_DECREF(funcname); | 
					
						
							|  |  |  |         funcname = NULL; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* XXX Shouldn't use repr()/%R here! */ | 
					
						
							| 
									
										
										
										
											2014-08-20 18:41:57 -05:00
										 |  |  |     result = PyUnicode_FromFormat("<bound method %V of %R>", | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |                                   funcname, defname, self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Py_XDECREF(funcname); | 
					
						
							|  |  |  |     return result; | 
					
						
							| 
									
										
										
										
											1993-05-19 14:50:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-17 20:54:53 +00:00
										 |  |  | static Py_hash_t | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_hash(PyMethodObject *a) | 
					
						
							| 
									
										
										
										
											1993-03-29 10:43:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-17 20:54:53 +00:00
										 |  |  |     Py_hash_t x, y; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (a->im_self == NULL) | 
					
						
							|  |  |  |         x = PyObject_Hash(Py_None); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         x = PyObject_Hash(a->im_self); | 
					
						
							|  |  |  |     if (x == -1) | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     y = PyObject_Hash(a->im_func); | 
					
						
							|  |  |  |     if (y == -1) | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     x = x ^ y; | 
					
						
							|  |  |  |     if (x == -1) | 
					
						
							|  |  |  |         x = -2; | 
					
						
							|  |  |  |     return x; | 
					
						
							| 
									
										
										
										
											1993-03-29 10:43:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-23 14:18:11 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_traverse(PyMethodObject *im, visitproc visit, void *arg) | 
					
						
							| 
									
										
										
										
											2000-06-23 14:18:11 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     Py_VISIT(im->im_func); | 
					
						
							|  |  |  |     Py_VISIT(im->im_self); | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2000-06-23 14:18:11 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2016-08-25 01:04:14 +02:00
										 |  |  | method_call(PyObject *method, PyObject *args, PyObject *kwargs) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:04:14 +02:00
										 |  |  |     PyObject *self, *func; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:04:14 +02:00
										 |  |  |     self = PyMethod_GET_SELF(method); | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (self == NULL) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-25 01:04:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     func = PyMethod_GET_FUNCTION(method); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return _PyObject_Call_Prepend(func, self, args, kwargs); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 17:52:31 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-08-24 00:41:19 +00:00
										 |  |  | method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) | 
					
						
							| 
									
										
										
										
											2001-08-15 17:52:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     /* Don't rebind an already bound method of a class that's not a base
 | 
					
						
							|  |  |  |        class of cls. */ | 
					
						
							|  |  |  |     if (PyMethod_GET_SELF(meth) != NULL) { | 
					
						
							|  |  |  |         /* Already bound */ | 
					
						
							|  |  |  |         Py_INCREF(meth); | 
					
						
							|  |  |  |         return meth; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* Bind it to obj */ | 
					
						
							|  |  |  |     return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj); | 
					
						
							| 
									
										
										
										
											2001-08-15 17:52:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-02 03:12:38 +00:00
										 |  |  | PyTypeObject PyMethod_Type = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyVarObject_HEAD_INIT(&PyType_Type, 0) | 
					
						
							|  |  |  |     "method", | 
					
						
							|  |  |  |     sizeof(PyMethodObject), | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     (destructor)method_dealloc,                 /* tp_dealloc */ | 
					
						
							|  |  |  |     0,                                          /* tp_print */ | 
					
						
							|  |  |  |     0,                                          /* tp_getattr */ | 
					
						
							|  |  |  |     0,                                          /* tp_setattr */ | 
					
						
							|  |  |  |     0,                                          /* tp_reserved */ | 
					
						
							|  |  |  |     (reprfunc)method_repr,                      /* tp_repr */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_number */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_sequence */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_mapping */ | 
					
						
							|  |  |  |     (hashfunc)method_hash,                      /* tp_hash */ | 
					
						
							|  |  |  |     method_call,                                /* tp_call */ | 
					
						
							|  |  |  |     0,                                          /* tp_str */ | 
					
						
							|  |  |  |     method_getattro,                            /* tp_getattro */ | 
					
						
							|  |  |  |     PyObject_GenericSetAttr,                    /* tp_setattro */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_buffer */ | 
					
						
							|  |  |  |     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							|  |  |  |     method_doc,                                 /* tp_doc */ | 
					
						
							|  |  |  |     (traverseproc)method_traverse,              /* tp_traverse */ | 
					
						
							|  |  |  |     0,                                          /* tp_clear */ | 
					
						
							|  |  |  |     method_richcompare,                         /* tp_richcompare */ | 
					
						
							|  |  |  |     offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */ | 
					
						
							|  |  |  |     0,                                          /* tp_iter */ | 
					
						
							|  |  |  |     0,                                          /* tp_iternext */ | 
					
						
							| 
									
										
										
										
											2013-11-23 18:59:12 +01:00
										 |  |  |     method_methods,                             /* tp_methods */ | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     method_memberlist,                          /* tp_members */ | 
					
						
							|  |  |  |     method_getset,                              /* tp_getset */ | 
					
						
							|  |  |  |     0,                                          /* tp_base */ | 
					
						
							|  |  |  |     0,                                          /* tp_dict */ | 
					
						
							|  |  |  |     method_descr_get,                           /* tp_descr_get */ | 
					
						
							|  |  |  |     0,                                          /* tp_descr_set */ | 
					
						
							|  |  |  |     0,                                          /* tp_dictoffset */ | 
					
						
							|  |  |  |     0,                                          /* tp_init */ | 
					
						
							|  |  |  |     0,                                          /* tp_alloc */ | 
					
						
							|  |  |  |     method_new,                                 /* tp_new */ | 
					
						
							| 
									
										
										
										
											1990-10-14 12:07:46 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											1997-08-05 02:06:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Clear out the free list */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
  Add diagnostic message to help figure-out why SocketServer tests occasionally crash
  when trying to remove a pid that in not in the activechildren list.
........
  r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
  Add fixed-point examples to the decimal FAQ
........
  r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
  Improve rst markup
........
  r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
  Show how to remove exponents.
........
  r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
  Fix markup.
........
  r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
  Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
  r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
  Simplify moneyfmt() recipe.
........
  r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
  Fix markup
........
  r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
  No need to register subclass of ABCs.
........
  r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
  Try to correct a markup error that does hide the following paragraph.
........
  r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
  Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
  r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
  Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
  r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
  Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
  Thanks to Thomas Herve for the fix.
........
  r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
  In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long.  It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
  r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
  Two new functions:
    * place_summary_first copies the regrtest summary to the front of the file
      making it easier to scan quickly for problems.
    * count_failures gets the actual count of the number of failing tests, not
      just a 1 (some failures) or 0 (no failures).
........
  r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
  Update example to match the current syntax.
........
  r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
  Issue #2115: __slot__ attributes setting was 10x slower.
  Also correct a possible crash using ABCs.
  This change is exactly the same as an optimisation
  done 5 years ago, but on slot *access*:
  http://svn.python.org/view?view=rev&rev=28297
........
  r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
  Temporarily let these tests pass
........
  r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
  ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
  r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
  Configured selection highlighting colors were ignored; updating highlighting
  in the config dialog would cause non-Python files to be colored as if they
  were Python source; improve use of ColorDelagator.  Patch 1334. Tal Einat.
........
  r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
  Re-enable tests, they were failing since gc.collect() clears the various freelists.
  They still remain fragile.
  For example, a call to assertEqual currently does not make any allocation
  (which surprised me at first).
  But this can change when gc.collect also deletes the numerous "zombie frames"
  attached to each function.
........
											
										 
											2008-02-16 07:38:31 +00:00
										 |  |  | int | 
					
						
							|  |  |  | PyMethod_ClearFreeList(void) | 
					
						
							| 
									
										
										
										
											1997-08-05 02:06:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     int freelist_size = numfree; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (free_list) { | 
					
						
							|  |  |  |         PyMethodObject *im = free_list; | 
					
						
							|  |  |  |         free_list = (PyMethodObject *)(im->im_self); | 
					
						
							|  |  |  |         PyObject_GC_Del(im); | 
					
						
							|  |  |  |         numfree--; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     assert(numfree == 0); | 
					
						
							|  |  |  |     return freelist_size; | 
					
						
							| 
									
										
											  
											
												Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
  Add diagnostic message to help figure-out why SocketServer tests occasionally crash
  when trying to remove a pid that in not in the activechildren list.
........
  r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
  Add fixed-point examples to the decimal FAQ
........
  r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
  Improve rst markup
........
  r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
  Show how to remove exponents.
........
  r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
  Fix markup.
........
  r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
  Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
  r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
  Simplify moneyfmt() recipe.
........
  r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
  Fix markup
........
  r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
  No need to register subclass of ABCs.
........
  r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
  Try to correct a markup error that does hide the following paragraph.
........
  r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
  Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
  r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
  Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
  r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
  Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
  Thanks to Thomas Herve for the fix.
........
  r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
  In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long.  It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
  r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
  Two new functions:
    * place_summary_first copies the regrtest summary to the front of the file
      making it easier to scan quickly for problems.
    * count_failures gets the actual count of the number of failing tests, not
      just a 1 (some failures) or 0 (no failures).
........
  r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
  Update example to match the current syntax.
........
  r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
  Issue #2115: __slot__ attributes setting was 10x slower.
  Also correct a possible crash using ABCs.
  This change is exactly the same as an optimisation
  done 5 years ago, but on slot *access*:
  http://svn.python.org/view?view=rev&rev=28297
........
  r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
  Temporarily let these tests pass
........
  r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
  ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
  r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
  Configured selection highlighting colors were ignored; updating highlighting
  in the config dialog would cause non-Python files to be colored as if they
  were Python source; improve use of ColorDelagator.  Patch 1334. Tal Einat.
........
  r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
  Re-enable tests, they were failing since gc.collect() clears the various freelists.
  They still remain fragile.
  For example, a call to assertEqual currently does not make any allocation
  (which surprised me at first).
  But this can change when gc.collect also deletes the numerous "zombie frames"
  attached to each function.
........
											
										 
											2008-02-16 07:38:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | PyMethod_Fini(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     (void)PyMethod_ClearFreeList(); | 
					
						
							| 
									
										
										
										
											1997-08-05 02:06:53 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 14:55:41 -04:00
										 |  |  | /* Print summary info about the state of the optimized allocator */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | _PyMethod_DebugMallocStats(FILE *out) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     _PyDebugAllocatorStats(out, | 
					
						
							|  |  |  |                            "free PyMethodObject", | 
					
						
							|  |  |  |                            numfree, sizeof(PyMethodObject)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | /* ------------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * instance method | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyInstanceMethod_New(PyObject *func) { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyInstanceMethodObject *method; | 
					
						
							|  |  |  |     method = PyObject_GC_New(PyInstanceMethodObject, | 
					
						
							|  |  |  |                              &PyInstanceMethod_Type); | 
					
						
							|  |  |  |     if (method == NULL) return NULL; | 
					
						
							|  |  |  |     Py_INCREF(func); | 
					
						
							|  |  |  |     method->func = func; | 
					
						
							|  |  |  |     _PyObject_GC_TRACK(method); | 
					
						
							|  |  |  |     return (PyObject *)method; | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyInstanceMethod_Function(PyObject *im) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (!PyInstanceMethod_Check(im)) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return PyInstanceMethod_GET_FUNCTION(im); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IMO_OFF(x) offsetof(PyInstanceMethodObject, x)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMemberDef instancemethod_memberlist[] = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     {"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED, | 
					
						
							|  |  |  |      "the function (or other callable) implementing a method"}, | 
					
						
							|  |  |  |     {NULL}      /* Sentinel */ | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_get_doc(PyObject *self, void *context) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     static PyObject *docstr; | 
					
						
							|  |  |  |     if (docstr == NULL) { | 
					
						
							|  |  |  |         docstr = PyUnicode_InternFromString("__doc__"); | 
					
						
							|  |  |  |         if (docstr == NULL) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyGetSetDef instancemethod_getset[] = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     {"__doc__", (getter)instancemethod_get_doc, NULL, NULL}, | 
					
						
							|  |  |  |     {0} | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_getattro(PyObject *self, PyObject *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyTypeObject *tp = self->ob_type; | 
					
						
							|  |  |  |     PyObject *descr = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (tp->tp_dict == NULL) { | 
					
						
							|  |  |  |         if (PyType_Ready(tp) < 0) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     descr = _PyType_Lookup(tp, name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (descr != NULL) { | 
					
						
							|  |  |  |         descrgetfunc f = TP_DESCR_GET(descr->ob_type); | 
					
						
							|  |  |  |         if (f != NULL) | 
					
						
							|  |  |  |             return f(descr, self, (PyObject *)self->ob_type); | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             Py_INCREF(descr); | 
					
						
							|  |  |  |             return descr; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | instancemethod_dealloc(PyObject *self) { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     _PyObject_GC_UNTRACK(self); | 
					
						
							|  |  |  |     Py_DECREF(PyInstanceMethod_GET_FUNCTION(self)); | 
					
						
							|  |  |  |     PyObject_GC_Del(self); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | instancemethod_traverse(PyObject *self, visitproc visit, void *arg) { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     Py_VISIT(PyInstanceMethod_GET_FUNCTION(self)); | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) { | 
					
						
							| 
									
										
										
										
											2013-08-13 20:18:52 +02:00
										 |  |  |     PyObject *func = PyInstanceMethod_GET_FUNCTION(descr); | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (obj == NULL) { | 
					
						
							|  |  |  |         Py_INCREF(func); | 
					
						
							|  |  |  |         return func; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         return PyMethod_New(func, obj); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_richcompare(PyObject *self, PyObject *other, int op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyInstanceMethodObject *a, *b; | 
					
						
							|  |  |  |     PyObject *res; | 
					
						
							|  |  |  |     int eq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((op != Py_EQ && op != Py_NE) || | 
					
						
							|  |  |  |         !PyInstanceMethod_Check(self) || | 
					
						
							|  |  |  |         !PyInstanceMethod_Check(other)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-08-10 20:28:54 -05:00
										 |  |  |         Py_RETURN_NOTIMPLEMENTED; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     a = (PyInstanceMethodObject *)self; | 
					
						
							|  |  |  |     b = (PyInstanceMethodObject *)other; | 
					
						
							|  |  |  |     eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ); | 
					
						
							|  |  |  |     if (eq < 0) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (op == Py_EQ) | 
					
						
							|  |  |  |         res = eq ? Py_True : Py_False; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         res = eq ? Py_False : Py_True; | 
					
						
							|  |  |  |     Py_INCREF(res); | 
					
						
							|  |  |  |     return res; | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_repr(PyObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyObject *func = PyInstanceMethod_Function(self); | 
					
						
							|  |  |  |     PyObject *funcname = NULL , *result = NULL; | 
					
						
							| 
									
										
										
										
											2017-11-11 13:06:26 +02:00
										 |  |  |     const char *defname = "?"; | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (func == NULL) { | 
					
						
							|  |  |  |         PyErr_BadInternalCall(); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 18:11:30 +02:00
										 |  |  |     funcname = _PyObject_GetAttrId(func, &PyId___name__); | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     if (funcname == NULL) { | 
					
						
							|  |  |  |         if (!PyErr_ExceptionMatches(PyExc_AttributeError)) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |         PyErr_Clear(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (!PyUnicode_Check(funcname)) { | 
					
						
							|  |  |  |         Py_DECREF(funcname); | 
					
						
							|  |  |  |         funcname = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result = PyUnicode_FromFormat("<instancemethod %V at %p>", | 
					
						
							|  |  |  |                                   funcname, defname, self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Py_XDECREF(funcname); | 
					
						
							|  |  |  |     return result; | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | static long | 
					
						
							|  |  |  | instancemethod_hash(PyObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     long x, y; | 
					
						
							|  |  |  |     x = (long)self; | 
					
						
							|  |  |  |     y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self)); | 
					
						
							|  |  |  |     if (y == -1) | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     x = x ^ y; | 
					
						
							|  |  |  |     if (x == -1) | 
					
						
							|  |  |  |         x = -2; | 
					
						
							|  |  |  |     return x; | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(instancemethod_doc, | 
					
						
							|  |  |  | "instancemethod(function)\n\
 | 
					
						
							|  |  |  | \n\ | 
					
						
							|  |  |  | Bind a function to a class."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyObject *func; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!_PyArg_NoKeywords("instancemethod", kw)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!PyCallable_Check(func)) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                         "first argument must be callable"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return PyInstanceMethod_New(func); | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject PyInstanceMethod_Type = { | 
					
						
							| 
									
										
										
										
											2010-05-09 15:52:27 +00:00
										 |  |  |     PyVarObject_HEAD_INIT(&PyType_Type, 0) | 
					
						
							|  |  |  |     "instancemethod",                           /* tp_name */ | 
					
						
							|  |  |  |     sizeof(PyInstanceMethodObject),             /* tp_basicsize */ | 
					
						
							|  |  |  |     0,                                          /* tp_itemsize */ | 
					
						
							|  |  |  |     instancemethod_dealloc,                     /* tp_dealloc */ | 
					
						
							|  |  |  |     0,                                          /* tp_print */ | 
					
						
							|  |  |  |     0,                                          /* tp_getattr */ | 
					
						
							|  |  |  |     0,                                          /* tp_setattr */ | 
					
						
							|  |  |  |     0,                                          /* tp_reserved */ | 
					
						
							|  |  |  |     (reprfunc)instancemethod_repr,              /* tp_repr */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_number */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_sequence */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_mapping */ | 
					
						
							|  |  |  |     0, /*(hashfunc)instancemethod_hash,         tp_hash  */ | 
					
						
							|  |  |  |     instancemethod_call,                        /* tp_call */ | 
					
						
							|  |  |  |     0,                                          /* tp_str */ | 
					
						
							|  |  |  |     instancemethod_getattro,                    /* tp_getattro */ | 
					
						
							|  |  |  |     PyObject_GenericSetAttr,                    /* tp_setattro */ | 
					
						
							|  |  |  |     0,                                          /* tp_as_buffer */ | 
					
						
							|  |  |  |     Py_TPFLAGS_DEFAULT | 
					
						
							|  |  |  |         | Py_TPFLAGS_HAVE_GC,                   /* tp_flags */ | 
					
						
							|  |  |  |     instancemethod_doc,                         /* tp_doc */ | 
					
						
							|  |  |  |     instancemethod_traverse,                    /* tp_traverse */ | 
					
						
							|  |  |  |     0,                                          /* tp_clear */ | 
					
						
							|  |  |  |     instancemethod_richcompare,                 /* tp_richcompare */ | 
					
						
							|  |  |  |     0,                                          /* tp_weaklistoffset */ | 
					
						
							|  |  |  |     0,                                          /* tp_iter */ | 
					
						
							|  |  |  |     0,                                          /* tp_iternext */ | 
					
						
							|  |  |  |     0,                                          /* tp_methods */ | 
					
						
							|  |  |  |     instancemethod_memberlist,                  /* tp_members */ | 
					
						
							|  |  |  |     instancemethod_getset,                      /* tp_getset */ | 
					
						
							|  |  |  |     0,                                          /* tp_base */ | 
					
						
							|  |  |  |     0,                                          /* tp_dict */ | 
					
						
							|  |  |  |     instancemethod_descr_get,                   /* tp_descr_get */ | 
					
						
							|  |  |  |     0,                                          /* tp_descr_set */ | 
					
						
							|  |  |  |     0,                                          /* tp_dictoffset */ | 
					
						
							|  |  |  |     0,                                          /* tp_init */ | 
					
						
							|  |  |  |     0,                                          /* tp_alloc */ | 
					
						
							|  |  |  |     instancemethod_new,                         /* tp_new */ | 
					
						
							| 
									
										
										
										
											2007-12-11 19:56:40 +00:00
										 |  |  | }; |