Mercurial > cpython-lru_cache-weakref
annotate Objects/methodobject.c @ 46075:84bb7701efba legacy-trunk
Make Py3k warnings consistent w.r.t. punctuation; also respect the
EOL 80 limit and supply more alternatives in warning messages.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 25 Mar 2008 08:29:14 +0000 |
| parents | 2275612c16a9 |
| children | aef3501d8e77 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Method object implementation */ |
| 3 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
5 #include "structmember.h" |
| 6 | 6 |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
7 /* Free list for method objects to safe malloc/free overhead |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
8 * The m_self element is used to chain the objects. |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
9 */ |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
10 static PyCFunctionObject *free_list = NULL; |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
11 static int numfree = 0; |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
45189
diff
changeset
|
12 #ifndef PyCFunction_MAXFREELIST |
|
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
45189
diff
changeset
|
13 #define PyCFunction_MAXFREELIST 256 |
|
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
45189
diff
changeset
|
14 #endif |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
15 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
16 PyObject * |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
17 PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) |
| 6 | 18 { |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
19 PyCFunctionObject *op; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
20 op = free_list; |
| 6 | 21 if (op != NULL) { |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
22 free_list = (PyCFunctionObject *)(op->m_self); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
23 PyObject_INIT(op, &PyCFunction_Type); |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
24 numfree--; |
| 6 | 25 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
26 else { |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
27 op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type); |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
28 if (op == NULL) |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
29 return NULL; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
30 } |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
31 op->m_ml = ml; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
32 Py_XINCREF(self); |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
33 op->m_self = self; |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
34 Py_XINCREF(module); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
35 op->m_module = module; |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
36 _PyObject_GC_TRACK(op); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
37 return (PyObject *)op; |
| 6 | 38 } |
| 39 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
40 PyCFunction |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
41 PyCFunction_GetFunction(PyObject *op) |
| 6 | 42 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
43 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
44 PyErr_BadInternalCall(); |
| 6 | 45 return NULL; |
| 46 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
47 return ((PyCFunctionObject *)op) -> m_ml -> ml_meth; |
| 6 | 48 } |
| 49 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
50 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
51 PyCFunction_GetSelf(PyObject *op) |
| 6 | 52 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
53 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
54 PyErr_BadInternalCall(); |
| 6 | 55 return NULL; |
| 56 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
57 return ((PyCFunctionObject *)op) -> m_self; |
| 6 | 58 } |
| 59 | |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
60 int |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
61 PyCFunction_GetFlags(PyObject *op) |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
62 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
63 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
64 PyErr_BadInternalCall(); |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
65 return -1; |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
66 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
67 return ((PyCFunctionObject *)op) -> m_ml -> ml_flags; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
68 } |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
69 |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
70 PyObject * |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
71 PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
72 { |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
73 PyCFunctionObject* f = (PyCFunctionObject*)func; |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
74 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
75 PyObject *self = PyCFunction_GET_SELF(func); |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
76 Py_ssize_t size; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
77 |
|
31172
e4fb6164158c
* Added a new method flag, METH_COEXIST.
Raymond Hettinger <python@rcn.com>
parents:
27941
diff
changeset
|
78 switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
79 case METH_VARARGS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
80 if (kw == NULL || PyDict_Size(kw) == 0) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
81 return (*meth)(self, arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
82 break; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
83 case METH_VARARGS | METH_KEYWORDS: |
|
27093
bd750378d5c1
PyCFunction_Call(): Combined two switch cases w/ identical bodies.
Tim Peters <tim.peters@gmail.com>
parents:
27072
diff
changeset
|
84 case METH_OLDARGS | METH_KEYWORDS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
85 return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
86 case METH_NOARGS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
87 if (kw == NULL || PyDict_Size(kw) == 0) { |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
88 size = PyTuple_GET_SIZE(arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
89 if (size == 0) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
90 return (*meth)(self, NULL); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
91 PyErr_Format(PyExc_TypeError, |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
92 "%.200s() takes no arguments (%zd given)", |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
93 f->m_ml->ml_name, size); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
94 return NULL; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
95 } |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
96 break; |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
97 case METH_O: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
98 if (kw == NULL || PyDict_Size(kw) == 0) { |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
99 size = PyTuple_GET_SIZE(arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
100 if (size == 1) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
101 return (*meth)(self, PyTuple_GET_ITEM(arg, 0)); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
102 PyErr_Format(PyExc_TypeError, |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
103 "%.200s() takes exactly one argument (%zd given)", |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
104 f->m_ml->ml_name, size); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
105 return NULL; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
106 } |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
107 break; |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
108 case METH_OLDARGS: |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
109 /* the really old style */ |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
110 if (kw == NULL || PyDict_Size(kw) == 0) { |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
111 size = PyTuple_GET_SIZE(arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
112 if (size == 1) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
113 arg = PyTuple_GET_ITEM(arg, 0); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
114 else if (size == 0) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
115 arg = NULL; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
116 return (*meth)(self, arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
117 } |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
118 break; |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
119 default: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
120 PyErr_BadInternalCall(); |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
121 return NULL; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
122 } |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
123 PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
124 f->m_ml->ml_name); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
125 return NULL; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
126 } |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
127 |
| 6 | 128 /* Methods (the standard built-in methods, that is) */ |
| 129 | |
| 130 static void | |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
131 meth_dealloc(PyCFunctionObject *m) |
| 6 | 132 { |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
133 _PyObject_GC_UNTRACK(m); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
134 Py_XDECREF(m->m_self); |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
135 Py_XDECREF(m->m_module); |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
45189
diff
changeset
|
136 if (numfree < PyCFunction_MAXFREELIST) { |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
137 m->m_self = (PyObject *)free_list; |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
138 free_list = m; |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
139 numfree++; |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
140 } |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
141 else { |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
142 PyObject_GC_Del(m); |
|
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
143 } |
| 6 | 144 } |
| 145 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
146 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
147 meth_get__doc__(PyCFunctionObject *m, void *closure) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
148 { |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
31172
diff
changeset
|
149 const char *doc = m->m_ml->ml_doc; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
150 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
151 if (doc != NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
152 return PyString_FromString(doc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
153 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
154 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
155 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
156 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
157 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
158 meth_get__name__(PyCFunctionObject *m, void *closure) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
159 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
160 return PyString_FromString(m->m_ml->ml_name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
161 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
162 |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
163 static int |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
164 meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg) |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
165 { |
|
37756
7b2e436a4a21
Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents:
36519
diff
changeset
|
166 Py_VISIT(m->m_self); |
|
7b2e436a4a21
Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents:
36519
diff
changeset
|
167 Py_VISIT(m->m_module); |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
168 return 0; |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
169 } |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
170 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
171 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
172 meth_get__self__(PyCFunctionObject *m, void *closure) |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
173 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
174 PyObject *self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
175 if (PyEval_GetRestricted()) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
176 PyErr_SetString(PyExc_RuntimeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
177 "method.__self__ not accessible in restricted mode"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
178 return NULL; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
179 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
180 self = m->m_self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
181 if (self == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
182 self = Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
183 Py_INCREF(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
184 return self; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
185 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
186 |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
19599
diff
changeset
|
187 static PyGetSetDef meth_getsets [] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
188 {"__doc__", (getter)meth_get__doc__, NULL, NULL}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
189 {"__name__", (getter)meth_get__name__, NULL, NULL}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
190 {"__self__", (getter)meth_get__self__, NULL, NULL}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
191 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
192 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
193 |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
194 #define OFF(x) offsetof(PyCFunctionObject, x) |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
195 |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
196 static PyMemberDef meth_members[] = { |
|
43972
a8dd8874ff2d
Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
197 {"__module__", T_OBJECT, OFF(m_module), PY_WRITE_RESTRICTED}, |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
198 {NULL} |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
199 }; |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
200 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
201 static PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
202 meth_repr(PyCFunctionObject *m) |
| 6 | 203 { |
| 204 if (m->m_self == NULL) | |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
205 return PyString_FromFormat("<built-in function %s>", |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
206 m->m_ml->ml_name); |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
207 return PyString_FromFormat("<built-in method %s of %s object at %p>", |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
208 m->m_ml->ml_name, |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
209 m->m_self->ob_type->tp_name, |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19301
diff
changeset
|
210 m->m_self); |
| 6 | 211 } |
| 212 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
213 static int |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
214 meth_compare(PyCFunctionObject *a, PyCFunctionObject *b) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
215 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
216 if (a->m_self != b->m_self) |
|
9592
2aafcee220bc
When comparing bound methods, use identity test on the objects,
Guido van Rossum <guido@python.org>
parents:
8656
diff
changeset
|
217 return (a->m_self < b->m_self) ? -1 : 1; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
218 if (a->m_ml->ml_meth == b->m_ml->ml_meth) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
219 return 0; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
220 if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
221 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
222 else |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
223 return 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
224 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
225 |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
226 static PyObject * |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
227 meth_richcompare(PyObject *self, PyObject *other, int op) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
228 { |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
229 PyCFunctionObject *a, *b; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
230 PyObject *res; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
231 int eq; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
232 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
233 if ((op != Py_EQ && op != Py_NE) || |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
234 !PyCFunction_Check(self) || |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
235 !PyCFunction_Check(other)) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
236 { |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
237 /* Py3K warning if types are not equal and comparison isn't == or != */ |
|
46075
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
238 if (Py_Py3kWarningFlag && |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
239 PyErr_Warn(PyExc_DeprecationWarning, |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
240 "builtin_function_or_method inequality " |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
241 "comparisons not supported in 3.x") < 0) { |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
242 return NULL; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
243 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
244 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
245 Py_INCREF(Py_NotImplemented); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
246 return Py_NotImplemented; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
247 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
248 a = (PyCFunctionObject *)self; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
249 b = (PyCFunctionObject *)other; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
250 eq = a->m_self == b->m_self; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
251 if (eq) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
252 eq = a->m_ml->ml_meth == b->m_ml->ml_meth; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
253 if (op == Py_EQ) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
254 res = eq ? Py_True : Py_False; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
255 else |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
256 res = eq ? Py_False : Py_True; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
257 Py_INCREF(res); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
258 return res; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
259 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
260 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
261 static long |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
262 meth_hash(PyCFunctionObject *a) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
263 { |
|
13141
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
264 long x,y; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
265 if (a->m_self == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
266 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
267 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
268 x = PyObject_Hash(a->m_self); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
269 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
270 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
271 } |
|
13252
310d7cbba329
Fix an error on AIX by using a proper cast.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
272 y = _Py_HashPointer((void*)(a->m_ml->ml_meth)); |
|
13141
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
273 if (y == -1) |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
274 return -1; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
275 x ^= y; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
276 if (x == -1) |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
277 x = -2; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
278 return x; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
279 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
280 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
281 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
282 PyTypeObject PyCFunction_Type = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
37756
diff
changeset
|
283 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
284 "builtin_function_or_method", |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
285 sizeof(PyCFunctionObject), |
| 6 | 286 0, |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
287 (destructor)meth_dealloc, /* tp_dealloc */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
288 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
289 0, /* tp_getattr */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
290 0, /* tp_setattr */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
291 (cmpfunc)meth_compare, /* tp_compare */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
292 (reprfunc)meth_repr, /* tp_repr */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
293 0, /* tp_as_number */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
294 0, /* tp_as_sequence */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
295 0, /* tp_as_mapping */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
296 (hashfunc)meth_hash, /* tp_hash */ |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
297 PyCFunction_Call, /* tp_call */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
298 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
299 PyObject_GenericGetAttr, /* tp_getattro */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
300 0, /* tp_setattro */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
301 0, /* tp_as_buffer */ |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
302 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
303 0, /* tp_doc */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
304 (traverseproc)meth_traverse, /* tp_traverse */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
305 0, /* tp_clear */ |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
45341
diff
changeset
|
306 meth_richcompare, /* tp_richcompare */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
307 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
308 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
309 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
310 0, /* tp_methods */ |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
311 meth_members, /* tp_members */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
312 meth_getsets, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
313 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
314 0, /* tp_dict */ |
| 6 | 315 }; |
| 86 | 316 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
317 /* List all methods in a chain -- helper for findmethodinchain */ |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
318 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
319 static PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
320 listmethodchain(PyMethodChain *chain) |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
321 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
322 PyMethodChain *c; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
323 PyMethodDef *ml; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
324 int i, n; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
325 PyObject *v; |
|
27093
bd750378d5c1
PyCFunction_Call(): Combined two switch cases w/ identical bodies.
Tim Peters <tim.peters@gmail.com>
parents:
27072
diff
changeset
|
326 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
327 n = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
328 for (c = chain; c != NULL; c = c->link) { |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
329 for (ml = c->methods; ml->ml_name != NULL; ml++) |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
330 n++; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
331 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
332 v = PyList_New(n); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
333 if (v == NULL) |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
334 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
335 i = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
336 for (c = chain; c != NULL; c = c->link) { |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
337 for (ml = c->methods; ml->ml_name != NULL; ml++) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
338 PyList_SetItem(v, i, PyString_FromString(ml->ml_name)); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
339 i++; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
340 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
341 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
342 if (PyErr_Occurred()) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
343 Py_DECREF(v); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
344 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
345 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
346 PyList_Sort(v); |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
347 return v; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
348 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
349 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
350 /* Find a method in a method chain */ |
| 86 | 351 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
352 PyObject * |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
31172
diff
changeset
|
353 Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name) |
| 86 | 354 { |
|
8565
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
355 if (name[0] == '_' && name[1] == '_') { |
|
45984
2275612c16a9
#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents:
45885
diff
changeset
|
356 if (strcmp(name, "__methods__") == 0) { |
|
46075
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
357 if (Py_Py3kWarningFlag && |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
358 PyErr_Warn(PyExc_DeprecationWarning, |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
359 "__methods__ not supported in 3.x") < 0) |
|
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45984
diff
changeset
|
360 return NULL; |
|
8565
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
361 return listmethodchain(chain); |
|
45984
2275612c16a9
#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents:
45885
diff
changeset
|
362 } |
|
8565
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
363 if (strcmp(name, "__doc__") == 0) { |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
31172
diff
changeset
|
364 const char *doc = self->ob_type->tp_doc; |
|
8565
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
365 if (doc != NULL) |
|
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
366 return PyString_FromString(doc); |
|
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
367 } |
|
19e8016cd38c
New feature: if the object's type has a non-NULL tp_doc field, that
Guido van Rossum <guido@python.org>
parents:
5934
diff
changeset
|
368 } |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
369 while (chain != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
370 PyMethodDef *ml = chain->methods; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
371 for (; ml->ml_name != NULL; ml++) { |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
372 if (name[0] == ml->ml_name[0] && |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
373 strcmp(name+1, ml->ml_name+1) == 0) |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
374 /* XXX */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
375 return PyCFunction_New(ml, self); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
376 } |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
377 chain = chain->link; |
| 86 | 378 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
379 PyErr_SetString(PyExc_AttributeError, name); |
| 86 | 380 return NULL; |
| 381 } | |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
382 |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
383 /* Find a method in a single method list */ |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
384 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
385 PyObject * |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
31172
diff
changeset
|
386 Py_FindMethod(PyMethodDef *methods, PyObject *self, const char *name) |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
387 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
388 PyMethodChain chain; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
389 chain.methods = methods; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
390 chain.link = NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
391 return Py_FindMethodInChain(&chain, self, name); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
392 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
393 |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
394 /* Clear out the free list */ |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
395 |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
396 int |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
397 PyCFunction_ClearFreeList(void) |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
398 { |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
399 int freelist_size = numfree; |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
400 |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
401 while (free_list) { |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
402 PyCFunctionObject *v = free_list; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
403 free_list = (PyCFunctionObject *)(v->m_self); |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
404 PyObject_GC_Del(v); |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
405 numfree--; |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
406 } |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
407 assert(numfree == 0); |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
408 return freelist_size; |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
409 } |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
410 |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
411 void |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
412 PyCFunction_Fini(void) |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
413 { |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
414 (void)PyCFunction_ClearFreeList(); |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
415 } |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
416 |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
417 /* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(), |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
418 but it's part of the API so we need to keep a function around that |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
419 existing C extensions can call. |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
420 */ |
|
45189
a4c87c889648
Limit free list of method and builtin function objects to 256 entries each.
Christian Heimes <christian@cheimes.de>
parents:
43972
diff
changeset
|
421 |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
422 #undef PyCFunction_New |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
423 PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
424 |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
425 PyObject * |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
426 PyCFunction_New(PyMethodDef *ml, PyObject *self) |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
427 { |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
428 return PyCFunction_NewEx(ml, self, NULL); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27093
diff
changeset
|
429 } |
