Mercurial > cpython-lru_cache-weakref
annotate Objects/methodobject.c @ 27210:428eecdfd57f legacy-trunk
Get build working on Redhat 7.2 linux 2.4.7
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Fri, 10 Jan 2003 21:27:54 +0000 |
| parents | bd750378d5c1 |
| children | faabd9867fb8 |
| 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" |
| 6 | 5 |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
6 static PyCFunctionObject *free_list = NULL; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
7 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
8 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
9 PyCFunction_New(PyMethodDef *ml, PyObject *self) |
| 6 | 10 { |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
11 PyCFunctionObject *op; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
12 op = free_list; |
| 6 | 13 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
|
14 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
|
15 PyObject_INIT(op, &PyCFunction_Type); |
| 6 | 16 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
17 else { |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
18 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
|
19 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
|
20 return NULL; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
21 } |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
22 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
|
23 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
|
24 op->m_self = self; |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
25 _PyObject_GC_TRACK(op); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
26 return (PyObject *)op; |
| 6 | 27 } |
| 28 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
29 PyCFunction |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
30 PyCFunction_GetFunction(PyObject *op) |
| 6 | 31 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
32 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
33 PyErr_BadInternalCall(); |
| 6 | 34 return NULL; |
| 35 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
36 return ((PyCFunctionObject *)op) -> m_ml -> ml_meth; |
| 6 | 37 } |
| 38 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
39 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
40 PyCFunction_GetSelf(PyObject *op) |
| 6 | 41 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
42 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
43 PyErr_BadInternalCall(); |
| 6 | 44 return NULL; |
| 45 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
46 return ((PyCFunctionObject *)op) -> m_self; |
| 6 | 47 } |
| 48 | |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
49 int |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
50 PyCFunction_GetFlags(PyObject *op) |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
51 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
52 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
53 PyErr_BadInternalCall(); |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
54 return -1; |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
55 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
56 return ((PyCFunctionObject *)op) -> m_ml -> ml_flags; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
57 } |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
58 |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
59 PyObject * |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
60 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
|
61 { |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
62 PyCFunctionObject* f = (PyCFunctionObject*)func; |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
63 PyCFunction meth = PyCFunction_GET_FUNCTION(func); |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
64 PyObject *self = PyCFunction_GET_SELF(func); |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
65 int size; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
66 |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
67 switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC)) { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
68 case METH_VARARGS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
69 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
|
70 return (*meth)(self, arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
71 break; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
72 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
|
73 case METH_OLDARGS | METH_KEYWORDS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
74 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
|
75 case METH_NOARGS: |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
76 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
|
77 size = PyTuple_GET_SIZE(arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
78 if (size == 0) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
79 return (*meth)(self, NULL); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
80 PyErr_Format(PyExc_TypeError, |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
81 "%.200s() takes no arguments (%d given)", |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
82 f->m_ml->ml_name, size); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
83 return NULL; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
84 } |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
85 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
|
86 case METH_O: |
|
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 == 1) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
90 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
|
91 PyErr_Format(PyExc_TypeError, |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
92 "%.200s() takes exactly one argument (%d given)", |
|
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_OLDARGS: |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
98 /* the really old style */ |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
99 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
|
100 size = PyTuple_GET_SIZE(arg); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
101 if (size == 1) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
102 arg = PyTuple_GET_ITEM(arg, 0); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
103 else if (size == 0) |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
104 arg = NULL; |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
105 return (*meth)(self, arg); |
|
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 default: |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19198
diff
changeset
|
109 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
|
110 return NULL; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
111 } |
|
27072
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
112 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
|
113 f->m_ml->ml_name); |
|
1564c6839e6b
SF Patch #661440: Refactor and streamline PyCFunction_Call
Raymond Hettinger <python@rcn.com>
parents:
22613
diff
changeset
|
114 return NULL; |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
115 } |
|
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
116 |
| 6 | 117 /* Methods (the standard built-in methods, that is) */ |
| 118 | |
| 119 static void | |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
120 meth_dealloc(PyCFunctionObject *m) |
| 6 | 121 { |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
122 _PyObject_GC_UNTRACK(m); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
123 Py_XDECREF(m->m_self); |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
124 m->m_self = (PyObject *)free_list; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
125 free_list = m; |
| 6 | 126 } |
| 127 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
128 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
129 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
|
130 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
131 char *doc = m->m_ml->ml_doc; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
132 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
133 if (doc != NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
134 return PyString_FromString(doc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
135 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
136 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
137 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
138 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
139 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
140 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
|
141 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
142 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
|
143 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
144 |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
145 static int |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
146 meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg) |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
147 { |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
148 if (m->m_self != NULL) |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
149 return visit(m->m_self, arg); |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
150 else |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
151 return 0; |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
152 } |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
153 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
154 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
155 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
|
156 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
157 PyObject *self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
158 if (PyEval_GetRestricted()) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
159 PyErr_SetString(PyExc_RuntimeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
160 "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
|
161 return NULL; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
162 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
163 self = m->m_self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
164 if (self == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
165 self = Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
166 Py_INCREF(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
167 return self; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
168 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
169 |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
19599
diff
changeset
|
170 static PyGetSetDef meth_getsets [] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
171 {"__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
|
172 {"__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
|
173 {"__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
|
174 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
175 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
176 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
177 static PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
178 meth_repr(PyCFunctionObject *m) |
| 6 | 179 { |
| 180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 m->m_self); |
| 6 | 187 } |
| 188 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
189 static int |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
190 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
|
191 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 return 0; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
196 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
|
197 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
198 else |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
199 return 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
200 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
201 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
202 static long |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
203 meth_hash(PyCFunctionObject *a) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
204 { |
|
13141
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
205 long x,y; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
206 if (a->m_self == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
207 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
208 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
209 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
|
210 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
211 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
212 } |
|
13252
310d7cbba329
Fix an error on AIX by using a proper cast.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
213 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
|
214 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
|
215 return -1; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
216 x ^= y; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
217 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
|
218 x = -2; |
|
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
219 return x; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
220 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
221 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
222 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
223 PyTypeObject PyCFunction_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
224 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 225 0, |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
226 "builtin_function_or_method", |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
227 sizeof(PyCFunctionObject), |
| 6 | 228 0, |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
229 (destructor)meth_dealloc, /* tp_dealloc */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
230 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
231 0, /* tp_getattr */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
232 0, /* tp_setattr */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
233 (cmpfunc)meth_compare, /* tp_compare */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
234 (reprfunc)meth_repr, /* tp_repr */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
235 0, /* tp_as_number */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
236 0, /* tp_as_sequence */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
237 0, /* tp_as_mapping */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
238 (hashfunc)meth_hash, /* tp_hash */ |
|
19198
3c1c9948ff65
Remove much dead code from ceval.c
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18933
diff
changeset
|
239 PyCFunction_Call, /* tp_call */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
240 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
241 PyObject_GenericGetAttr, /* tp_getattro */ |
|
18512
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
242 0, /* tp_setattro */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
243 0, /* tp_as_buffer */ |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
244 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
|
245 0, /* tp_doc */ |
|
b2bf88e06fc5
GC for method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
246 (traverseproc)meth_traverse, /* tp_traverse */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
247 0, /* tp_clear */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
248 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
249 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
250 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
251 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
252 0, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
253 0, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
254 meth_getsets, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
255 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18512
diff
changeset
|
256 0, /* tp_dict */ |
| 6 | 257 }; |
| 86 | 258 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
259 /* List all methods in a chain -- helper for findmethodinchain */ |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
260 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
261 static PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
262 listmethodchain(PyMethodChain *chain) |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
263 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
264 PyMethodChain *c; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
265 PyMethodDef *ml; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
266 int i, n; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
267 PyObject *v; |
|
27093
bd750378d5c1
PyCFunction_Call(): Combined two switch cases w/ identical bodies.
Tim Peters <tim.peters@gmail.com>
parents:
27072
diff
changeset
|
268 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
269 n = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
270 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
|
271 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
|
272 n++; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
273 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
274 v = PyList_New(n); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
275 if (v == NULL) |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
276 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
277 i = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 i++; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
282 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
283 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
284 if (PyErr_Occurred()) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
285 Py_DECREF(v); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
286 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
287 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
288 PyList_Sort(v); |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
289 return v; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
290 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
291 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
292 /* Find a method in a method chain */ |
| 86 | 293 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
294 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
295 Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, char *name) |
| 86 | 296 { |
|
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
|
297 if (name[0] == '_' && name[1] == '_') { |
|
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
|
298 if (strcmp(name, "__methods__") == 0) |
|
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
|
299 return listmethodchain(chain); |
|
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
|
300 if (strcmp(name, "__doc__") == 0) { |
|
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
|
301 char *doc = self->ob_type->tp_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
|
302 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
|
303 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
|
304 } |
|
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
|
305 } |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
306 while (chain != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
307 PyMethodDef *ml = chain->methods; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
308 for (; ml->ml_name != NULL; ml++) { |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
309 if (name[0] == ml->ml_name[0] && |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
310 strcmp(name+1, ml->ml_name+1) == 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
311 return PyCFunction_New(ml, self); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
312 } |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
313 chain = chain->link; |
| 86 | 314 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
315 PyErr_SetString(PyExc_AttributeError, name); |
| 86 | 316 return NULL; |
| 317 } | |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
318 |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
319 /* 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
|
320 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
321 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
322 Py_FindMethod(PyMethodDef *methods, PyObject *self, char *name) |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
323 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
324 PyMethodChain chain; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
325 chain.methods = methods; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
326 chain.link = NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
327 return Py_FindMethodInChain(&chain, self, name); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
328 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
329 |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
330 /* 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
|
331 |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
332 void |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
333 PyCFunction_Fini(void) |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
334 { |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
335 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
|
336 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
|
337 free_list = (PyCFunctionObject *)(v->m_self); |
|
22397
132a064da656
Re-enable GC of method objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20015
diff
changeset
|
338 PyObject_GC_Del(v); |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
339 } |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
340 } |
