Mercurial > cpython-lru_cache-weakref
annotate Objects/methodobject.c @ 7278:59d2761ba1cf legacy-trunk
Remove obsolete pagenumbering / pagestyle cruft.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Fri, 13 Feb 1998 07:08:56 +0000 |
| parents | 0369d63b100b |
| children | 19e8016cd38c |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2864
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 6 | 32 /* Method object implementation */ |
| 33 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
34 #include "Python.h" |
| 6 | 35 |
| 36 #include "token.h" | |
| 37 | |
| 38 typedef struct { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
39 PyObject_HEAD |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
40 PyMethodDef *m_ml; |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
41 PyObject *m_self; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
42 } PyCFunctionObject; |
| 6 | 43 |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
44 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
|
45 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
46 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
47 PyCFunction_New(ml, self) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
48 PyMethodDef *ml; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
49 PyObject *self; |
| 6 | 50 { |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
51 PyCFunctionObject *op; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
52 op = free_list; |
| 6 | 53 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
|
54 free_list = (PyCFunctionObject *)(op->m_self); |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
55 op->ob_type = &PyCFunction_Type; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
56 _Py_NewReference(op); |
| 6 | 57 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
58 else { |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
59 op = PyObject_NEW(PyCFunctionObject, &PyCFunction_Type); |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
60 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
|
61 return NULL; |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
62 } |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
63 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
|
64 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
|
65 op->m_self = self; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
66 return (PyObject *)op; |
| 6 | 67 } |
| 68 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
69 PyCFunction |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
70 PyCFunction_GetFunction(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
71 PyObject *op; |
| 6 | 72 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
73 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
74 PyErr_BadInternalCall(); |
| 6 | 75 return NULL; |
| 76 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
77 return ((PyCFunctionObject *)op) -> m_ml -> ml_meth; |
| 6 | 78 } |
| 79 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
80 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
81 PyCFunction_GetSelf(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
82 PyObject *op; |
| 6 | 83 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
84 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
85 PyErr_BadInternalCall(); |
| 6 | 86 return NULL; |
| 87 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
88 return ((PyCFunctionObject *)op) -> m_self; |
| 6 | 89 } |
| 90 | |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
91 int |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
92 PyCFunction_GetFlags(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
93 PyObject *op; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
94 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
95 if (!PyCFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
96 PyErr_BadInternalCall(); |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
97 return -1; |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
98 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
99 return ((PyCFunctionObject *)op) -> m_ml -> ml_flags; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
100 } |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
101 |
| 6 | 102 /* Methods (the standard built-in methods, that is) */ |
| 103 | |
| 104 static void | |
| 105 meth_dealloc(m) | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
106 PyCFunctionObject *m; |
| 6 | 107 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
108 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
|
109 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
|
110 free_list = m; |
| 6 | 111 } |
| 112 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
113 static PyObject * |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
114 meth_getattr(m, name) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
115 PyCFunctionObject *m; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
116 char *name; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
117 { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
118 if (strcmp(name, "__name__") == 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
119 return PyString_FromString(m->m_ml->ml_name); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
120 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
121 if (strcmp(name, "__doc__") == 0) { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
122 char *doc = m->m_ml->ml_doc; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
123 if (doc != NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
124 return PyString_FromString(doc); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
125 Py_INCREF(Py_None); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
126 return Py_None; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
127 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
128 if (strcmp(name, "__self__") == 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
129 PyObject *self; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
130 if (PyEval_GetRestricted()) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
131 PyErr_SetString(PyExc_RuntimeError, |
|
2105
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
132 "method.__self__ not accessible in restricted mode"); |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
133 return NULL; |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
134 } |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
135 self = m->m_self; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
136 if (self == NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
137 self = Py_None; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
138 Py_INCREF(self); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
139 return self; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
140 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
141 if (strcmp(name, "__members__") == 0) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
142 return Py_BuildValue("[sss]", |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
143 "__doc__", "__name__", "__self__"); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
144 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
145 PyErr_SetString(PyExc_AttributeError, name); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
146 return NULL; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
147 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
148 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
149 static PyObject * |
| 6 | 150 meth_repr(m) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
151 PyCFunctionObject *m; |
| 6 | 152 { |
| 153 char buf[200]; | |
| 154 if (m->m_self == NULL) | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
155 sprintf(buf, "<built-in function %.80s>", m->m_ml->ml_name); |
| 6 | 156 else |
| 86 | 157 sprintf(buf, |
|
1290
7971fecbf28e
* Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
158 "<built-in method %.80s of %.80s object at %lx>", |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
159 m->m_ml->ml_name, m->m_self->ob_type->tp_name, |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
160 (long)m->m_self); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
161 return PyString_FromString(buf); |
| 6 | 162 } |
| 163 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
164 static int |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
165 meth_compare(a, b) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
166 PyCFunctionObject *a, *b; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
167 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
168 if (a->m_self != b->m_self) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
169 return PyObject_Compare(a->m_self, b->m_self); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
170 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
|
171 return 0; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
172 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
|
173 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
174 else |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
175 return 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
176 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
177 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
178 static long |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
179 meth_hash(a) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
180 PyCFunctionObject *a; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
181 { |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
182 long x; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
183 if (a->m_self == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
184 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
185 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
186 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
|
187 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
188 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
189 } |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
190 return x ^ (long) a->m_ml->ml_meth; |
|
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 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
193 PyTypeObject PyCFunction_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
194 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 195 0, |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
196 "builtin_function_or_method", |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
197 sizeof(PyCFunctionObject), |
| 6 | 198 0, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
199 (destructor)meth_dealloc, /*tp_dealloc*/ |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
200 0, /*tp_print*/ |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
201 (getattrfunc)meth_getattr, /*tp_getattr*/ |
| 6 | 202 0, /*tp_setattr*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
203 (cmpfunc)meth_compare, /*tp_compare*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
204 (reprfunc)meth_repr, /*tp_repr*/ |
| 6 | 205 0, /*tp_as_number*/ |
| 206 0, /*tp_as_sequence*/ | |
| 207 0, /*tp_as_mapping*/ | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
208 (hashfunc)meth_hash, /*tp_hash*/ |
| 6 | 209 }; |
| 86 | 210 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
211 /* List all methods in a chain -- helper for findmethodinchain */ |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
212 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
213 static PyObject * |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
214 listmethodchain(chain) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
215 PyMethodChain *chain; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
216 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
217 PyMethodChain *c; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
218 PyMethodDef *ml; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
219 int i, n; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
220 PyObject *v; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
221 |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
222 n = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
223 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
|
224 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
|
225 n++; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
226 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
227 v = PyList_New(n); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
228 if (v == NULL) |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
229 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
230 i = 0; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 i++; |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
235 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
236 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
237 if (PyErr_Occurred()) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
238 Py_DECREF(v); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
239 return NULL; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
240 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
241 PyList_Sort(v); |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
242 return v; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
243 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
244 |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
245 /* Find a method in a method chain */ |
| 86 | 246 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
247 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
248 Py_FindMethodInChain(chain, self, name) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
249 PyMethodChain *chain; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
250 PyObject *self; |
| 86 | 251 char *name; |
| 252 { | |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
253 if (strcmp(name, "__methods__") == 0) |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
254 return listmethodchain(chain); |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
255 while (chain != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
256 PyMethodDef *ml = chain->methods; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
257 for (; ml->ml_name != NULL; ml++) { |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
258 if (name[0] == ml->ml_name[0] && |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
259 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
|
260 return PyCFunction_New(ml, self); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
261 } |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
262 chain = chain->link; |
| 86 | 263 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
264 PyErr_SetString(PyExc_AttributeError, name); |
| 86 | 265 return NULL; |
| 266 } | |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
267 |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
268 /* 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
|
269 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
270 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
271 Py_FindMethod(methods, self, name) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
272 PyMethodDef *methods; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
273 PyObject *self; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
274 char *name; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
275 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
276 PyMethodChain chain; |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
277 chain.methods = methods; |
|
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
278 chain.link = NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
279 return Py_FindMethodInChain(&chain, self, name); |
|
2256
d091b246a3a7
added findmethodinchain and methodchain data types
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
280 } |
|
5934
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
281 |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
282 /* 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
|
283 |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
284 void |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
285 PyCFunction_Fini() |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
286 { |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
287 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
|
288 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
|
289 free_list = (PyCFunctionObject *)(v->m_self); |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
290 PyMem_DEL(v); |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
291 } |
|
0369d63b100b
Added separate free list for cfunction (builtin method) objects, for a
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
292 } |
