Mercurial > cpython-lru_cache-weakref
annotate Objects/classobject.c @ 51271:87fbbf22adf3 3.0
Merged revisions 69214 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r69214 | mark.dickinson | 2009-02-02 20:36:42 +0000 (Mon, 02 Feb 2009) | 4 lines
Issue #1717: rename tp_compare to tp_reserved. I'll change the
type of tp_compare in a separate commit, for ease of reversion
should things go wrong.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Mon, 02 Feb 2009 20:41:29 +0000 |
| parents | 770e4e132775 |
| children | 3fb1c1fbe26c |
| rev | line source |
|---|---|
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
1 /* Class object implementation (dead now except for methods) */ |
| 6 | 2 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
3 #include "Python.h" |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
791
diff
changeset
|
4 #include "structmember.h" |
| 6 | 5 |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38673
diff
changeset
|
6 #define TP_DESCR_GET(t) ((t)->tp_descr_get) |
|
20501
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
7 |
|
45192
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
8 /* Free list for method objects to safe malloc/free overhead |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
9 * The im_self element is used to chain the elements. |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
10 */ |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
11 static PyMethodObject *free_list; |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
12 static int numfree = 0; |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
13 #ifndef PyMethod_MAXFREELIST |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
14 #define PyMethod_MAXFREELIST 256 |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
15 #endif |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
16 |
|
19751
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
17 PyObject * |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
18 PyMethod_Function(PyObject *im) |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
19 { |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
20 if (!PyMethod_Check(im)) { |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
21 PyErr_BadInternalCall(); |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
22 return NULL; |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
23 } |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
24 return ((PyMethodObject *)im)->im_func; |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
25 } |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
26 |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
27 PyObject * |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
28 PyMethod_Self(PyObject *im) |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
29 { |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
30 if (!PyMethod_Check(im)) { |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
31 PyErr_BadInternalCall(); |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
32 return NULL; |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
33 } |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
34 return ((PyMethodObject *)im)->im_self; |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
35 } |
|
3d76dfc34c57
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
Guido van Rossum <guido@python.org>
parents:
19581
diff
changeset
|
36 |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
37 /* Method objects are used for bound instance methods returned by |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
38 instancename.methodname. ClassName.methodname returns an ordinary |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
39 function. |
|
1289
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
40 */ |
| 6 | 41 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
42 PyObject * |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
43 PyMethod_New(PyObject *func, PyObject *self) |
| 6 | 44 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
45 register PyMethodObject *im; |
|
8651
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8649
diff
changeset
|
46 if (!PyCallable_Check(func)) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
47 PyErr_BadInternalCall(); |
| 6 | 48 return NULL; |
| 49 } | |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
50 if (self == NULL) { |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
51 PyErr_BadInternalCall(); |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
52 return NULL; |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
53 } |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
54 im = free_list; |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
55 if (im != NULL) { |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
56 free_list = (PyMethodObject *)(im->im_self); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12504
diff
changeset
|
57 PyObject_INIT(im, &PyMethod_Type); |
|
45192
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
58 numfree--; |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
59 } |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
60 else { |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19480
diff
changeset
|
61 im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
62 if (im == NULL) |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
63 return NULL; |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
64 } |
|
17170
962196ce7231
Add support for weak references to the function and method types.
Fred Drake <fdrake@acm.org>
parents:
17154
diff
changeset
|
65 im->im_weakreflist = NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
66 Py_INCREF(func); |
|
224
e71b6fec86e5
Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents:
202
diff
changeset
|
67 im->im_func = func; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
68 Py_XINCREF(self); |
|
224
e71b6fec86e5
Renamed class methods to instance methods (which they are)
Guido van Rossum <guido@python.org>
parents:
202
diff
changeset
|
69 im->im_self = self; |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19480
diff
changeset
|
70 _PyObject_GC_TRACK(im); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
71 return (PyObject *)im; |
| 6 | 72 } |
| 73 | |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
74 /* Descriptors for PyMethod attributes */ |
|
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
75 |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
76 /* im_func and im_self are stored in the PyMethod object */ |
| 6 | 77 |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
78 #define MO_OFF(x) offsetof(PyMethodObject, x) |
| 86 | 79 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
80 static PyMemberDef method_memberlist[] = { |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
81 {"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED, |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19966
diff
changeset
|
82 "the function (or other callable) implementing a method"}, |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
83 {"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED, |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
84 "the instance to which a method is bound"}, |
| 86 | 85 {NULL} /* Sentinel */ |
| 86 }; | |
| 87 | |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
88 /* Christian Tismer argued convincingly that method attributes should |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
89 (nearly) always override function attributes. |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
90 The one exception is __doc__; there's a default __doc__ which |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
91 should only be used for the class, not for instances */ |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
92 |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
93 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
94 method_get_doc(PyMethodObject *im, void *context) |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
95 { |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
96 static PyObject *docstr; |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
97 if (docstr == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
98 docstr= PyUnicode_InternFromString("__doc__"); |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
99 if (docstr == NULL) |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
100 return NULL; |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
101 } |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
102 return PyObject_GetAttr(im->im_func, docstr); |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
103 } |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
104 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
105 static PyGetSetDef method_getset[] = { |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
106 {"__doc__", (getter)method_get_doc, NULL, NULL}, |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
107 {0} |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
108 }; |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
15722
diff
changeset
|
109 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
110 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
111 method_getattro(PyObject *obj, PyObject *name) |
| 86 | 112 { |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
113 PyMethodObject *im = (PyMethodObject *)obj; |
|
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
114 PyTypeObject *tp = obj->ob_type; |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
115 PyObject *descr = NULL; |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
116 |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38673
diff
changeset
|
117 { |
|
20501
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
118 if (tp->tp_dict == NULL) { |
|
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
119 if (PyType_Ready(tp) < 0) |
|
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
120 return NULL; |
|
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
121 } |
|
733cb268ad2f
Protect references to tp_descr_get and tp_dict with the appropriate test:
Guido van Rossum <guido@python.org>
parents:
20183
diff
changeset
|
122 descr = _PyType_Lookup(tp, name); |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
123 } |
|
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
124 |
|
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
125 if (descr != NULL) { |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
126 descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
127 if (f != NULL) |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
128 return f(descr, obj, (PyObject *)obj->ob_type); |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
129 else { |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
130 Py_INCREF(descr); |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
131 return descr; |
|
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
132 } |
|
3549
f66306bc0663
Added __name__ attribute to class instance method objects.
Guido van Rossum <guido@python.org>
parents:
3096
diff
changeset
|
133 } |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
134 |
|
31003
278976b19dcc
- When method objects have an attribute that can be satisfied either
Guido van Rossum <guido@python.org>
parents:
30801
diff
changeset
|
135 return PyObject_GetAttr(im->im_func, name); |
| 86 | 136 } |
| 137 | |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
138 PyDoc_STRVAR(method_doc, |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
139 "method(function, instance)\n\ |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
140 \n\ |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
141 Create a bound instance method object."); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
142 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
143 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
144 method_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
145 { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
146 PyObject *func; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
147 PyObject *self; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
148 |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
149 if (!_PyArg_NoKeywords("method", kw)) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
150 return NULL; |
|
44233
50a50e752142
Fixed a bug found by Marcin Kowalczyk
Christian Heimes <christian@cheimes.de>
parents:
44026
diff
changeset
|
151 if (!PyArg_UnpackTuple(args, "method", 2, 2, |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
152 &func, &self)) |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
153 return NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
154 if (!PyCallable_Check(func)) { |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
155 PyErr_SetString(PyExc_TypeError, |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
156 "first argument must be callable"); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
157 return NULL; |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
158 } |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
159 if (self == NULL || self == Py_None) { |
| 34850 | 160 PyErr_SetString(PyExc_TypeError, |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
161 "self must not be None"); |
| 34850 | 162 return NULL; |
| 163 } | |
| 164 | |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
165 return PyMethod_New(func, self); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
166 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
167 |
| 6 | 168 static void |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
169 method_dealloc(register PyMethodObject *im) |
| 6 | 170 { |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19480
diff
changeset
|
171 _PyObject_GC_UNTRACK(im); |
|
20698
b229208a2a72
Be smarter about clearing the weakref lists for instances, instance methods,
Fred Drake <fdrake@acm.org>
parents:
20601
diff
changeset
|
172 if (im->im_weakreflist != NULL) |
|
b229208a2a72
Be smarter about clearing the weakref lists for instances, instance methods,
Fred Drake <fdrake@acm.org>
parents:
20601
diff
changeset
|
173 PyObject_ClearWeakRefs((PyObject *)im); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
174 Py_DECREF(im->im_func); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
175 Py_XDECREF(im->im_self); |
|
45192
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
176 if (numfree < PyMethod_MAXFREELIST) { |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
177 im->im_self = (PyObject *)free_list; |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
178 free_list = im; |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
179 numfree++; |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
180 } |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
181 else { |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
182 PyObject_GC_Del(im); |
|
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
183 } |
| 6 | 184 } |
| 185 | |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
186 static PyObject * |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
187 method_richcompare(PyObject *self, PyObject *other, int op) |
|
1021
0d7c82366704
Compare instance methods by comparing the object and the function.
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
188 { |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
189 PyMethodObject *a, *b; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
190 PyObject *res; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
191 int eq; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
192 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
193 if ((op != Py_EQ && op != Py_NE) || |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
194 !PyMethod_Check(self) || |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
195 !PyMethod_Check(other)) |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
196 { |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
197 Py_INCREF(Py_NotImplemented); |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
198 return Py_NotImplemented; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
199 } |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
200 a = (PyMethodObject *)self; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
201 b = (PyMethodObject *)other; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
202 eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
203 if (eq == 1) { |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
204 if (a->im_self == NULL || b->im_self == NULL) |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
205 eq = a->im_self == b->im_self; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
206 else |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
207 eq = PyObject_RichCompareBool(a->im_self, b->im_self, |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
208 Py_EQ); |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
209 } |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
210 if (eq < 0) |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
211 return NULL; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
212 if (op == Py_EQ) |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
213 res = eq ? Py_True : Py_False; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
214 else |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
215 res = eq ? Py_False : Py_True; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
216 Py_INCREF(res); |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
217 return res; |
|
1021
0d7c82366704
Compare instance methods by comparing the object and the function.
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
218 } |
|
0d7c82366704
Compare instance methods by comparing the object and the function.
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
219 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
220 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
221 method_repr(PyMethodObject *a) |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1272
diff
changeset
|
222 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
223 PyObject *self = a->im_self; |
|
8651
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8649
diff
changeset
|
224 PyObject *func = a->im_func; |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44272
diff
changeset
|
225 PyObject *klass = (PyObject*)Py_TYPE(self); |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
226 PyObject *funcname = NULL ,*klassname = NULL, *result = NULL; |
|
42047
d678ba0177da
Add a format specifier %V to PyUnicode_FromFormat(), that works similar to %U,
Walter Dörwald <walter@livinglogic.de>
parents:
42018
diff
changeset
|
227 char *defname = "?"; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
228 |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
229 if (self == NULL) { |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
230 PyErr_BadInternalCall(); |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
231 return NULL; |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
232 } |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
233 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
234 funcname = PyObject_GetAttrString(func, "__name__"); |
|
23842
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
235 if (funcname == NULL) { |
|
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
236 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
237 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
238 PyErr_Clear(); |
|
23842
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
239 } |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
240 else if (!PyUnicode_Check(funcname)) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
241 Py_DECREF(funcname); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
242 funcname = NULL; |
|
8651
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8649
diff
changeset
|
243 } |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
244 |
|
19336
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
245 if (klass == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
246 klassname = NULL; |
|
19336
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
247 else { |
|
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
248 klassname = PyObject_GetAttrString(klass, "__name__"); |
|
23842
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
249 if (klassname == NULL) { |
|
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
250 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
251 return NULL; |
|
19336
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
252 PyErr_Clear(); |
|
23842
6c619c161b87
Major cleanup operation: whenever there's a call that looks for an
Guido van Rossum <guido@python.org>
parents:
23839
diff
changeset
|
253 } |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
254 else if (!PyUnicode_Check(klassname)) { |
|
19336
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
255 Py_DECREF(klassname); |
|
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
256 klassname = NULL; |
|
ebfb74ce7e56
Fix core dump in repr() of instancemethod whose class==NULL.
Guido van Rossum <guido@python.org>
parents:
19334
diff
changeset
|
257 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
258 } |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
259 |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
260 /* XXX Shouldn't use repr()/%R here! */ |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
261 result = PyUnicode_FromFormat("<bound method %V.%V of %R>", |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
262 klassname, defname, |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
263 funcname, defname, self); |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
264 |
|
11378
dc9f1f964690
Fix for PR#98 (Adrian Eyre) -- in instancemethod_repr, the funcname
Guido van Rossum <guido@python.org>
parents:
8806
diff
changeset
|
265 Py_XDECREF(funcname); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
266 Py_XDECREF(klassname); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
267 return result; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1272
diff
changeset
|
268 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1272
diff
changeset
|
269 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
270 static long |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
271 method_hash(PyMethodObject *a) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
272 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
273 long x, y; |
|
1289
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
274 if (a->im_self == NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
275 x = PyObject_Hash(Py_None); |
|
1289
4d292c7857d4
Access checks now work, at least for instance data (not for methods
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
276 else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
277 x = PyObject_Hash(a->im_self); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
278 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
279 return -1; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
280 y = PyObject_Hash(a->im_func); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
281 if (y == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
282 return -1; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
283 x = x ^ y; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
284 if (x == -1) |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
285 x = -2; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
286 return x; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
287 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
288 |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
289 static int |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
290 method_traverse(PyMethodObject *im, visitproc visit, void *arg) |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
291 { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
292 Py_VISIT(im->im_func); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
293 Py_VISIT(im->im_self); |
|
12992
3f990ef66667
traverse functions should return 0 on success
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12990
diff
changeset
|
294 return 0; |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
295 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
296 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
297 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
298 method_call(PyObject *func, PyObject *arg, PyObject *kw) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
299 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
300 PyObject *self = PyMethod_GET_SELF(func); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
301 PyObject *result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
302 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
303 func = PyMethod_GET_FUNCTION(func); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
304 if (self == NULL) { |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
305 PyErr_BadInternalCall(); |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
306 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
307 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
308 else { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
309 Py_ssize_t argcount = PyTuple_Size(arg); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
310 PyObject *newarg = PyTuple_New(argcount + 1); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
311 int i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
312 if (newarg == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
313 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
314 Py_INCREF(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
315 PyTuple_SET_ITEM(newarg, 0, self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
316 for (i = 0; i < argcount; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
317 PyObject *v = PyTuple_GET_ITEM(arg, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
318 Py_XINCREF(v); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
319 PyTuple_SET_ITEM(newarg, i+1, v); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
320 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
321 arg = newarg; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
322 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
323 result = PyObject_Call((PyObject *)func, arg, kw); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
324 Py_DECREF(arg); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
325 return result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
326 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17894
diff
changeset
|
327 |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
328 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
329 method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
330 { |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
331 /* Don't rebind an already bound method of a class that's not a base |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
332 class of cls. */ |
|
27817
bf083e35185f
Refactor instancemethod_descr_get() to (a) be more clear, (b) be safe
Guido van Rossum <guido@python.org>
parents:
26818
diff
changeset
|
333 if (PyMethod_GET_SELF(meth) != NULL) { |
|
bf083e35185f
Refactor instancemethod_descr_get() to (a) be more clear, (b) be safe
Guido van Rossum <guido@python.org>
parents:
26818
diff
changeset
|
334 /* Already bound */ |
|
19323
261e28e7fa01
classobject.c:instancemethod_descr_get(): when a bound method is
Guido van Rossum <guido@python.org>
parents:
19280
diff
changeset
|
335 Py_INCREF(meth); |
|
261e28e7fa01
classobject.c:instancemethod_descr_get(): when a bound method is
Guido van Rossum <guido@python.org>
parents:
19280
diff
changeset
|
336 return meth; |
|
261e28e7fa01
classobject.c:instancemethod_descr_get(): when a bound method is
Guido van Rossum <guido@python.org>
parents:
19280
diff
changeset
|
337 } |
|
27817
bf083e35185f
Refactor instancemethod_descr_get() to (a) be more clear, (b) be safe
Guido van Rossum <guido@python.org>
parents:
26818
diff
changeset
|
338 /* Bind it to obj */ |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
339 return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj); |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
340 } |
|
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
341 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5008
diff
changeset
|
342 PyTypeObject PyMethod_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42047
diff
changeset
|
343 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
344 "method", |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19480
diff
changeset
|
345 sizeof(PyMethodObject), |
| 6 | 346 0, |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
347 (destructor)method_dealloc, /* tp_dealloc */ |
| 15943 | 348 0, /* tp_print */ |
| 349 0, /* tp_getattr */ | |
| 350 0, /* tp_setattr */ | |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47259
diff
changeset
|
351 0, /* tp_reserved */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
352 (reprfunc)method_repr, /* tp_repr */ |
| 15943 | 353 0, /* tp_as_number */ |
| 354 0, /* tp_as_sequence */ | |
| 355 0, /* tp_as_mapping */ | |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
356 (hashfunc)method_hash, /* tp_hash */ |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
357 method_call, /* tp_call */ |
| 15943 | 358 0, /* tp_str */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
359 method_getattro, /* tp_getattro */ |
|
19956
33669c8914b4
Redo the PyMethod attributes using a dir()-friendly approach, creating
Guido van Rossum <guido@python.org>
parents:
19808
diff
changeset
|
360 PyObject_GenericSetAttr, /* tp_setattro */ |
| 15943 | 361 0, /* tp_as_buffer */ |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38673
diff
changeset
|
362 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
363 method_doc, /* tp_doc */ |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
364 (traverseproc)method_traverse, /* tp_traverse */ |
|
17170
962196ce7231
Add support for weak references to the function and method types.
Fred Drake <fdrake@acm.org>
parents:
17154
diff
changeset
|
365 0, /* tp_clear */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
366 method_richcompare, /* tp_richcompare */ |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
367 offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */ |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
368 0, /* tp_iter */ |
|
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
369 0, /* tp_iternext */ |
|
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
370 0, /* tp_methods */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
371 method_memberlist, /* tp_members */ |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
372 method_getset, /* tp_getset */ |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
373 0, /* tp_base */ |
|
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
374 0, /* tp_dict */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
375 method_descr_get, /* tp_descr_get */ |
|
19280
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
376 0, /* tp_descr_set */ |
|
f10b68eceefc
PyMethod_Type: add a tp_descr_get slot function to ensure proper
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
377 0, /* tp_dictoffset */ |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
378 0, /* tp_init */ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23842
diff
changeset
|
379 0, /* tp_alloc */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
380 method_new, /* tp_new */ |
| 6 | 381 }; |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
382 |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
383 /* Clear out the free list */ |
|
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
384 |
|
45371
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
385 int |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
386 PyMethod_ClearFreeList(void) |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
387 { |
|
45371
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
388 int freelist_size = numfree; |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
389 |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
390 while (free_list) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12504
diff
changeset
|
391 PyMethodObject *im = free_list; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12504
diff
changeset
|
392 free_list = (PyMethodObject *)(im->im_self); |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19480
diff
changeset
|
393 PyObject_GC_Del(im); |
|
45192
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
394 numfree--; |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
395 } |
|
45192
142a11b3057e
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
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
396 assert(numfree == 0); |
|
45371
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
397 return freelist_size; |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
398 } |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
399 |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
400 void |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
401 PyMethod_Fini(void) |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
402 { |
|
7c4c46342137
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
Christian Heimes <christian@cheimes.de>
parents:
45192
diff
changeset
|
403 (void)PyMethod_ClearFreeList(); |
|
5932
40cfc905c776
Added separate free list for instance method objects, for a few
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
404 } |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
405 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
406 /* ------------------------------------------------------------------------ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
407 * instance method |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
408 */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
409 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
410 PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
411 PyInstanceMethod_New(PyObject *func) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
412 PyInstanceMethodObject *method; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
413 method = PyObject_GC_New(PyInstanceMethodObject, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
414 &PyInstanceMethod_Type); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
415 if (method == NULL) return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
416 Py_INCREF(func); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
417 method->func = func; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
418 _PyObject_GC_TRACK(method); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
419 return (PyObject *)method; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
420 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
421 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
422 PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
423 PyInstanceMethod_Function(PyObject *im) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
424 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
425 if (!PyInstanceMethod_Check(im)) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
426 PyErr_BadInternalCall(); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
427 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
428 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
429 return PyInstanceMethod_GET_FUNCTION(im); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
430 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
431 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
432 #define IMO_OFF(x) offsetof(PyInstanceMethodObject, x) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
433 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
434 static PyMemberDef instancemethod_memberlist[] = { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
435 {"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
436 "the function (or other callable) implementing a method"}, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
437 {NULL} /* Sentinel */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
438 }; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
439 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
440 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
441 instancemethod_get_doc(PyObject *self, void *context) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
442 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
443 static PyObject *docstr; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
444 if (docstr == NULL) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
445 docstr = PyUnicode_InternFromString("__doc__"); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
446 if (docstr == NULL) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
447 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
448 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
449 return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
450 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
451 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
452 static PyGetSetDef instancemethod_getset[] = { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
453 {"__doc__", (getter)instancemethod_get_doc, NULL, NULL}, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
454 {0} |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
455 }; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
456 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
457 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
458 instancemethod_getattro(PyObject *self, PyObject *name) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
459 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
460 PyTypeObject *tp = self->ob_type; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
461 PyObject *descr = NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
462 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
463 if (tp->tp_dict == NULL) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
464 if (PyType_Ready(tp) < 0) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
465 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
466 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
467 descr = _PyType_Lookup(tp, name); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
468 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
469 if (descr != NULL) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
470 descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
471 if (f != NULL) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
472 return f(descr, self, (PyObject *)self->ob_type); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
473 else { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
474 Py_INCREF(descr); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
475 return descr; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
476 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
477 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
478 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
479 return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
480 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
481 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
482 static void |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
483 instancemethod_dealloc(PyObject *self) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
484 _PyObject_GC_UNTRACK(self); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
485 Py_DECREF(PyInstanceMethod_GET_FUNCTION(self)); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
486 PyObject_GC_Del(self); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
487 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
488 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
489 static int |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
490 instancemethod_traverse(PyObject *self, visitproc visit, void *arg) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
491 Py_VISIT(PyInstanceMethod_GET_FUNCTION(self)); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
492 return 0; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
493 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
494 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
495 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
496 instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
497 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
498 return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
499 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
500 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
501 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
502 instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
503 register PyObject *func = PyInstanceMethod_GET_FUNCTION(descr); |
|
47259
770e4e132775
#2964: fix missing INCREF.
Georg Brandl <georg@python.org>
parents:
45371
diff
changeset
|
504 if (obj == NULL) { |
|
770e4e132775
#2964: fix missing INCREF.
Georg Brandl <georg@python.org>
parents:
45371
diff
changeset
|
505 Py_INCREF(func); |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
506 return func; |
|
47259
770e4e132775
#2964: fix missing INCREF.
Georg Brandl <georg@python.org>
parents:
45371
diff
changeset
|
507 } |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
508 else |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
509 return PyMethod_New(func, obj); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
510 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
511 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
512 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
513 instancemethod_richcompare(PyObject *self, PyObject *other, int op) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
514 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
515 PyInstanceMethodObject *a, *b; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
516 PyObject *res; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
517 int eq; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
518 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
519 if ((op != Py_EQ && op != Py_NE) || |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
520 !PyInstanceMethod_Check(self) || |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
521 !PyInstanceMethod_Check(other)) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
522 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
523 Py_INCREF(Py_NotImplemented); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
524 return Py_NotImplemented; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
525 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
526 a = (PyInstanceMethodObject *)self; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
527 b = (PyInstanceMethodObject *)other; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
528 eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
529 if (eq < 0) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
530 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
531 if (op == Py_EQ) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
532 res = eq ? Py_True : Py_False; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
533 else |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
534 res = eq ? Py_False : Py_True; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
535 Py_INCREF(res); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
536 return res; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
537 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
538 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
539 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
540 instancemethod_repr(PyObject *self) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
541 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
542 PyObject *func = PyInstanceMethod_Function(self); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
543 PyObject *funcname = NULL , *result = NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
544 char *defname = "?"; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
545 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
546 if (func == NULL) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
547 PyErr_BadInternalCall(); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
548 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
549 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
550 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
551 funcname = PyObject_GetAttrString(func, "__name__"); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
552 if (funcname == NULL) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
553 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
554 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
555 PyErr_Clear(); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
556 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
557 else if (!PyUnicode_Check(funcname)) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
558 Py_DECREF(funcname); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
559 funcname = NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
560 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
561 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
562 result = PyUnicode_FromFormat("<instancemethod %V at %p>", |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
563 funcname, defname, self); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
564 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
565 Py_XDECREF(funcname); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
566 return result; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
567 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
568 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
569 /* |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
570 static long |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
571 instancemethod_hash(PyObject *self) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
572 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
573 long x, y; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
574 x = (long)self; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
575 y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self)); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
576 if (y == -1) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
577 return -1; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
578 x = x ^ y; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
579 if (x == -1) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
580 x = -2; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
581 return x; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
582 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
583 */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
584 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
585 PyDoc_STRVAR(instancemethod_doc, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
586 "instancemethod(function)\n\ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
587 \n\ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
588 Bind a function to a class."); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
589 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
590 static PyObject * |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
591 instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
592 { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
593 PyObject *func; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
594 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
595 if (!_PyArg_NoKeywords("instancemethod", kw)) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
596 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
597 if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func)) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
598 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
599 if (!PyCallable_Check(func)) { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
600 PyErr_SetString(PyExc_TypeError, |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
601 "first argument must be callable"); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
602 return NULL; |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
603 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
604 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
605 return PyInstanceMethod_New(func); |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
606 } |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
607 |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
608 PyTypeObject PyInstanceMethod_Type = { |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
609 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
610 "instancemethod", /* tp_name */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
611 sizeof(PyInstanceMethodObject), /* tp_basicsize */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
612 0, /* tp_itemsize */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
613 instancemethod_dealloc, /* tp_dealloc */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
614 0, /* tp_print */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
615 0, /* tp_getattr */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
616 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47259
diff
changeset
|
617 0, /* tp_reserved */ |
|
44272
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
618 (reprfunc)instancemethod_repr, /* tp_repr */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
619 0, /* tp_as_number */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
620 0, /* tp_as_sequence */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
621 0, /* tp_as_mapping */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
622 0, /*(hashfunc)instancemethod_hash, tp_hash */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
623 instancemethod_call, /* tp_call */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
624 0, /* tp_str */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
625 instancemethod_getattro, /* tp_getattro */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
626 PyObject_GenericSetAttr, /* tp_setattro */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
627 0, /* tp_as_buffer */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
628 Py_TPFLAGS_DEFAULT |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
629 | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
630 instancemethod_doc, /* tp_doc */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
631 instancemethod_traverse, /* tp_traverse */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
632 0, /* tp_clear */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
633 instancemethod_richcompare, /* tp_richcompare */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
634 0, /* tp_weaklistoffset */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
635 0, /* tp_iter */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
636 0, /* tp_iternext */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
637 0, /* tp_methods */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
638 instancemethod_memberlist, /* tp_members */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
639 instancemethod_getset, /* tp_getset */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
640 0, /* tp_base */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
641 0, /* tp_dict */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
642 instancemethod_descr_get, /* tp_descr_get */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
643 0, /* tp_descr_set */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
644 0, /* tp_dictoffset */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
645 0, /* tp_init */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
646 0, /* tp_alloc */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
647 instancemethod_new, /* tp_new */ |
|
3e0867a07765
Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
Christian Heimes <christian@cheimes.de>
parents:
44233
diff
changeset
|
648 }; |
