Mercurial > cpython-lru_cache-weakref
annotate Objects/typeobject.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 | 22d660494f29 |
| children | e0fa52067dbe |
| rev | line source |
|---|---|
| 6 | 1 /* Type object implementation */ |
| 2 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
3 #include "Python.h" |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4 #include "structmember.h" |
| 6 | 5 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
6 #include <ctype.h> |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
7 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
8 /* The *real* layout of a type object when allocated on the heap */ |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
9 /* XXX Should we publish this in a header file? */ |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
10 typedef struct { |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
11 /* Note: there's a dependency on the order of these members |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
12 in slotptr() below. */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
13 PyTypeObject type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
14 PyNumberMethods as_number; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
15 PyMappingMethods as_mapping; |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
16 PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
17 so that the mapping wins when both |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
18 the mapping and the sequence define |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
19 a given operator (e.g. __getitem__). |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
20 see add_operators() below. */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
21 PyBufferProcs as_buffer; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
22 PyObject *name, *slots; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
23 PyMemberDef members[1]; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
24 } etype; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
25 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
26 static PyMemberDef type_members[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
27 {"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
28 {"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
29 {"__flags__", T_LONG, offsetof(PyTypeObject, tp_flags), READONLY}, |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
30 {"__weakrefoffset__", T_LONG, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
31 offsetof(PyTypeObject, tp_weaklistoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
32 {"__base__", T_OBJECT, offsetof(PyTypeObject, tp_base), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
33 {"__dictoffset__", T_LONG, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
34 offsetof(PyTypeObject, tp_dictoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
35 {"__mro__", T_OBJECT, offsetof(PyTypeObject, tp_mro), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
36 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
37 }; |
| 6 | 38 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
39 static PyObject * |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
40 type_name(PyTypeObject *type, void *context) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
41 { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
42 char *s; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
43 |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
44 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
45 etype* et = (etype*)type; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
46 |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
47 Py_INCREF(et->name); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
48 return et->name; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
49 } |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
50 else { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
51 s = strrchr(type->tp_name, '.'); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
52 if (s == NULL) |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
53 s = type->tp_name; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
54 else |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
55 s++; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
56 return PyString_FromString(s); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
57 } |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
58 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
59 |
| 26421 | 60 static int |
| 61 type_set_name(PyTypeObject *type, PyObject *value, void *context) | |
| 62 { | |
| 63 etype* et; | |
| 64 | |
| 65 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
| 66 PyErr_Format(PyExc_TypeError, | |
| 67 "can't set %s.__name__", type->tp_name); | |
| 68 return -1; | |
| 69 } | |
| 70 if (!value) { | |
| 71 PyErr_Format(PyExc_TypeError, | |
| 72 "can't delete %s.__name__", type->tp_name); | |
| 73 return -1; | |
| 74 } | |
| 75 if (!PyString_Check(value)) { | |
| 76 PyErr_Format(PyExc_TypeError, | |
| 77 "can only assign string to %s.__name__, not '%s'", | |
| 78 type->tp_name, value->ob_type->tp_name); | |
| 79 return -1; | |
| 80 } | |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
81 if (strlen(PyString_AS_STRING(value)) |
| 26421 | 82 != (size_t)PyString_GET_SIZE(value)) { |
| 83 PyErr_Format(PyExc_ValueError, | |
| 84 "__name__ must not contain null bytes"); | |
| 85 return -1; | |
| 86 } | |
| 87 | |
| 88 et = (etype*)type; | |
| 89 | |
| 90 Py_INCREF(value); | |
| 91 | |
| 92 Py_DECREF(et->name); | |
| 93 et->name = value; | |
| 94 | |
| 95 type->tp_name = PyString_AS_STRING(value); | |
| 96 | |
| 97 return 0; | |
| 98 } | |
| 99 | |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
100 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
101 type_module(PyTypeObject *type, void *context) |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
102 { |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
103 PyObject *mod; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
104 char *s; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
105 |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
106 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
107 mod = PyDict_GetItemString(type->tp_dict, "__module__"); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
108 Py_XINCREF(mod); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
109 return mod; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
110 } |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
111 else { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
112 s = strrchr(type->tp_name, '.'); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
113 if (s != NULL) |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
114 return PyString_FromStringAndSize( |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
115 type->tp_name, (int)(s - type->tp_name)); |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
116 return PyString_FromString("__builtin__"); |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
117 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
118 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
119 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
120 static int |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
121 type_set_module(PyTypeObject *type, PyObject *value, void *context) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
122 { |
| 26421 | 123 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
124 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
125 "can't set %s.__module__", type->tp_name); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
126 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
127 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
128 if (!value) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
129 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
130 "can't delete %s.__module__", type->tp_name); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
131 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
132 } |
| 26421 | 133 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
134 return PyDict_SetItemString(type->tp_dict, "__module__", value); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
135 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
136 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
137 static PyObject * |
| 26421 | 138 type_get_bases(PyTypeObject *type, void *context) |
| 139 { | |
| 140 Py_INCREF(type->tp_bases); | |
| 141 return type->tp_bases; | |
| 142 } | |
| 143 | |
| 144 static PyTypeObject *best_base(PyObject *); | |
| 145 static int mro_internal(PyTypeObject *); | |
| 146 static int compatible_for_assignment(PyTypeObject *, PyTypeObject *, char *); | |
| 147 static int add_subclass(PyTypeObject*, PyTypeObject*); | |
| 148 static void remove_subclass(PyTypeObject *, PyTypeObject *); | |
| 149 static void update_all_slots(PyTypeObject *); | |
| 150 | |
| 151 static int | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
152 mro_subclasses(PyTypeObject *type, PyObject* temp) |
| 26421 | 153 { |
| 154 PyTypeObject *subclass; | |
| 155 PyObject *ref, *subclasses, *old_mro; | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
156 int i, n; |
| 26421 | 157 |
| 158 subclasses = type->tp_subclasses; | |
| 159 if (subclasses == NULL) | |
| 160 return 0; | |
| 161 assert(PyList_Check(subclasses)); | |
| 162 n = PyList_GET_SIZE(subclasses); | |
| 163 for (i = 0; i < n; i++) { | |
| 164 ref = PyList_GET_ITEM(subclasses, i); | |
| 165 assert(PyWeakref_CheckRef(ref)); | |
| 166 subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref); | |
| 167 assert(subclass != NULL); | |
| 168 if ((PyObject *)subclass == Py_None) | |
| 169 continue; | |
| 170 assert(PyType_Check(subclass)); | |
| 171 old_mro = subclass->tp_mro; | |
| 172 if (mro_internal(subclass) < 0) { | |
| 173 subclass->tp_mro = old_mro; | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
174 return -1; |
| 26421 | 175 } |
| 176 else { | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
177 PyObject* tuple; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
178 tuple = Py_BuildValue("OO", subclass, old_mro); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
179 if (!tuple) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
180 return -1; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
181 if (PyList_Append(temp, tuple) < 0) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
182 return -1; |
| 26421 | 183 } |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
184 if (mro_subclasses(subclass, temp) < 0) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
185 return -1; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
186 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
187 return 0; |
| 26421 | 188 } |
| 189 | |
| 190 static int | |
| 191 type_set_bases(PyTypeObject *type, PyObject *value, void *context) | |
| 192 { | |
| 193 int i, r = 0; | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
194 PyObject *ob, *temp; |
| 26421 | 195 PyTypeObject *new_base, *old_base; |
| 196 PyObject *old_bases, *old_mro; | |
| 197 | |
| 198 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
| 199 PyErr_Format(PyExc_TypeError, | |
| 200 "can't set %s.__bases__", type->tp_name); | |
| 201 return -1; | |
| 202 } | |
| 203 if (!value) { | |
| 204 PyErr_Format(PyExc_TypeError, | |
| 205 "can't delete %s.__bases__", type->tp_name); | |
| 206 return -1; | |
| 207 } | |
| 208 if (!PyTuple_Check(value)) { | |
| 209 PyErr_Format(PyExc_TypeError, | |
| 210 "can only assign tuple to %s.__bases__, not %s", | |
| 211 type->tp_name, value->ob_type->tp_name); | |
| 212 return -1; | |
| 213 } | |
|
26645
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
214 if (PyTuple_GET_SIZE(value) == 0) { |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
215 PyErr_Format(PyExc_TypeError, |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
216 "can only assign non-empty tuple to %s.__bases__, not ()", |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
217 type->tp_name); |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
218 return -1; |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
219 } |
| 26421 | 220 for (i = 0; i < PyTuple_GET_SIZE(value); i++) { |
| 221 ob = PyTuple_GET_ITEM(value, i); | |
| 222 if (!PyClass_Check(ob) && !PyType_Check(ob)) { | |
| 223 PyErr_Format( | |
| 224 PyExc_TypeError, | |
| 225 "%s.__bases__ must be tuple of old- or new-style classes, not '%s'", | |
| 226 type->tp_name, ob->ob_type->tp_name); | |
| 227 return -1; | |
| 228 } | |
|
26440
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
229 if (PyType_Check(ob)) { |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
230 if (PyType_IsSubtype((PyTypeObject*)ob, type)) { |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
231 PyErr_SetString(PyExc_TypeError, |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
232 "a __bases__ item causes an inheritance cycle"); |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
233 return -1; |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
234 } |
| 26421 | 235 } |
| 236 } | |
| 237 | |
| 238 new_base = best_base(value); | |
| 239 | |
| 240 if (!new_base) { | |
| 241 return -1; | |
| 242 } | |
| 243 | |
| 244 if (!compatible_for_assignment(type->tp_base, new_base, "__bases__")) | |
| 245 return -1; | |
| 246 | |
| 247 Py_INCREF(new_base); | |
| 248 Py_INCREF(value); | |
| 249 | |
| 250 old_bases = type->tp_bases; | |
| 251 old_base = type->tp_base; | |
| 252 old_mro = type->tp_mro; | |
| 253 | |
| 254 type->tp_bases = value; | |
| 255 type->tp_base = new_base; | |
| 256 | |
| 257 if (mro_internal(type) < 0) { | |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
258 goto bail; |
| 26421 | 259 } |
| 260 | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
261 temp = PyList_New(0); |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
262 if (!temp) |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
263 goto bail; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
264 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
265 r = mro_subclasses(type, temp); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
266 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
267 if (r < 0) { |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
268 for (i = 0; i < PyList_Size(temp); i++) { |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
269 PyTypeObject* cls; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
270 PyObject* mro; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
271 PyArg_ParseTuple(PyList_GetItem(temp, i), |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
272 "OO", &cls, &mro); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
273 Py_DECREF(cls->tp_mro); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
274 cls->tp_mro = mro; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
275 Py_INCREF(cls->tp_mro); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
276 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
277 Py_DECREF(temp); |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
278 goto bail; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
279 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
280 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
281 Py_DECREF(temp); |
| 26421 | 282 |
| 283 /* any base that was in __bases__ but now isn't, we | |
| 26660 | 284 need to remove |type| from its tp_subclasses. |
| 26421 | 285 conversely, any class now in __bases__ that wasn't |
| 26660 | 286 needs to have |type| added to its subclasses. */ |
| 26421 | 287 |
| 288 /* for now, sod that: just remove from all old_bases, | |
| 289 add to all new_bases */ | |
| 290 | |
| 291 for (i = PyTuple_GET_SIZE(old_bases) - 1; i >= 0; i--) { | |
| 292 ob = PyTuple_GET_ITEM(old_bases, i); | |
| 293 if (PyType_Check(ob)) { | |
| 294 remove_subclass( | |
| 295 (PyTypeObject*)ob, type); | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 for (i = PyTuple_GET_SIZE(value) - 1; i >= 0; i--) { | |
| 300 ob = PyTuple_GET_ITEM(value, i); | |
| 301 if (PyType_Check(ob)) { | |
| 302 if (add_subclass((PyTypeObject*)ob, type) < 0) | |
| 303 r = -1; | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 update_all_slots(type); | |
| 308 | |
| 309 Py_DECREF(old_bases); | |
| 310 Py_DECREF(old_base); | |
| 311 Py_DECREF(old_mro); | |
| 312 | |
| 313 return r; | |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
314 |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
315 bail: |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
316 type->tp_bases = old_bases; |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
317 type->tp_base = old_base; |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
318 type->tp_mro = old_mro; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
319 |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
320 Py_DECREF(value); |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
321 Py_DECREF(new_base); |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
322 |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
323 return -1; |
| 26421 | 324 } |
| 325 | |
| 326 static PyObject * | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
327 type_dict(PyTypeObject *type, void *context) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
328 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
329 if (type->tp_dict == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
330 Py_INCREF(Py_None); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
331 return Py_None; |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
332 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
333 return PyDictProxy_New(type->tp_dict); |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
334 } |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
335 |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
336 static PyObject * |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
337 type_get_doc(PyTypeObject *type, void *context) |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
338 { |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
339 PyObject *result; |
| 23118 | 340 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
341 return PyString_FromString(type->tp_doc); |
| 23118 | 342 result = PyDict_GetItemString(type->tp_dict, "__doc__"); |
| 343 if (result == NULL) { | |
| 344 result = Py_None; | |
| 345 Py_INCREF(result); | |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
346 } |
| 23118 | 347 else if (result->ob_type->tp_descr_get) { |
|
23127
70650ae1a2cf
type_get_doc(): Squash compiler wng about incompatible ptr types.
Tim Peters <tim.peters@gmail.com>
parents:
23118
diff
changeset
|
348 result = result->ob_type->tp_descr_get(result, NULL, |
|
70650ae1a2cf
type_get_doc(): Squash compiler wng about incompatible ptr types.
Tim Peters <tim.peters@gmail.com>
parents:
23118
diff
changeset
|
349 (PyObject *)type); |
| 23118 | 350 } |
| 351 else { | |
| 352 Py_INCREF(result); | |
| 353 } | |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
354 return result; |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
355 } |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
356 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
357 static PyGetSetDef type_getsets[] = { |
| 26421 | 358 {"__name__", (getter)type_name, (setter)type_set_name, NULL}, |
| 359 {"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL}, | |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
360 {"__module__", (getter)type_module, (setter)type_set_module, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
361 {"__dict__", (getter)type_dict, NULL, NULL}, |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
362 {"__doc__", (getter)type_get_doc, NULL, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
363 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
364 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
365 |
|
18063
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
366 static int |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
367 type_compare(PyObject *v, PyObject *w) |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
368 { |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
369 /* This is called with type objects only. So we |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
370 can just compare the addresses. */ |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
371 Py_uintptr_t vv = (Py_uintptr_t)v; |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
372 Py_uintptr_t ww = (Py_uintptr_t)w; |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
373 return (vv < ww) ? -1 : (vv > ww) ? 1 : 0; |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
374 } |
|
bbac2a6a5d16
Patch #424475: Speed-up tp_compare usage, by special-casing the common
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
375 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
377 type_repr(PyTypeObject *type) |
| 6 | 378 { |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
379 PyObject *mod, *name, *rtn; |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
380 char *kind; |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
381 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
382 mod = type_module(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
383 if (mod == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
384 PyErr_Clear(); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
385 else if (!PyString_Check(mod)) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
386 Py_DECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
387 mod = NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
388 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
389 name = type_name(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
390 if (name == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
391 return NULL; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
392 |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
393 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
394 kind = "class"; |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
395 else |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
396 kind = "type"; |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
397 |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
398 if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) { |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
399 rtn = PyString_FromFormat("<%s '%s.%s'>", |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
400 kind, |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
401 PyString_AS_STRING(mod), |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
402 PyString_AS_STRING(name)); |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
403 } |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
404 else |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
405 rtn = PyString_FromFormat("<%s '%s'>", kind, type->tp_name); |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
406 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
407 Py_XDECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
408 Py_DECREF(name); |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
409 return rtn; |
| 6 | 410 } |
| 411 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
412 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
413 type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
414 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
415 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
416 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
417 if (type->tp_new == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
418 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
419 "cannot create '%.100s' instances", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
420 type->tp_name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
421 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
422 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
423 |
|
19898
fc40d0b54043
type_call(): Change in policy. The keyword args (if any) are now passed
Tim Peters <tim.peters@gmail.com>
parents:
19808
diff
changeset
|
424 obj = type->tp_new(type, args, kwds); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
425 if (obj != NULL) { |
|
20516
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
426 /* Ugly exception: when the call was type(something), |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
427 don't call tp_init on the result. */ |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
428 if (type == &PyType_Type && |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
429 PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 && |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
430 (kwds == NULL || |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
431 (PyDict_Check(kwds) && PyDict_Size(kwds) == 0))) |
|
d21160a92179
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
Guido van Rossum <guido@python.org>
parents:
20499
diff
changeset
|
432 return obj; |
|
22859
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
433 /* If the returned object is not an instance of type, |
|
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
434 it won't be initialized. */ |
|
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
435 if (!PyType_IsSubtype(obj->ob_type, type)) |
|
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
436 return obj; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
437 type = obj->ob_type; |
|
24250
804ea51cfce6
The object returned by tp_new() may not have a tp_init.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24245
diff
changeset
|
438 if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS) && |
|
804ea51cfce6
The object returned by tp_new() may not have a tp_init.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24245
diff
changeset
|
439 type->tp_init != NULL && |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
440 type->tp_init(obj, args, kwds) < 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
441 Py_DECREF(obj); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
442 obj = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
443 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
444 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
445 return obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
446 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
447 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
448 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
449 PyType_GenericAlloc(PyTypeObject *type, int nitems) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
450 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
451 PyObject *obj; |
|
20296
6cc0b48049ec
Guido suggests, and I agree, to insist that SIZEOF_VOID_P be a power of 2.
Tim Peters <tim.peters@gmail.com>
parents:
20294
diff
changeset
|
452 const size_t size = _PyObject_VAR_SIZE(type, nitems); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
453 |
|
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
454 if (PyType_IS_GC(type)) |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
455 obj = _PyObject_GC_Malloc(size); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
456 else |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
457 obj = PyObject_MALLOC(size); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
458 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
459 if (obj == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
460 return PyErr_NoMemory(); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
461 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
462 memset(obj, '\0', size); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
463 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
464 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
465 Py_INCREF(type); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
466 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
467 if (type->tp_itemsize == 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
468 PyObject_INIT(obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
469 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
470 (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
471 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
472 if (PyType_IS_GC(type)) |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
473 _PyObject_GC_TRACK(obj); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
474 return obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
475 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
476 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
477 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
478 PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
479 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
480 return type->tp_alloc(type, 0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
481 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
482 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
483 /* Helpers for subtyping */ |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
484 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
485 static int |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
486 traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
487 { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
488 int i, n; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
489 PyMemberDef *mp; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
490 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
491 n = type->ob_size; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
492 mp = ((etype *)type)->members; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
493 for (i = 0; i < n; i++, mp++) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
494 if (mp->type == T_OBJECT_EX) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
495 char *addr = (char *)self + mp->offset; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
496 PyObject *obj = *(PyObject **)addr; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
497 if (obj != NULL) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
498 int err = visit(obj, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
499 if (err) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
500 return err; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
501 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
502 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
503 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
504 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
505 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
506 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
507 static int |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
508 subtype_traverse(PyObject *self, visitproc visit, void *arg) |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
509 { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
510 PyTypeObject *type, *base; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
511 traverseproc basetraverse; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
512 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
513 /* Find the nearest base with a different tp_traverse, |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
514 and traverse slots while we're at it */ |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
515 type = self->ob_type; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
516 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
517 while ((basetraverse = base->tp_traverse) == subtype_traverse) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
518 if (base->ob_size) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
519 int err = traverse_slots(base, self, visit, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
520 if (err) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
521 return err; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
522 } |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
523 base = base->tp_base; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
524 assert(base); |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
525 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
526 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
527 if (type->tp_dictoffset != base->tp_dictoffset) { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
528 PyObject **dictptr = _PyObject_GetDictPtr(self); |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
529 if (dictptr && *dictptr) { |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
530 int err = visit(*dictptr, arg); |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
531 if (err) |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
532 return err; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
533 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
534 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
535 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
536 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
537 /* For a heaptype, the instances count as references |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
538 to the type. Traverse the type so the collector |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
539 can find cycles involving this link. */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
540 int err = visit((PyObject *)type, arg); |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
541 if (err) |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
542 return err; |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
543 } |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
544 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
545 if (basetraverse) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
546 return basetraverse(self, visit, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
547 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
548 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
549 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
550 static void |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
551 clear_slots(PyTypeObject *type, PyObject *self) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
552 { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
553 int i, n; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
554 PyMemberDef *mp; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
555 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
556 n = type->ob_size; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
557 mp = ((etype *)type)->members; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
558 for (i = 0; i < n; i++, mp++) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
559 if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
560 char *addr = (char *)self + mp->offset; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
561 PyObject *obj = *(PyObject **)addr; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
562 if (obj != NULL) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
563 Py_DECREF(obj); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
564 *(PyObject **)addr = NULL; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
565 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
566 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
567 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
568 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
569 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
570 static int |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
571 subtype_clear(PyObject *self) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
572 { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
573 PyTypeObject *type, *base; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
574 inquiry baseclear; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
575 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
576 /* Find the nearest base with a different tp_clear |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
577 and clear slots while we're at it */ |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
578 type = self->ob_type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
579 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
580 while ((baseclear = base->tp_clear) == subtype_clear) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
581 if (base->ob_size) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
582 clear_slots(base, self); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
583 base = base->tp_base; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
584 assert(base); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
585 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
586 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
587 /* There's no need to clear the instance dict (if any); |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
588 the collector will call its tp_clear handler. */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
589 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
590 if (baseclear) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
591 return baseclear(self); |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
592 return 0; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
593 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
594 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
595 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
596 subtype_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
597 { |
|
21246
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
598 PyTypeObject *type, *base; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
599 destructor basedealloc; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
600 |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
601 /* Extract the type; we expect it to be a heap type */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
602 type = self->ob_type; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
603 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
604 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
605 /* Test whether the type has GC exactly once */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
606 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
607 if (!PyType_IS_GC(type)) { |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
608 /* It's really rare to find a dynamic type that doesn't have |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
609 GC; it can only happen when deriving from 'object' and not |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
610 adding any slots or instance variables. This allows |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
611 certain simplifications: there's no need to call |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
612 clear_slots(), or DECREF the dict, or clear weakrefs. */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
613 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
614 /* Maybe call finalizer; exit early if resurrected */ |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
615 if (type->tp_del) { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
616 type->tp_del(self); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
617 if (self->ob_refcnt > 0) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
618 return; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
619 } |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
620 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
621 /* Find the nearest base with a different tp_dealloc */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
622 base = type; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
623 while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
624 assert(base->ob_size == 0); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
625 base = base->tp_base; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
626 assert(base); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
627 } |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
628 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
629 /* Call the base tp_dealloc() */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
630 assert(basedealloc); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
631 basedealloc(self); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
632 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
633 /* Can't reference self beyond this point */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
634 Py_DECREF(type); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
635 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
636 /* Done */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
637 return; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
638 } |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
639 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
640 /* We get here only if the type has GC */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
641 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
642 /* UnTrack and re-Track around the trashcan macro, alas */ |
|
24653
1ab27c1770df
Fix a subtle bug in the trashcan code I added yesterday to
Guido van Rossum <guido@python.org>
parents:
24614
diff
changeset
|
643 PyObject_GC_UnTrack(self); |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
644 Py_TRASHCAN_SAFE_BEGIN(self); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
645 _PyObject_GC_TRACK(self); /* We'll untrack for real later */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
646 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
647 /* Maybe call finalizer; exit early if resurrected */ |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
648 if (type->tp_del) { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
649 type->tp_del(self); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
650 if (self->ob_refcnt > 0) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
651 goto endlabel; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
652 } |
|
20753
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
653 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
654 /* Find the nearest base with a different tp_dealloc |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
655 and clear slots while we're at it */ |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
656 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
657 while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
658 if (base->ob_size) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
659 clear_slots(base, self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
660 base = base->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
661 assert(base); |
|
21246
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
662 } |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
663 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
664 /* If we added a dict, DECREF it */ |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
665 if (type->tp_dictoffset && !base->tp_dictoffset) { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
666 PyObject **dictptr = _PyObject_GetDictPtr(self); |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
667 if (dictptr != NULL) { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
668 PyObject *dict = *dictptr; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
669 if (dict != NULL) { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
670 Py_DECREF(dict); |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
671 *dictptr = NULL; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
672 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
673 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
674 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
675 |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
676 /* If we added weaklist, we clear it */ |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
677 if (type->tp_weaklistoffset && !base->tp_weaklistoffset) |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
678 PyObject_ClearWeakRefs(self); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
679 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
680 /* Finalize GC if the base doesn't do GC and we do */ |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
681 if (!PyType_IS_GC(base)) |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
682 _PyObject_GC_UNTRACK(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
683 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
684 /* Call the base tp_dealloc() */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
685 assert(basedealloc); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
686 basedealloc(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
687 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
688 /* Can't reference self beyond this point */ |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
689 Py_DECREF(type); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
690 |
|
24653
1ab27c1770df
Fix a subtle bug in the trashcan code I added yesterday to
Guido van Rossum <guido@python.org>
parents:
24614
diff
changeset
|
691 endlabel: |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
692 Py_TRASHCAN_SAFE_END(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
693 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
694 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
695 static PyTypeObject *solid_base(PyTypeObject *type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
696 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
697 /* type test with subclassing support */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
698 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
699 int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
700 PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
701 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
702 PyObject *mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
703 |
|
19803
32cfce4d83dc
PyType_IsSubtype(): test tp_flags for HAVE_CLASS bit before accessing
Guido van Rossum <guido@python.org>
parents:
19630
diff
changeset
|
704 if (!(a->tp_flags & Py_TPFLAGS_HAVE_CLASS)) |
|
32cfce4d83dc
PyType_IsSubtype(): test tp_flags for HAVE_CLASS bit before accessing
Guido van Rossum <guido@python.org>
parents:
19630
diff
changeset
|
705 return b == a || b == &PyBaseObject_Type; |
|
32cfce4d83dc
PyType_IsSubtype(): test tp_flags for HAVE_CLASS bit before accessing
Guido van Rossum <guido@python.org>
parents:
19630
diff
changeset
|
706 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
707 mro = a->tp_mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
708 if (mro != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
709 /* Deal with multiple inheritance without recursion |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
710 by walking the MRO tuple */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
711 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
712 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
713 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
714 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
715 if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
716 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
717 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
718 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
719 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
720 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
721 /* a is not completely initilized yet; follow tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
722 do { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
723 if (a == b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
724 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
725 a = a->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
726 } while (a != NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
727 return b == &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
728 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
729 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
730 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
731 /* Internal routines to do a method lookup in the type |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
732 without looking in the instance dictionary |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
733 (so we can't use PyObject_GetAttr) but still binding |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
734 it to the instance. The arguments are the object, |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
735 the method name as a C string, and the address of a |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
736 static variable used to cache the interned Python string. |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
737 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
738 Two variants: |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
739 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
740 - lookup_maybe() returns NULL without raising an exception |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
741 when the _PyType_Lookup() call fails; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
742 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
743 - lookup_method() always raises an exception upon errors. |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
744 */ |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
745 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
746 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
747 lookup_maybe(PyObject *self, char *attrstr, PyObject **attrobj) |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
748 { |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
749 PyObject *res; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
750 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
751 if (*attrobj == NULL) { |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
752 *attrobj = PyString_InternFromString(attrstr); |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
753 if (*attrobj == NULL) |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
754 return NULL; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
755 } |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
756 res = _PyType_Lookup(self->ob_type, *attrobj); |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
757 if (res != NULL) { |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
758 descrgetfunc f; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
759 if ((f = res->ob_type->tp_descr_get) == NULL) |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
760 Py_INCREF(res); |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
761 else |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
762 res = f(res, self, (PyObject *)(self->ob_type)); |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
763 } |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
764 return res; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
765 } |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
766 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
767 static PyObject * |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
768 lookup_method(PyObject *self, char *attrstr, PyObject **attrobj) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
769 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
770 PyObject *res = lookup_maybe(self, attrstr, attrobj); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
771 if (res == NULL && !PyErr_Occurred()) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
772 PyErr_SetObject(PyExc_AttributeError, *attrobj); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
773 return res; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
774 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
775 |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
776 /* A variation of PyObject_CallMethod that uses lookup_method() |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
777 instead of PyObject_GetAttrString(). This uses the same convention |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
778 as lookup_method to cache the interned name string object. */ |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
779 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
780 static PyObject * |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
781 call_method(PyObject *o, char *name, PyObject **nameobj, char *format, ...) |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
782 { |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
783 va_list va; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
784 PyObject *args, *func = 0, *retval; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
785 va_start(va, format); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
786 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
787 func = lookup_maybe(o, name, nameobj); |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
788 if (func == NULL) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
789 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
790 if (!PyErr_Occurred()) |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
791 PyErr_SetObject(PyExc_AttributeError, *nameobj); |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
792 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
793 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
794 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
795 if (format && *format) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
796 args = Py_VaBuildValue(format, va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
797 else |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
798 args = PyTuple_New(0); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
799 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
800 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
801 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
802 if (args == NULL) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
803 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
804 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
805 assert(PyTuple_Check(args)); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
806 retval = PyObject_Call(func, args, NULL); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
807 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
808 Py_DECREF(args); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
809 Py_DECREF(func); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
810 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
811 return retval; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
812 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
813 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
814 /* Clone of call_method() that returns NotImplemented when the lookup fails. */ |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
815 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
816 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
817 call_maybe(PyObject *o, char *name, PyObject **nameobj, char *format, ...) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
818 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
819 va_list va; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
820 PyObject *args, *func = 0, *retval; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
821 va_start(va, format); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
822 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
823 func = lookup_maybe(o, name, nameobj); |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
824 if (func == NULL) { |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
825 va_end(va); |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
826 if (!PyErr_Occurred()) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
827 Py_INCREF(Py_NotImplemented); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
828 return Py_NotImplemented; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
829 } |
| 19911 | 830 return NULL; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
831 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
832 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
833 if (format && *format) |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
834 args = Py_VaBuildValue(format, va); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
835 else |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
836 args = PyTuple_New(0); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
837 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
838 va_end(va); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
839 |
| 19911 | 840 if (args == NULL) |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
841 return NULL; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
842 |
| 19911 | 843 assert(PyTuple_Check(args)); |
| 844 retval = PyObject_Call(func, args, NULL); | |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
845 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
846 Py_DECREF(args); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
847 Py_DECREF(func); |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
848 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
849 return retval; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
850 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
851 |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
852 static int |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
853 fill_classic_mro(PyObject *mro, PyObject *cls) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
854 { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
855 PyObject *bases, *base; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
856 int i, n; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
857 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
858 assert(PyList_Check(mro)); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
859 assert(PyClass_Check(cls)); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
860 i = PySequence_Contains(mro, cls); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
861 if (i < 0) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
862 return -1; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
863 if (!i) { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
864 if (PyList_Append(mro, cls) < 0) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
865 return -1; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
866 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
867 bases = ((PyClassObject *)cls)->cl_bases; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
868 assert(bases && PyTuple_Check(bases)); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
869 n = PyTuple_GET_SIZE(bases); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
870 for (i = 0; i < n; i++) { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
871 base = PyTuple_GET_ITEM(bases, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
872 if (fill_classic_mro(mro, base) < 0) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
873 return -1; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
874 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
875 return 0; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
876 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
877 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
878 static PyObject * |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
879 classic_mro(PyObject *cls) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
880 { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
881 PyObject *mro; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
882 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
883 assert(PyClass_Check(cls)); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
884 mro = PyList_New(0); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
885 if (mro != NULL) { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
886 if (fill_classic_mro(mro, cls) == 0) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
887 return mro; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
888 Py_DECREF(mro); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
889 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
890 return NULL; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
891 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
892 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
893 /* |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
894 Method resolution order algorithm C3 described in |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
895 "A Monotonic Superclass Linearization for Dylan", |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
896 by Kim Barrett, Bob Cassel, Paul Haahr, |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
897 David A. Moon, Keith Playford, and P. Tucker Withington. |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
898 (OOPSLA 1996) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
899 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
900 Some notes about the rules implied by C3: |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
901 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
902 No duplicate bases. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
903 It isn't legal to repeat a class in a list of base classes. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
904 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
905 The next three properties are the 3 constraints in "C3". |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
906 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
907 Local precendece order. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
908 If A precedes B in C's MRO, then A will precede B in the MRO of all |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
909 subclasses of C. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
910 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
911 Monotonicity. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
912 The MRO of a class must be an extension without reordering of the |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
913 MRO of each of its superclasses. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
914 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
915 Extended Precedence Graph (EPG). |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
916 Linearization is consistent if there is a path in the EPG from |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
917 each class to all its successors in the linearization. See |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
918 the paper for definition of EPG. |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
919 */ |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
920 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
921 static int |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
922 tail_contains(PyObject *list, int whence, PyObject *o) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
923 int j, size; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
924 size = PyList_GET_SIZE(list); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
925 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
926 for (j = whence+1; j < size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
927 if (PyList_GET_ITEM(list, j) == o) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
928 return 1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
929 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
930 return 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
931 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
932 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
933 static PyObject * |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
934 class_name(PyObject *cls) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
935 { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
936 PyObject *name = PyObject_GetAttrString(cls, "__name__"); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
937 if (name == NULL) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
938 PyErr_Clear(); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
939 Py_XDECREF(name); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
940 name = PyObject_Repr(cls); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
941 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
942 if (name == NULL) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
943 return NULL; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
944 if (!PyString_Check(name)) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
945 Py_DECREF(name); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
946 return NULL; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
947 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
948 return name; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
949 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
950 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
951 static int |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
952 check_duplicates(PyObject *list) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
953 { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
954 int i, j, n; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
955 /* Let's use a quadratic time algorithm, |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
956 assuming that the bases lists is short. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
957 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
958 n = PyList_GET_SIZE(list); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
959 for (i = 0; i < n; i++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
960 PyObject *o = PyList_GET_ITEM(list, i); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
961 for (j = i + 1; j < n; j++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
962 if (PyList_GET_ITEM(list, j) == o) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
963 o = class_name(o); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
964 PyErr_Format(PyExc_TypeError, |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
965 "duplicate base class %s", |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
966 o ? PyString_AS_STRING(o) : "?"); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
967 Py_XDECREF(o); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
968 return -1; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
969 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
970 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
971 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
972 return 0; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
973 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
974 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
975 /* Raise a TypeError for an MRO order disagreement. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
976 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
977 It's hard to produce a good error message. In the absence of better |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
978 insight into error reporting, report the classes that were candidates |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
979 to be put next into the MRO. There is some conflict between the |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
980 order in which they should be put in the MRO, but it's hard to |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
981 diagnose what constraint can't be satisfied. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
982 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
983 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
984 static void |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
985 set_mro_error(PyObject *to_merge, int *remain) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
986 { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
987 int i, n, off, to_merge_size; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
988 char buf[1000]; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
989 PyObject *k, *v; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
990 PyObject *set = PyDict_New(); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
991 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
992 to_merge_size = PyList_GET_SIZE(to_merge); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
993 for (i = 0; i < to_merge_size; i++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
994 PyObject *L = PyList_GET_ITEM(to_merge, i); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
995 if (remain[i] < PyList_GET_SIZE(L)) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
996 PyObject *c = PyList_GET_ITEM(L, remain[i]); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
997 if (PyDict_SetItem(set, c, Py_None) < 0) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
998 return; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
999 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1000 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1001 n = PyDict_Size(set); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1002 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1003 off = PyOS_snprintf(buf, sizeof(buf), "MRO conflict among bases"); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1004 i = 0; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1005 while (PyDict_Next(set, &i, &k, &v) && off < sizeof(buf)) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1006 PyObject *name = class_name(k); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1007 off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1008 name ? PyString_AS_STRING(name) : "?"); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1009 Py_XDECREF(name); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1010 if (--n && off+1 < sizeof(buf)) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1011 buf[off++] = ','; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1012 buf[off] = '\0'; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1013 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1014 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1015 PyErr_SetString(PyExc_TypeError, buf); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1016 Py_DECREF(set); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1017 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1018 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1019 static int |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1020 pmerge(PyObject *acc, PyObject* to_merge) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1021 int i, j, to_merge_size; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1022 int *remain; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1023 int ok, empty_cnt; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1024 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1025 to_merge_size = PyList_GET_SIZE(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1026 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1027 /* remain stores an index into each sublist of to_merge. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1028 remain[i] is the index of the next base in to_merge[i] |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1029 that is not included in acc. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1030 */ |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1031 remain = PyMem_MALLOC(SIZEOF_INT*to_merge_size); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1032 if (remain == NULL) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1033 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1034 for (i = 0; i < to_merge_size; i++) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1035 remain[i] = 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1036 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1037 again: |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1038 empty_cnt = 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1039 for (i = 0; i < to_merge_size; i++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1040 PyObject *candidate; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1041 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1042 PyObject *cur_list = PyList_GET_ITEM(to_merge, i); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1043 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1044 if (remain[i] >= PyList_GET_SIZE(cur_list)) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1045 empty_cnt++; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1046 continue; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1047 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1048 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1049 /* Choose next candidate for MRO. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1050 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1051 The input sequences alone can determine the choice. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1052 If not, choose the class which appears in the MRO |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1053 of the earliest direct superclass of the new class. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1054 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1055 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1056 candidate = PyList_GET_ITEM(cur_list, remain[i]); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1057 for (j = 0; j < to_merge_size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1058 PyObject *j_lst = PyList_GET_ITEM(to_merge, j); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1059 if (tail_contains(j_lst, remain[j], candidate)) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1060 goto skip; /* continue outer loop */ |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1061 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1062 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1063 ok = PyList_Append(acc, candidate); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1064 if (ok < 0) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1065 PyMem_Free(remain); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1066 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1067 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1068 for (j = 0; j < to_merge_size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1069 PyObject *j_lst = PyList_GET_ITEM(to_merge, j); |
|
26964
5df7a284eaf4
Fix an out-of-bound index in pmerge() discovered by Zooko (SF bug
Guido van Rossum <guido@python.org>
parents:
26660
diff
changeset
|
1070 if (remain[j] < PyList_GET_SIZE(j_lst) && |
|
5df7a284eaf4
Fix an out-of-bound index in pmerge() discovered by Zooko (SF bug
Guido van Rossum <guido@python.org>
parents:
26660
diff
changeset
|
1071 PyList_GET_ITEM(j_lst, remain[j]) == candidate) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1072 remain[j]++; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1073 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1074 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1075 goto again; |
|
26227
529719a5350e
Repaired illegal syntax most compilers probably let slide (but MSVC
Tim Peters <tim.peters@gmail.com>
parents:
26222
diff
changeset
|
1076 skip: ; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1077 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1078 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1079 if (empty_cnt == to_merge_size) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1080 PyMem_FREE(remain); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1081 return 0; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1082 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1083 set_mro_error(to_merge, remain); |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1084 PyMem_FREE(remain); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1085 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1086 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1087 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1088 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1089 mro_implementation(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1090 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1091 int i, n, ok; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1092 PyObject *bases, *result; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1093 PyObject *to_merge, *bases_aslist; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1094 |
|
23903
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1095 if(type->tp_dict == NULL) { |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1096 if(PyType_Ready(type) < 0) |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1097 return NULL; |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1098 } |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1099 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1100 /* Find a superclass linearization that honors the constraints |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1101 of the explicit lists of bases and the constraints implied by |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1102 each base class. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1103 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1104 to_merge is a list of lists, where each list is a superclass |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1105 linearization implied by a base class. The last element of |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1106 to_merge is the declared list of bases. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1107 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1108 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1109 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1110 n = PyTuple_GET_SIZE(bases); |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1111 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1112 to_merge = PyList_New(n+1); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1113 if (to_merge == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1114 return NULL; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1115 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1116 for (i = 0; i < n; i++) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1117 PyObject *base = PyTuple_GET_ITEM(bases, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1118 PyObject *parentMRO; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1119 if (PyType_Check(base)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1120 parentMRO = PySequence_List( |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1121 ((PyTypeObject*)base)->tp_mro); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1122 else |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1123 parentMRO = classic_mro(base); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1124 if (parentMRO == NULL) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1125 Py_DECREF(to_merge); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1126 return NULL; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1127 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1128 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1129 PyList_SET_ITEM(to_merge, i, parentMRO); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1130 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1131 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1132 bases_aslist = PySequence_List(bases); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1133 if (bases_aslist == NULL) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1134 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1135 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1136 } |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1137 /* This is just a basic sanity check. */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1138 if (check_duplicates(bases_aslist) < 0) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1139 Py_DECREF(to_merge); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1140 Py_DECREF(bases_aslist); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1141 return NULL; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1142 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1143 PyList_SET_ITEM(to_merge, n, bases_aslist); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1144 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1145 result = Py_BuildValue("[O]", (PyObject *)type); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1146 if (result == NULL) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1147 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1148 return NULL; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1149 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1150 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1151 ok = pmerge(result, to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1152 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1153 if (ok < 0) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1154 Py_DECREF(result); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1155 return NULL; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1156 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1157 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1158 return result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1159 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1160 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1161 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19300
diff
changeset
|
1162 mro_external(PyObject *self) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1163 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1164 PyTypeObject *type = (PyTypeObject *)self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1165 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1166 return mro_implementation(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1167 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1168 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1169 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1170 mro_internal(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1171 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1172 PyObject *mro, *result, *tuple; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1173 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1174 if (type->ob_type == &PyType_Type) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1175 result = mro_implementation(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1176 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1177 else { |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
1178 static PyObject *mro_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
1179 mro = lookup_method((PyObject *)type, "mro", &mro_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1180 if (mro == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1181 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1182 result = PyObject_CallObject(mro, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1183 Py_DECREF(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1184 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1185 if (result == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1186 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1187 tuple = PySequence_Tuple(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1188 Py_DECREF(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1189 type->tp_mro = tuple; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1190 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1191 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1192 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1193 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1194 /* Calculate the best base amongst multiple base classes. |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1195 This is the first one that's on the path to the "solid base". */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1196 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1197 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1198 best_base(PyObject *bases) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1199 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1200 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1201 PyTypeObject *base, *winner, *candidate, *base_i; |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1202 PyObject *base_proto; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1203 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1204 assert(PyTuple_Check(bases)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1205 n = PyTuple_GET_SIZE(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1206 assert(n > 0); |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1207 base = NULL; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1208 winner = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1209 for (i = 0; i < n; i++) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1210 base_proto = PyTuple_GET_ITEM(bases, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1211 if (PyClass_Check(base_proto)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1212 continue; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1213 if (!PyType_Check(base_proto)) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1214 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1215 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1216 "bases must be types"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1217 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1218 } |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1219 base_i = (PyTypeObject *)base_proto; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1220 if (base_i->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1221 if (PyType_Ready(base_i) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1222 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1223 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1224 candidate = solid_base(base_i); |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1225 if (winner == NULL) { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1226 winner = candidate; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1227 base = base_i; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1228 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1229 else if (PyType_IsSubtype(winner, candidate)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1230 ; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1231 else if (PyType_IsSubtype(candidate, winner)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1232 winner = candidate; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1233 base = base_i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1234 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1235 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1236 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1237 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1238 "multiple bases have " |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1239 "instance lay-out conflict"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1240 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1241 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1242 } |
| 21404 | 1243 if (base == NULL) |
| 1244 PyErr_SetString(PyExc_TypeError, | |
| 1245 "a new-style class can't have only classic bases"); | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1246 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1247 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1248 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1249 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1250 extra_ivars(PyTypeObject *type, PyTypeObject *base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1251 { |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1252 size_t t_size = type->tp_basicsize; |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1253 size_t b_size = base->tp_basicsize; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1254 |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1255 assert(t_size >= b_size); /* Else type smaller than base! */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1256 if (type->tp_itemsize || base->tp_itemsize) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1257 /* If itemsize is involved, stricter rules */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1258 return t_size != b_size || |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1259 type->tp_itemsize != base->tp_itemsize; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1260 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1261 if (type->tp_weaklistoffset && base->tp_weaklistoffset == 0 && |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1262 type->tp_weaklistoffset + sizeof(PyObject *) == t_size) |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1263 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1264 if (type->tp_dictoffset && base->tp_dictoffset == 0 && |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1265 type->tp_dictoffset + sizeof(PyObject *) == t_size) |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1266 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1267 |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1268 return t_size != b_size; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1269 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1270 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1271 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1272 solid_base(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1273 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1274 PyTypeObject *base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1275 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1276 if (type->tp_base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1277 base = solid_base(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1278 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1279 base = &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1280 if (extra_ivars(type, base)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1281 return type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1282 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1283 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1284 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1285 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1286 static void object_dealloc(PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1287 static int object_init(PyObject *, PyObject *, PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1288 static int update_slot(PyTypeObject *, PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1289 static void fixup_slot_dispatchers(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1290 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1291 static PyObject * |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1292 subtype_dict(PyObject *obj, void *context) |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1293 { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1294 PyObject **dictptr = _PyObject_GetDictPtr(obj); |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1295 PyObject *dict; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1296 |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1297 if (dictptr == NULL) { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1298 PyErr_SetString(PyExc_AttributeError, |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1299 "This object has no __dict__"); |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1300 return NULL; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1301 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1302 dict = *dictptr; |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1303 if (dict == NULL) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1304 *dictptr = dict = PyDict_New(); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1305 Py_XINCREF(dict); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1306 return dict; |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1307 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1308 |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1309 static int |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1310 subtype_setdict(PyObject *obj, PyObject *value, void *context) |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1311 { |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1312 PyObject **dictptr = _PyObject_GetDictPtr(obj); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1313 PyObject *dict; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1314 |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1315 if (dictptr == NULL) { |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1316 PyErr_SetString(PyExc_AttributeError, |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1317 "This object has no __dict__"); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1318 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1319 } |
|
21235
b782490da7f0
At the PythonLabs meeting someone mentioned it would make Jim really
Guido van Rossum <guido@python.org>
parents:
21192
diff
changeset
|
1320 if (value != NULL && !PyDict_Check(value)) { |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1321 PyErr_SetString(PyExc_TypeError, |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1322 "__dict__ must be set to a dictionary"); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1323 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1324 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1325 dict = *dictptr; |
|
21235
b782490da7f0
At the PythonLabs meeting someone mentioned it would make Jim really
Guido van Rossum <guido@python.org>
parents:
21192
diff
changeset
|
1326 Py_XINCREF(value); |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1327 *dictptr = value; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1328 Py_XDECREF(dict); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1329 return 0; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1330 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1331 |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1332 static PyObject * |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1333 subtype_getweakref(PyObject *obj, void *context) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1334 { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1335 PyObject **weaklistptr; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1336 PyObject *result; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1337 |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1338 if (obj->ob_type->tp_weaklistoffset == 0) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1339 PyErr_SetString(PyExc_AttributeError, |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1340 "This object has no __weaklist__"); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1341 return NULL; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1342 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1343 assert(obj->ob_type->tp_weaklistoffset > 0); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1344 assert(obj->ob_type->tp_weaklistoffset + sizeof(PyObject *) <= |
| 24762 | 1345 (size_t)(obj->ob_type->tp_basicsize)); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1346 weaklistptr = (PyObject **) |
| 24762 | 1347 ((char *)obj + obj->ob_type->tp_weaklistoffset); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1348 if (*weaklistptr == NULL) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1349 result = Py_None; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1350 else |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1351 result = *weaklistptr; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1352 Py_INCREF(result); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1353 return result; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1354 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1355 |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1356 /* Three variants on the subtype_getsets list. */ |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1357 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1358 static PyGetSetDef subtype_getsets_full[] = { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1359 {"__dict__", subtype_dict, subtype_setdict, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
1360 PyDoc_STR("dictionary for instance variables (if defined)")}, |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1361 {"__weakref__", subtype_getweakref, NULL, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
1362 PyDoc_STR("list of weak references to the object (if defined)")}, |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1363 {0} |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1364 }; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1365 |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1366 static PyGetSetDef subtype_getsets_dict_only[] = { |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1367 {"__dict__", subtype_dict, subtype_setdict, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1368 PyDoc_STR("dictionary for instance variables (if defined)")}, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1369 {0} |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1370 }; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1371 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1372 static PyGetSetDef subtype_getsets_weakref_only[] = { |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1373 {"__weakref__", subtype_getweakref, NULL, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1374 PyDoc_STR("list of weak references to the object (if defined)")}, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1375 {0} |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1376 }; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1377 |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1378 /* bozo: __getstate__ that raises TypeError */ |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1379 |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1380 static PyObject * |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1381 bozo_func(PyObject *self, PyObject *args) |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1382 { |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1383 PyErr_SetString(PyExc_TypeError, |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1384 "a class that defines __slots__ without " |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1385 "defining __getstate__ cannot be pickled"); |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1386 return NULL; |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1387 } |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1388 |
|
22713
cc8b73040e83
Use METH_VARARGS rather than METH_OLDARGS implicitly (args are ignored)
Neal Norwitz <nnorwitz@gmail.com>
parents:
22613
diff
changeset
|
1389 static PyMethodDef bozo_ml = {"__getstate__", bozo_func, METH_VARARGS}; |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1390 |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1391 static PyObject *bozo_obj = NULL; |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1392 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1393 static int |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1394 valid_identifier(PyObject *s) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1395 { |
|
24245
50443127b21d
valid_identifier(): use an unsigned char* so that isalpha() will do
Guido van Rossum <guido@python.org>
parents:
24184
diff
changeset
|
1396 unsigned char *p; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1397 int i, n; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1398 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1399 if (!PyString_Check(s)) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1400 PyErr_SetString(PyExc_TypeError, |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1401 "__slots__ must be strings"); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1402 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1403 } |
|
24245
50443127b21d
valid_identifier(): use an unsigned char* so that isalpha() will do
Guido van Rossum <guido@python.org>
parents:
24184
diff
changeset
|
1404 p = (unsigned char *) PyString_AS_STRING(s); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1405 n = PyString_GET_SIZE(s); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1406 /* We must reject an empty name. As a hack, we bump the |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1407 length to 1 so that the loop will balk on the trailing \0. */ |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1408 if (n == 0) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1409 n = 1; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1410 for (i = 0; i < n; i++, p++) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1411 if (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_') { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1412 PyErr_SetString(PyExc_TypeError, |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1413 "__slots__ must be identifiers"); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1414 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1415 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1416 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1417 return 1; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1418 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1419 |
|
25792
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1420 #ifdef Py_USING_UNICODE |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1421 /* Replace Unicode objects in slots. */ |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1422 |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1423 static PyObject * |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1424 _unicode_to_string(PyObject *slots, int nslots) |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1425 { |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1426 PyObject *tmp = slots; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1427 PyObject *o, *o1; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1428 int i; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1429 intintargfunc copy = slots->ob_type->tp_as_sequence->sq_slice; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1430 for (i = 0; i < nslots; i++) { |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1431 if (PyUnicode_Check(o = PyTuple_GET_ITEM(tmp, i))) { |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1432 if (tmp == slots) { |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1433 tmp = copy(slots, 0, PyTuple_GET_SIZE(slots)); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1434 if (tmp == NULL) |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1435 return NULL; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1436 } |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1437 o1 = _PyUnicode_AsDefaultEncodedString |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1438 (o, NULL); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1439 if (o1 == NULL) { |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1440 Py_DECREF(tmp); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1441 return 0; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1442 } |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1443 Py_INCREF(o1); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1444 Py_DECREF(o); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1445 PyTuple_SET_ITEM(tmp, i, o1); |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1446 } |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1447 } |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1448 return tmp; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1449 } |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1450 #endif |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1451 |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1452 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1453 type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1454 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1455 PyObject *name, *bases, *dict; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1456 static char *kwlist[] = {"name", "bases", "dict", 0}; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1457 PyObject *slots, *tmp, *newslots; |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1458 PyTypeObject *type, *base, *tmptype, *winner; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1459 etype *et; |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
1460 PyMemberDef *mp; |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1461 int i, nbases, nslots, slotoffset, add_dict, add_weak; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1462 int j, may_add_dict, may_add_weak; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1463 |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1464 assert(args != NULL && PyTuple_Check(args)); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1465 assert(kwds == NULL || PyDict_Check(kwds)); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1466 |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1467 /* Special case: type(x) should return x->ob_type */ |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1468 { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1469 const int nargs = PyTuple_GET_SIZE(args); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1470 const int nkwds = kwds == NULL ? 0 : PyDict_Size(kwds); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1471 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1472 if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1473 PyObject *x = PyTuple_GET_ITEM(args, 0); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1474 Py_INCREF(x->ob_type); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1475 return (PyObject *) x->ob_type; |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1476 } |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1477 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1478 /* SF bug 475327 -- if that didn't trigger, we need 3 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1479 arguments. but PyArg_ParseTupleAndKeywords below may give |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1480 a msg saying type() needs exactly 3. */ |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1481 if (nargs + nkwds != 3) { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1482 PyErr_SetString(PyExc_TypeError, |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1483 "type() takes 1 or 3 arguments"); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1484 return NULL; |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1485 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1486 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1487 |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1488 /* Check arguments: (name, bases, dict) */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1489 if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:type", kwlist, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1490 &name, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1491 &PyTuple_Type, &bases, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1492 &PyDict_Type, &dict)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1493 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1494 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1495 /* Determine the proper metatype to deal with this, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1496 and check for metatype conflicts while we're at it. |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1497 Note that if some other metatype wins to contract, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1498 it's possible that its instances are not types. */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1499 nbases = PyTuple_GET_SIZE(bases); |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1500 winner = metatype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1501 for (i = 0; i < nbases; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1502 tmp = PyTuple_GET_ITEM(bases, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1503 tmptype = tmp->ob_type; |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1504 if (tmptype == &PyClass_Type) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1505 continue; /* Special case classic classes */ |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1506 if (PyType_IsSubtype(winner, tmptype)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1507 continue; |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1508 if (PyType_IsSubtype(tmptype, winner)) { |
|
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1509 winner = tmptype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1510 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1511 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1512 PyErr_SetString(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1513 "metatype conflict among bases"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1514 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1515 } |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1516 if (winner != metatype) { |
|
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1517 if (winner->tp_new != type_new) /* Pass it to the winner */ |
|
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1518 return winner->tp_new(winner, args, kwds); |
|
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1519 metatype = winner; |
|
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1520 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1521 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1522 /* Adjust for empty tuple bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1523 if (nbases == 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1524 bases = Py_BuildValue("(O)", &PyBaseObject_Type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1525 if (bases == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1526 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1527 nbases = 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1528 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1529 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1530 Py_INCREF(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1531 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1532 /* XXX From here until type is allocated, "return NULL" leaks bases! */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1533 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1534 /* Calculate best base, and check that all bases are type objects */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1535 base = best_base(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1536 if (base == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1537 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1538 if (!PyType_HasFeature(base, Py_TPFLAGS_BASETYPE)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1539 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1540 "type '%.100s' is not an acceptable base type", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1541 base->tp_name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1542 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1543 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1544 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1545 /* Check for a __slots__ sequence variable in dict, and count it */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1546 slots = PyDict_GetItemString(dict, "__slots__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1547 nslots = 0; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1548 add_dict = 0; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1549 add_weak = 0; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1550 may_add_dict = base->tp_dictoffset == 0; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1551 may_add_weak = base->tp_weaklistoffset == 0 && base->tp_itemsize == 0; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1552 if (slots == NULL) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1553 if (may_add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1554 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1555 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1556 if (may_add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1557 add_weak++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1558 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1559 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1560 else { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1561 /* Have slots */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1562 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1563 /* Make it into a tuple */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1564 if (PyString_Check(slots)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1565 slots = Py_BuildValue("(O)", slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1566 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1567 slots = PySequence_Tuple(slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1568 if (slots == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1569 return NULL; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1570 assert(PyTuple_Check(slots)); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1571 |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1572 /* Are slots allowed? */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1573 nslots = PyTuple_GET_SIZE(slots); |
|
19595
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1574 if (nslots > 0 && base->tp_itemsize != 0) { |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1575 PyErr_Format(PyExc_TypeError, |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1576 "nonempty __slots__ " |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1577 "not supported for subtype of '%s'", |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1578 base->tp_name); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1579 bad_slots: |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1580 Py_DECREF(slots); |
|
19595
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1581 return NULL; |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
1582 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1583 |
|
25792
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1584 #ifdef Py_USING_UNICODE |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1585 tmp = _unicode_to_string(slots, nslots); |
|
25793
b858f4c883dd
Don't drop old slots if _unicode_to_string did not change anything.
Martin v. Löwis <martin@v.loewis.de>
parents:
25792
diff
changeset
|
1586 if (tmp != slots) { |
|
b858f4c883dd
Don't drop old slots if _unicode_to_string did not change anything.
Martin v. Löwis <martin@v.loewis.de>
parents:
25792
diff
changeset
|
1587 Py_DECREF(slots); |
|
b858f4c883dd
Don't drop old slots if _unicode_to_string did not change anything.
Martin v. Löwis <martin@v.loewis.de>
parents:
25792
diff
changeset
|
1588 slots = tmp; |
|
b858f4c883dd
Don't drop old slots if _unicode_to_string did not change anything.
Martin v. Löwis <martin@v.loewis.de>
parents:
25792
diff
changeset
|
1589 } |
|
25792
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1590 if (!tmp) |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1591 return NULL; |
|
a3d612f0563f
Allow Unicode strings in __slots__, converting them to byte strings.
Martin v. Löwis <martin@v.loewis.de>
parents:
24867
diff
changeset
|
1592 #endif |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1593 /* Check for valid slot names and two special cases */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1594 for (i = 0; i < nslots; i++) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1595 PyObject *tmp = PyTuple_GET_ITEM(slots, i); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1596 char *s; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1597 if (!valid_identifier(tmp)) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1598 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1599 assert(PyString_Check(tmp)); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1600 s = PyString_AS_STRING(tmp); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1601 if (strcmp(s, "__dict__") == 0) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1602 if (!may_add_dict || add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1603 PyErr_SetString(PyExc_TypeError, |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1604 "__dict__ slot disallowed: " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1605 "we already got one"); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1606 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1607 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1608 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1609 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1610 if (strcmp(s, "__weakref__") == 0) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1611 if (!may_add_weak || add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1612 PyErr_SetString(PyExc_TypeError, |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1613 "__weakref__ slot disallowed: " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1614 "either we already got one, " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1615 "or __itemsize__ != 0"); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1616 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1617 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1618 add_weak++; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1619 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1620 } |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1621 |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1622 /* Copy slots into yet another tuple, demangling names */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1623 newslots = PyTuple_New(nslots - add_dict - add_weak); |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1624 if (newslots == NULL) |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1625 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1626 for (i = j = 0; i < nslots; i++) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1627 char *s; |
|
24862
5b656c3e132b
Fix SF bug 595838 -- buffer in type_new() should not be static. Moved
Guido van Rossum <guido@python.org>
parents:
24825
diff
changeset
|
1628 char buffer[256]; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1629 tmp = PyTuple_GET_ITEM(slots, i); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1630 s = PyString_AS_STRING(tmp); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1631 if ((add_dict && strcmp(s, "__dict__") == 0) || |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1632 (add_weak && strcmp(s, "__weakref__") == 0)) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1633 continue; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1634 if (_Py_Mangle(PyString_AS_STRING(name), |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1635 PyString_AS_STRING(tmp), |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1636 buffer, sizeof(buffer))) |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1637 { |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1638 tmp = PyString_FromString(buffer); |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1639 } else { |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1640 Py_INCREF(tmp); |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1641 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1642 PyTuple_SET_ITEM(newslots, j, tmp); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1643 j++; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1644 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1645 assert(j == nslots - add_dict - add_weak); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1646 nslots = j; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1647 Py_DECREF(slots); |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1648 slots = newslots; |
|
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1649 |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1650 /* See if *this* class defines __getstate__ */ |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1651 if (PyDict_GetItemString(dict, "__getstate__") == NULL) { |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1652 /* If not, provide a bozo that raises TypeError */ |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1653 if (bozo_obj == NULL) { |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1654 bozo_obj = PyCFunction_New(&bozo_ml, NULL); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1655 if (bozo_obj == NULL) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1656 goto bad_slots; |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1657 } |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1658 if (PyDict_SetItemString(dict, |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1659 "__getstate__", |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1660 bozo_obj) < 0) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1661 { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1662 Py_DECREF(bozo_obj); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1663 goto bad_slots; |
|
22331
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1664 } |
|
f2eb95fb4529
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22230
diff
changeset
|
1665 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1666 |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1667 /* Secondary bases may provide weakrefs or dict */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1668 if (nbases > 1 && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1669 ((may_add_dict && !add_dict) || |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1670 (may_add_weak && !add_weak))) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1671 for (i = 0; i < nbases; i++) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1672 tmp = PyTuple_GET_ITEM(bases, i); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1673 if (tmp == (PyObject *)base) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1674 continue; /* Skip primary base */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1675 if (PyClass_Check(tmp)) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1676 /* Classic base class provides both */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1677 if (may_add_dict && !add_dict) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1678 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1679 if (may_add_weak && !add_weak) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1680 add_weak++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1681 break; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1682 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1683 assert(PyType_Check(tmp)); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1684 tmptype = (PyTypeObject *)tmp; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1685 if (may_add_dict && !add_dict && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1686 tmptype->tp_dictoffset != 0) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1687 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1688 if (may_add_weak && !add_weak && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1689 tmptype->tp_weaklistoffset != 0) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1690 add_weak++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1691 if (may_add_dict && !add_dict) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1692 continue; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1693 if (may_add_weak && !add_weak) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1694 continue; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1695 /* Nothing more to check */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1696 break; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1697 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1698 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1699 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1700 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1701 /* XXX From here until type is safely allocated, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1702 "return NULL" may leak slots! */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1703 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1704 /* Allocate the type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1705 type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1706 if (type == NULL) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1707 Py_XDECREF(slots); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1708 return NULL; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1709 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1710 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1711 /* Keep name and slots alive in the extended type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1712 et = (etype *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1713 Py_INCREF(name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1714 et->name = name; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1715 et->slots = slots; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1716 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1717 /* Initialize tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1718 type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1719 Py_TPFLAGS_BASETYPE; |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1720 if (base->tp_flags & Py_TPFLAGS_HAVE_GC) |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1721 type->tp_flags |= Py_TPFLAGS_HAVE_GC; |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1722 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1723 /* It's a new-style number unless it specifically inherits any |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1724 old-style numeric behavior */ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1725 if ((base->tp_flags & Py_TPFLAGS_CHECKTYPES) || |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1726 (base->tp_as_number == NULL)) |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1727 type->tp_flags |= Py_TPFLAGS_CHECKTYPES; |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1728 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1729 /* Initialize essential fields */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1730 type->tp_as_number = &et->as_number; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1731 type->tp_as_sequence = &et->as_sequence; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1732 type->tp_as_mapping = &et->as_mapping; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1733 type->tp_as_buffer = &et->as_buffer; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1734 type->tp_name = PyString_AS_STRING(name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1735 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1736 /* Set tp_base and tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1737 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1738 Py_INCREF(base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1739 type->tp_base = base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1740 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1741 /* Initialize tp_dict from passed-in dict */ |
|
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1742 type->tp_dict = dict = PyDict_Copy(dict); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1743 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1744 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1745 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1746 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1747 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1748 /* Set __module__ in the dict */ |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1749 if (PyDict_GetItemString(dict, "__module__") == NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1750 tmp = PyEval_GetGlobals(); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1751 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1752 tmp = PyDict_GetItemString(tmp, "__name__"); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1753 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1754 if (PyDict_SetItemString(dict, "__module__", |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1755 tmp) < 0) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1756 return NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1757 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1758 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1759 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1760 |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1761 /* Set tp_doc to a copy of dict['__doc__'], if the latter is there |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
1762 and is a string. The __doc__ accessor will first look for tp_doc; |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
1763 if that fails, it will still look into __dict__. |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1764 */ |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1765 { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1766 PyObject *doc = PyDict_GetItemString(dict, "__doc__"); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1767 if (doc != NULL && PyString_Check(doc)) { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1768 const size_t n = (size_t)PyString_GET_SIZE(doc); |
|
20241
aff6fcd26c15
type_new(): cast PyObject_MALLOC's result to char*, for clarity.
Tim Peters <tim.peters@gmail.com>
parents:
20239
diff
changeset
|
1769 type->tp_doc = (char *)PyObject_MALLOC(n+1); |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1770 if (type->tp_doc == NULL) { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1771 Py_DECREF(type); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1772 return NULL; |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1773 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1774 memcpy(type->tp_doc, PyString_AS_STRING(doc), n+1); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1775 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1776 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1777 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1778 /* Special-case __new__: if it's a plain function, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1779 make it a static function */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1780 tmp = PyDict_GetItemString(dict, "__new__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1781 if (tmp != NULL && PyFunction_Check(tmp)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1782 tmp = PyStaticMethod_New(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1783 if (tmp == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1784 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1785 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1786 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1787 PyDict_SetItemString(dict, "__new__", tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1788 Py_DECREF(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1789 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1790 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1791 /* Add descriptors for custom slots from __slots__, or for __dict__ */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1792 mp = et->members; |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1793 slotoffset = base->tp_basicsize; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1794 if (slots != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1795 for (i = 0; i < nslots; i++, mp++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1796 mp->name = PyString_AS_STRING( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1797 PyTuple_GET_ITEM(slots, i)); |
|
21192
c18ad52dece3
Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents:
21151
diff
changeset
|
1798 mp->type = T_OBJECT_EX; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1799 mp->offset = slotoffset; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1800 if (base->tp_weaklistoffset == 0 && |
|
21192
c18ad52dece3
Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents:
21151
diff
changeset
|
1801 strcmp(mp->name, "__weakref__") == 0) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1802 add_weak++; |
|
21192
c18ad52dece3
Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents:
21151
diff
changeset
|
1803 mp->type = T_OBJECT; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1804 mp->flags = READONLY; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1805 type->tp_weaklistoffset = slotoffset; |
|
21192
c18ad52dece3
Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents:
21151
diff
changeset
|
1806 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1807 slotoffset += sizeof(PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1808 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1809 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1810 if (add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1811 if (base->tp_itemsize) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1812 type->tp_dictoffset = -(long)sizeof(PyObject *); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1813 else |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1814 type->tp_dictoffset = slotoffset; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1815 slotoffset += sizeof(PyObject *); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1816 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1817 if (add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1818 assert(!base->tp_itemsize); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1819 type->tp_weaklistoffset = slotoffset; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1820 slotoffset += sizeof(PyObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1821 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1822 type->tp_basicsize = slotoffset; |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1823 type->tp_itemsize = base->tp_itemsize; |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1824 type->tp_members = et->members; |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1825 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1826 if (type->tp_weaklistoffset && type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1827 type->tp_getset = subtype_getsets_full; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1828 else if (type->tp_weaklistoffset && !type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1829 type->tp_getset = subtype_getsets_weakref_only; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1830 else if (!type->tp_weaklistoffset && type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1831 type->tp_getset = subtype_getsets_dict_only; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1832 else |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1833 type->tp_getset = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1834 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1835 /* Special case some slots */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1836 if (type->tp_dictoffset != 0 || nslots > 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1837 if (base->tp_getattr == NULL && base->tp_getattro == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1838 type->tp_getattro = PyObject_GenericGetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1839 if (base->tp_setattr == NULL && base->tp_setattro == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1840 type->tp_setattro = PyObject_GenericSetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1841 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1842 type->tp_dealloc = subtype_dealloc; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1843 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1844 /* Enable GC unless there are really no instance variables possible */ |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1845 if (!(type->tp_basicsize == sizeof(PyObject) && |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1846 type->tp_itemsize == 0)) |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1847 type->tp_flags |= Py_TPFLAGS_HAVE_GC; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1848 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1849 /* Always override allocation strategy to use regular heap */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1850 type->tp_alloc = PyType_GenericAlloc; |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1851 if (type->tp_flags & Py_TPFLAGS_HAVE_GC) { |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
1852 type->tp_free = PyObject_GC_Del; |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1853 type->tp_traverse = subtype_traverse; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1854 type->tp_clear = subtype_clear; |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1855 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1856 else |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
1857 type->tp_free = PyObject_Del; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1858 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1859 /* Initialize the rest */ |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1860 if (PyType_Ready(type) < 0) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1861 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1862 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1863 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1864 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
1865 /* Put the proper slots in place */ |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
1866 fixup_slot_dispatchers(type); |
| 19036 | 1867 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1868 return (PyObject *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1869 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1870 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1871 /* Internal API to look for a name through the MRO. |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1872 This returns a borrowed reference, and doesn't set an exception! */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1873 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1874 _PyType_Lookup(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1875 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1876 int i, n; |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1877 PyObject *mro, *res, *base, *dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1878 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1879 /* Look in tp_dict of types in MRO */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1880 mro = type->tp_mro; |
|
23753
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1881 |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1882 /* If mro is NULL, the type is either not yet initialized |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1883 by PyType_Ready(), or already cleared by type_clear(). |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1884 Either way the safest thing to do is to return NULL. */ |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1885 if (mro == NULL) |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1886 return NULL; |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
1887 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1888 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1889 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1890 for (i = 0; i < n; i++) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1891 base = PyTuple_GET_ITEM(mro, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1892 if (PyClass_Check(base)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1893 dict = ((PyClassObject *)base)->cl_dict; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1894 else { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1895 assert(PyType_Check(base)); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1896 dict = ((PyTypeObject *)base)->tp_dict; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1897 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1898 assert(dict && PyDict_Check(dict)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1899 res = PyDict_GetItem(dict, name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1900 if (res != NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1901 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1902 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1903 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1904 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1905 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1906 /* This is similar to PyObject_GenericGetAttr(), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1907 but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1908 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1909 type_getattro(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1910 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1911 PyTypeObject *metatype = type->ob_type; |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1912 PyObject *meta_attribute, *attribute; |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1913 descrgetfunc meta_get; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1914 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1915 /* Initialize this type (we'll assume the metatype is initialized) */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1916 if (type->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1917 if (PyType_Ready(type) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1918 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1919 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1920 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1921 /* No readable descriptor found yet */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1922 meta_get = NULL; |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
1923 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1924 /* Look for the attribute in the metatype */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1925 meta_attribute = _PyType_Lookup(metatype, name); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1926 |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1927 if (meta_attribute != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1928 meta_get = meta_attribute->ob_type->tp_descr_get; |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
1929 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1930 if (meta_get != NULL && PyDescr_IsData(meta_attribute)) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1931 /* Data descriptors implement tp_descr_set to intercept |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1932 * writes. Assume the attribute is not overridden in |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1933 * type's tp_dict (and bases): call the descriptor now. |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1934 */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1935 return meta_get(meta_attribute, (PyObject *)type, |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1936 (PyObject *)metatype); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1937 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1938 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1939 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1940 /* No data descriptor found on metatype. Look in tp_dict of this |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1941 * type and its bases */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1942 attribute = _PyType_Lookup(type, name); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1943 if (attribute != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1944 /* Implement descriptor functionality, if any */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1945 descrgetfunc local_get = attribute->ob_type->tp_descr_get; |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1946 if (local_get != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1947 /* NULL 2nd argument indicates the descriptor was |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1948 * found on the target object itself (or a base) */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1949 return local_get(attribute, (PyObject *)NULL, |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1950 (PyObject *)type); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1951 } |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
1952 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1953 Py_INCREF(attribute); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1954 return attribute; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1955 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1956 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1957 /* No attribute found in local __dict__ (or bases): use the |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1958 * descriptor from the metatype, if any */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1959 if (meta_get != NULL) |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1960 return meta_get(meta_attribute, (PyObject *)type, |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1961 (PyObject *)metatype); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1962 |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1963 /* If an ordinary attribute was found on the metatype, return it now */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1964 if (meta_attribute != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1965 Py_INCREF(meta_attribute); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1966 return meta_attribute; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1967 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1968 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1969 /* Give up */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1970 PyErr_Format(PyExc_AttributeError, |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1971 "type object '%.50s' has no attribute '%.400s'", |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
1972 type->tp_name, PyString_AS_STRING(name)); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1973 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1974 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1975 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1976 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1977 type_setattro(PyTypeObject *type, PyObject *name, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1978 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1979 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1980 PyErr_Format( |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1981 PyExc_TypeError, |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1982 "can't set attributes of built-in/extension type '%s'", |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1983 type->tp_name); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1984 return -1; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
1985 } |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1986 if (PyObject_GenericSetAttr((PyObject *)type, name, value) < 0) |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1987 return -1; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1988 return update_slot(type, name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1989 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1990 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1991 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1992 type_dealloc(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1993 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1994 etype *et; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1995 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1996 /* Assert this is a heap-allocated type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1997 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1998 _PyObject_GC_UNTRACK(type); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1999 PyObject_ClearWeakRefs((PyObject *)type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2000 et = (etype *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2001 Py_XDECREF(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2002 Py_XDECREF(type->tp_dict); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2003 Py_XDECREF(type->tp_bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2004 Py_XDECREF(type->tp_mro); |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2005 Py_XDECREF(type->tp_cache); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2006 Py_XDECREF(type->tp_subclasses); |
|
24427
ea4821964043
SF patch #587889, fix memory leak of tp_doc
Neal Norwitz <nnorwitz@gmail.com>
parents:
24381
diff
changeset
|
2007 PyObject_Free(type->tp_doc); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2008 Py_XDECREF(et->name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2009 Py_XDECREF(et->slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2010 type->ob_type->tp_free((PyObject *)type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2011 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2012 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2013 static PyObject * |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2014 type_subclasses(PyTypeObject *type, PyObject *args_ignored) |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2015 { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2016 PyObject *list, *raw, *ref; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2017 int i, n; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2018 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2019 list = PyList_New(0); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2020 if (list == NULL) |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2021 return NULL; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2022 raw = type->tp_subclasses; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2023 if (raw == NULL) |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2024 return list; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2025 assert(PyList_Check(raw)); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2026 n = PyList_GET_SIZE(raw); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2027 for (i = 0; i < n; i++) { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2028 ref = PyList_GET_ITEM(raw, i); |
|
20320
f29b8ea0b695
type_subclasses(): debug build was broken due to typo in new assert().
Tim Peters <tim.peters@gmail.com>
parents:
20315
diff
changeset
|
2029 assert(PyWeakref_CheckRef(ref)); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2030 ref = PyWeakref_GET_OBJECT(ref); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2031 if (ref != Py_None) { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2032 if (PyList_Append(list, ref) < 0) { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2033 Py_DECREF(list); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2034 return NULL; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2035 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2036 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2037 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2038 return list; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2039 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2040 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2041 static PyMethodDef type_methods[] = { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19300
diff
changeset
|
2042 {"mro", (PyCFunction)mro_external, METH_NOARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2043 PyDoc_STR("mro() -> list\nreturn a type's method resolution order")}, |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2044 {"__subclasses__", (PyCFunction)type_subclasses, METH_NOARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2045 PyDoc_STR("__subclasses__() -> list of immediate subclasses")}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2046 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2047 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2048 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
2049 PyDoc_STRVAR(type_doc, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2050 "type(object) -> the object's type\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
2051 "type(name, bases, dict) -> a new type"); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2052 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2053 static int |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2054 type_traverse(PyTypeObject *type, visitproc visit, void *arg) |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2055 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2056 int err; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2057 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2058 /* Because of type_is_gc(), the collector only calls this |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2059 for heaptypes. */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2060 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2061 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2062 #define VISIT(SLOT) \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2063 if (SLOT) { \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2064 err = visit((PyObject *)(SLOT), arg); \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2065 if (err) \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2066 return err; \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2067 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2068 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2069 VISIT(type->tp_dict); |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2070 VISIT(type->tp_cache); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2071 VISIT(type->tp_mro); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2072 VISIT(type->tp_bases); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2073 VISIT(type->tp_base); |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2074 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2075 /* There's no need to visit type->tp_subclasses or |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2076 ((etype *)type)->slots, because they can't be involved |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2077 in cycles; tp_subclasses is a list of weak references, |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2078 and slots is a tuple of strings. */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2079 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2080 #undef VISIT |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2081 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2082 return 0; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2083 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2084 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2085 static int |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2086 type_clear(PyTypeObject *type) |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2087 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2088 PyObject *tmp; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2089 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2090 /* Because of type_is_gc(), the collector only calls this |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2091 for heaptypes. */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2092 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2093 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2094 #define CLEAR(SLOT) \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2095 if (SLOT) { \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2096 tmp = (PyObject *)(SLOT); \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2097 SLOT = NULL; \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2098 Py_DECREF(tmp); \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2099 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2100 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2101 /* The only field we need to clear is tp_mro, which is part of a |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2102 hard cycle (its first element is the class itself) that won't |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2103 be broken otherwise (it's a tuple and tuples don't have a |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2104 tp_clear handler). None of the other fields need to be |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2105 cleared, and here's why: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2106 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2107 tp_dict: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2108 It is a dict, so the collector will call its tp_clear. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2109 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2110 tp_cache: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2111 Not used; if it were, it would be a dict. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2112 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2113 tp_bases, tp_base: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2114 If these are involved in a cycle, there must be at least |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2115 one other, mutable object in the cycle, e.g. a base |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2116 class's dict; the cycle will be broken that way. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2117 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2118 tp_subclasses: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2119 A list of weak references can't be part of a cycle; and |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2120 lists have their own tp_clear. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2121 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2122 slots (in etype): |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2123 A tuple of strings can't be part of a cycle. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2124 */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2125 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2126 CLEAR(type->tp_mro); |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2127 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2128 #undef CLEAR |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2129 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2130 return 0; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2131 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2132 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2133 static int |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2134 type_is_gc(PyTypeObject *type) |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2135 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2136 return type->tp_flags & Py_TPFLAGS_HEAPTYPE; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2137 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2138 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2139 PyTypeObject PyType_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2140 PyObject_HEAD_INIT(&PyType_Type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2141 0, /* ob_size */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2142 "type", /* tp_name */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2143 sizeof(etype), /* tp_basicsize */ |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
2144 sizeof(PyMemberDef), /* tp_itemsize */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2145 (destructor)type_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2146 0, /* tp_print */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2147 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2148 0, /* tp_setattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2149 type_compare, /* tp_compare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2150 (reprfunc)type_repr, /* tp_repr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2151 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2152 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2153 0, /* tp_as_mapping */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2154 (hashfunc)_Py_HashPointer, /* tp_hash */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2155 (ternaryfunc)type_call, /* tp_call */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2156 0, /* tp_str */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2157 (getattrofunc)type_getattro, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2158 (setattrofunc)type_setattro, /* tp_setattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2159 0, /* tp_as_buffer */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2160 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2161 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2162 type_doc, /* tp_doc */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2163 (traverseproc)type_traverse, /* tp_traverse */ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2164 (inquiry)type_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2165 0, /* tp_richcompare */ |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2166 offsetof(PyTypeObject, tp_weaklist), /* tp_weaklistoffset */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2167 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2168 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2169 type_methods, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2170 type_members, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2171 type_getsets, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2172 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2173 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2174 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2175 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2176 offsetof(PyTypeObject, tp_dict), /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2177 0, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2178 0, /* tp_alloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2179 type_new, /* tp_new */ |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
2180 PyObject_GC_Del, /* tp_free */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2181 (inquiry)type_is_gc, /* tp_is_gc */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2182 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2183 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2184 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2185 /* The base type of all types (eventually)... except itself. */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2186 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2187 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2188 object_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2189 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2190 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2191 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2192 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2193 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2194 object_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2195 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2196 self->ob_type->tp_free(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2197 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2198 |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2199 static PyObject * |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2200 object_repr(PyObject *self) |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2201 { |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2202 PyTypeObject *type; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2203 PyObject *mod, *name, *rtn; |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2204 |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2205 type = self->ob_type; |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2206 mod = type_module(type, NULL); |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2207 if (mod == NULL) |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2208 PyErr_Clear(); |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2209 else if (!PyString_Check(mod)) { |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2210 Py_DECREF(mod); |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2211 mod = NULL; |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2212 } |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2213 name = type_name(type, NULL); |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2214 if (name == NULL) |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2215 return NULL; |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2216 if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) |
|
20056
33edc99861b9
Fix the baffler that Tim reported: sometimes the repr() of an object
Guido van Rossum <guido@python.org>
parents:
20028
diff
changeset
|
2217 rtn = PyString_FromFormat("<%s.%s object at %p>", |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2218 PyString_AS_STRING(mod), |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2219 PyString_AS_STRING(name), |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2220 self); |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2221 else |
|
20056
33edc99861b9
Fix the baffler that Tim reported: sometimes the repr() of an object
Guido van Rossum <guido@python.org>
parents:
20028
diff
changeset
|
2222 rtn = PyString_FromFormat("<%s object at %p>", |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2223 type->tp_name, self); |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2224 Py_XDECREF(mod); |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2225 Py_DECREF(name); |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2226 return rtn; |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2227 } |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2228 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2229 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2230 object_str(PyObject *self) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2231 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2232 unaryfunc f; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2233 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2234 f = self->ob_type->tp_repr; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2235 if (f == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2236 f = object_repr; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2237 return f(self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2238 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2239 |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2240 static long |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2241 object_hash(PyObject *self) |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2242 { |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2243 return _Py_HashPointer(self); |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2244 } |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2245 |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2246 static PyObject * |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2247 object_get_class(PyObject *self, void *closure) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2248 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2249 Py_INCREF(self->ob_type); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2250 return (PyObject *)(self->ob_type); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2251 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2252 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2253 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2254 equiv_structs(PyTypeObject *a, PyTypeObject *b) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2255 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2256 return a == b || |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2257 (a != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2258 b != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2259 a->tp_basicsize == b->tp_basicsize && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2260 a->tp_itemsize == b->tp_itemsize && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2261 a->tp_dictoffset == b->tp_dictoffset && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2262 a->tp_weaklistoffset == b->tp_weaklistoffset && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2263 ((a->tp_flags & Py_TPFLAGS_HAVE_GC) == |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2264 (b->tp_flags & Py_TPFLAGS_HAVE_GC))); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2265 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2266 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2267 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2268 same_slots_added(PyTypeObject *a, PyTypeObject *b) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2269 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2270 PyTypeObject *base = a->tp_base; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2271 int size; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2272 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2273 if (base != b->tp_base) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2274 return 0; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2275 if (equiv_structs(a, base) && equiv_structs(b, base)) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2276 return 1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2277 size = base->tp_basicsize; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2278 if (a->tp_dictoffset == size && b->tp_dictoffset == size) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2279 size += sizeof(PyObject *); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2280 if (a->tp_weaklistoffset == size && b->tp_weaklistoffset == size) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2281 size += sizeof(PyObject *); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2282 return size == a->tp_basicsize && size == b->tp_basicsize; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2283 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2284 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2285 static int |
| 26421 | 2286 compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr) |
| 2287 { | |
| 2288 PyTypeObject *newbase, *oldbase; | |
| 2289 | |
| 2290 if (new->tp_dealloc != old->tp_dealloc || | |
| 2291 new->tp_free != old->tp_free) | |
| 2292 { | |
| 2293 PyErr_Format(PyExc_TypeError, | |
| 2294 "%s assignment: " | |
| 2295 "'%s' deallocator differs from '%s'", | |
| 2296 attr, | |
| 2297 new->tp_name, | |
| 2298 old->tp_name); | |
| 2299 return 0; | |
| 2300 } | |
| 2301 newbase = new; | |
| 2302 oldbase = old; | |
| 2303 while (equiv_structs(newbase, newbase->tp_base)) | |
| 2304 newbase = newbase->tp_base; | |
| 2305 while (equiv_structs(oldbase, oldbase->tp_base)) | |
| 2306 oldbase = oldbase->tp_base; | |
| 2307 if (newbase != oldbase && | |
| 2308 (newbase->tp_base != oldbase->tp_base || | |
| 2309 !same_slots_added(newbase, oldbase))) { | |
| 2310 PyErr_Format(PyExc_TypeError, | |
| 2311 "%s assignment: " | |
| 2312 "'%s' object layout differs from '%s'", | |
| 2313 attr, | |
| 2314 new->tp_name, | |
| 2315 old->tp_name); | |
| 2316 return 0; | |
| 2317 } | |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
2318 |
| 26421 | 2319 return 1; |
| 2320 } | |
| 2321 | |
| 2322 static int | |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2323 object_set_class(PyObject *self, PyObject *value, void *closure) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2324 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2325 PyTypeObject *old = self->ob_type; |
| 26421 | 2326 PyTypeObject *new; |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2327 |
|
23037
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2328 if (value == NULL) { |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2329 PyErr_SetString(PyExc_TypeError, |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2330 "can't delete __class__ attribute"); |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2331 return -1; |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2332 } |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2333 if (!PyType_Check(value)) { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2334 PyErr_Format(PyExc_TypeError, |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2335 "__class__ must be set to new-style class, not '%s' object", |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2336 value->ob_type->tp_name); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2337 return -1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2338 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2339 new = (PyTypeObject *)value; |
|
24728
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2340 if (!(new->tp_flags & Py_TPFLAGS_HEAPTYPE) || |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2341 !(old->tp_flags & Py_TPFLAGS_HEAPTYPE)) |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2342 { |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2343 PyErr_Format(PyExc_TypeError, |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2344 "__class__ assignment: only for heap types"); |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2345 return -1; |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2346 } |
| 26421 | 2347 if (compatible_for_assignment(new, old, "__class__")) { |
| 2348 Py_INCREF(new); | |
| 2349 self->ob_type = new; | |
| 2350 Py_DECREF(old); | |
| 2351 return 0; | |
| 2352 } | |
| 2353 else { | |
|
23541
f6ded6efabcf
Add a safeguard against setting the class to something with a
Guido van Rossum <guido@python.org>
parents:
23127
diff
changeset
|
2354 return -1; |
|
f6ded6efabcf
Add a safeguard against setting the class to something with a
Guido van Rossum <guido@python.org>
parents:
23127
diff
changeset
|
2355 } |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2356 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2357 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2358 static PyGetSetDef object_getsets[] = { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2359 {"__class__", object_get_class, object_set_class, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
2360 PyDoc_STR("the object's class")}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2361 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2362 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2363 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2364 static PyObject * |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2365 object_reduce(PyObject *self, PyObject *args) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2366 { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2367 /* Call copy_reg._reduce(self) */ |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2368 static PyObject *copy_reg_str; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2369 PyObject *copy_reg, *res; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2370 |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2371 if (!copy_reg_str) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2372 copy_reg_str = PyString_InternFromString("copy_reg"); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2373 if (copy_reg_str == NULL) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2374 return NULL; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2375 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2376 copy_reg = PyImport_Import(copy_reg_str); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2377 if (!copy_reg) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2378 return NULL; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2379 res = PyEval_CallMethod(copy_reg, "_reduce", "(O)", self); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2380 Py_DECREF(copy_reg); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2381 return res; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2382 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2383 |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2384 static PyMethodDef object_methods[] = { |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
2385 {"__reduce__", object_reduce, METH_NOARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2386 PyDoc_STR("helper for pickle")}, |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2387 {0} |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2388 }; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2389 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2390 PyTypeObject PyBaseObject_Type = { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2391 PyObject_HEAD_INIT(&PyType_Type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2392 0, /* ob_size */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2393 "object", /* tp_name */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2394 sizeof(PyObject), /* tp_basicsize */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2395 0, /* tp_itemsize */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2396 (destructor)object_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2397 0, /* tp_print */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2398 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2399 0, /* tp_setattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2400 0, /* tp_compare */ |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2401 object_repr, /* tp_repr */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2402 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2403 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2404 0, /* tp_as_mapping */ |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2405 object_hash, /* tp_hash */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2406 0, /* tp_call */ |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2407 object_str, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2408 PyObject_GenericGetAttr, /* tp_getattro */ |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2409 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2410 0, /* tp_as_buffer */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2411 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2412 PyDoc_STR("The most base type"), /* tp_doc */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2413 0, /* tp_traverse */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2414 0, /* tp_clear */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2415 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2416 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2417 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2418 0, /* tp_iternext */ |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2419 object_methods, /* tp_methods */ |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2420 0, /* tp_members */ |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2421 object_getsets, /* tp_getset */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2422 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2423 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2424 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2425 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2426 0, /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2427 object_init, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2428 PyType_GenericAlloc, /* tp_alloc */ |
|
19108
b7984c9bbf2c
Thinking back to the 2.22 revision, I didn't like what I did there one
Guido van Rossum <guido@python.org>
parents:
19082
diff
changeset
|
2429 PyType_GenericNew, /* tp_new */ |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
2430 PyObject_Del, /* tp_free */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2431 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2432 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2433 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2434 /* Initialize the __dict__ in a type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2435 |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2436 static PyObject * |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2437 create_specialmethod(PyMethodDef *meth, PyObject *(*func)(PyObject *)) |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2438 { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2439 PyObject *cfunc; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2440 PyObject *result; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2441 |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2442 cfunc = PyCFunction_New(meth, NULL); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2443 if (cfunc == NULL) |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2444 return NULL; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2445 result = func(cfunc); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2446 Py_DECREF(cfunc); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2447 return result; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2448 } |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2449 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2450 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2451 add_methods(PyTypeObject *type, PyMethodDef *meth) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2452 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2453 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2454 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2455 for (; meth->ml_name != NULL; meth++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2456 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2457 if (PyDict_GetItemString(dict, meth->ml_name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2458 continue; |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2459 if (meth->ml_flags & METH_CLASS) { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2460 if (meth->ml_flags & METH_STATIC) { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2461 PyErr_SetString(PyExc_ValueError, |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2462 "method cannot be both class and static"); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2463 return -1; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2464 } |
|
26583
8991f78817c7
SF 548651: Fix the METH_CLASS implementation.
Tim Peters <tim.peters@gmail.com>
parents:
26575
diff
changeset
|
2465 descr = PyDescr_NewClassMethod(type, meth); |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2466 } |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2467 else if (meth->ml_flags & METH_STATIC) { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2468 descr = create_specialmethod(meth, PyStaticMethod_New); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2469 } |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2470 else { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2471 descr = PyDescr_NewMethod(type, meth); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2472 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2473 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2474 return -1; |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
2475 if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2476 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2477 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2478 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2479 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2480 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2481 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2482 static int |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
2483 add_members(PyTypeObject *type, PyMemberDef *memb) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2484 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2485 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2486 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2487 for (; memb->name != NULL; memb++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2488 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2489 if (PyDict_GetItemString(dict, memb->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2490 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2491 descr = PyDescr_NewMember(type, memb); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2492 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2493 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2494 if (PyDict_SetItemString(dict, memb->name, descr) < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2495 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2496 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2497 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2498 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2499 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2500 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2501 static int |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
2502 add_getset(PyTypeObject *type, PyGetSetDef *gsp) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2503 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2504 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2505 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2506 for (; gsp->name != NULL; gsp++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2507 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2508 if (PyDict_GetItemString(dict, gsp->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2509 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2510 descr = PyDescr_NewGetSet(type, gsp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2511 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2512 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2513 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2514 if (PyDict_SetItemString(dict, gsp->name, descr) < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2515 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2516 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2517 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2518 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2519 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2520 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2521 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2522 inherit_special(PyTypeObject *type, PyTypeObject *base) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2523 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2524 int oldsize, newsize; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2525 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2526 /* Special flag magic */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2527 if (!type->tp_as_buffer && base->tp_as_buffer) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2528 type->tp_flags &= ~Py_TPFLAGS_HAVE_GETCHARBUFFER; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2529 type->tp_flags |= |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2530 base->tp_flags & Py_TPFLAGS_HAVE_GETCHARBUFFER; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2531 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2532 if (!type->tp_as_sequence && base->tp_as_sequence) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2533 type->tp_flags &= ~Py_TPFLAGS_HAVE_SEQUENCE_IN; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2534 type->tp_flags |= base->tp_flags & Py_TPFLAGS_HAVE_SEQUENCE_IN; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2535 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2536 if ((type->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS) != |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2537 (base->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS)) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2538 if ((!type->tp_as_number && base->tp_as_number) || |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2539 (!type->tp_as_sequence && base->tp_as_sequence)) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2540 type->tp_flags &= ~Py_TPFLAGS_HAVE_INPLACEOPS; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2541 if (!type->tp_as_number && !type->tp_as_sequence) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2542 type->tp_flags |= base->tp_flags & |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2543 Py_TPFLAGS_HAVE_INPLACEOPS; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2544 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2545 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2546 /* Wow */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2547 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2548 if (!type->tp_as_number && base->tp_as_number) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2549 type->tp_flags &= ~Py_TPFLAGS_CHECKTYPES; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2550 type->tp_flags |= base->tp_flags & Py_TPFLAGS_CHECKTYPES; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2551 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2552 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2553 /* Copying basicsize is connected to the GC flags */ |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2554 oldsize = base->tp_basicsize; |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2555 newsize = type->tp_basicsize ? type->tp_basicsize : oldsize; |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2556 if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) && |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2557 (base->tp_flags & Py_TPFLAGS_HAVE_GC) && |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2558 (type->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE/*GC slots exist*/) && |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2559 (!type->tp_traverse && !type->tp_clear)) { |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2560 type->tp_flags |= Py_TPFLAGS_HAVE_GC; |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2561 if (type->tp_traverse == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2562 type->tp_traverse = base->tp_traverse; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2563 if (type->tp_clear == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2564 type->tp_clear = base->tp_clear; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2565 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2566 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) { |
|
21451
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2567 /* The condition below could use some explanation. |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2568 It appears that tp_new is not inherited for static types |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2569 whose base class is 'object'; this seems to be a precaution |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2570 so that old extension types don't suddenly become |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2571 callable (object.__new__ wouldn't insure the invariants |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2572 that the extension type's own factory function ensures). |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2573 Heap types, of course, are under our control, so they do |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2574 inherit tp_new; static extension types that specify some |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2575 other built-in type as the default are considered |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2576 new-style-aware so they also inherit object.__new__. */ |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2577 if (base != &PyBaseObject_Type || |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2578 (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2579 if (type->tp_new == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2580 type->tp_new = base->tp_new; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2581 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2582 } |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2583 type->tp_basicsize = newsize; |
|
19253
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2584 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2585 /* Copy other non-function slots */ |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2586 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2587 #undef COPYVAL |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2588 #define COPYVAL(SLOT) \ |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2589 if (type->SLOT == 0) type->SLOT = base->SLOT |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2590 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2591 COPYVAL(tp_itemsize); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2592 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_WEAKREFS) { |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2593 COPYVAL(tp_weaklistoffset); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2594 } |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2595 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) { |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2596 COPYVAL(tp_dictoffset); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
2597 } |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2598 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2599 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2600 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2601 inherit_slots(PyTypeObject *type, PyTypeObject *base) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2602 { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2603 PyTypeObject *basebase; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2604 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2605 #undef SLOTDEFINED |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2606 #undef COPYSLOT |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2607 #undef COPYNUM |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2608 #undef COPYSEQ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2609 #undef COPYMAP |
|
20386
3c01c34d07f6
Now that COPYBUF is a new local macro, add #undef COPYBUF.
Guido van Rossum <guido@python.org>
parents:
20384
diff
changeset
|
2610 #undef COPYBUF |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2611 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2612 #define SLOTDEFINED(SLOT) \ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2613 (base->SLOT != 0 && \ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2614 (basebase == NULL || base->SLOT != basebase->SLOT)) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2615 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2616 #define COPYSLOT(SLOT) \ |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2617 if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2618 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2619 #define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2620 #define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2621 #define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT) |
|
20384
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2622 #define COPYBUF(SLOT) COPYSLOT(tp_as_buffer->SLOT) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2623 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2624 /* This won't inherit indirect slots (from tp_as_number etc.) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2625 if type doesn't provide the space. */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2626 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2627 if (type->tp_as_number != NULL && base->tp_as_number != NULL) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2628 basebase = base->tp_base; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2629 if (basebase->tp_as_number == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2630 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2631 COPYNUM(nb_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2632 COPYNUM(nb_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2633 COPYNUM(nb_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2634 COPYNUM(nb_divide); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2635 COPYNUM(nb_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2636 COPYNUM(nb_divmod); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2637 COPYNUM(nb_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2638 COPYNUM(nb_negative); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2639 COPYNUM(nb_positive); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2640 COPYNUM(nb_absolute); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2641 COPYNUM(nb_nonzero); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2642 COPYNUM(nb_invert); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2643 COPYNUM(nb_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2644 COPYNUM(nb_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2645 COPYNUM(nb_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2646 COPYNUM(nb_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2647 COPYNUM(nb_or); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2648 COPYNUM(nb_coerce); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2649 COPYNUM(nb_int); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2650 COPYNUM(nb_long); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2651 COPYNUM(nb_float); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2652 COPYNUM(nb_oct); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2653 COPYNUM(nb_hex); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2654 COPYNUM(nb_inplace_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2655 COPYNUM(nb_inplace_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2656 COPYNUM(nb_inplace_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2657 COPYNUM(nb_inplace_divide); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2658 COPYNUM(nb_inplace_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2659 COPYNUM(nb_inplace_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2660 COPYNUM(nb_inplace_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2661 COPYNUM(nb_inplace_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2662 COPYNUM(nb_inplace_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2663 COPYNUM(nb_inplace_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2664 COPYNUM(nb_inplace_or); |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2665 if (base->tp_flags & Py_TPFLAGS_CHECKTYPES) { |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2666 COPYNUM(nb_true_divide); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2667 COPYNUM(nb_floor_divide); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2668 COPYNUM(nb_inplace_true_divide); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2669 COPYNUM(nb_inplace_floor_divide); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2670 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2671 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2672 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2673 if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2674 basebase = base->tp_base; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2675 if (basebase->tp_as_sequence == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2676 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2677 COPYSEQ(sq_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2678 COPYSEQ(sq_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2679 COPYSEQ(sq_repeat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2680 COPYSEQ(sq_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2681 COPYSEQ(sq_slice); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2682 COPYSEQ(sq_ass_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2683 COPYSEQ(sq_ass_slice); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2684 COPYSEQ(sq_contains); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2685 COPYSEQ(sq_inplace_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2686 COPYSEQ(sq_inplace_repeat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2687 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2688 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2689 if (type->tp_as_mapping != NULL && base->tp_as_mapping != NULL) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2690 basebase = base->tp_base; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2691 if (basebase->tp_as_mapping == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2692 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2693 COPYMAP(mp_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2694 COPYMAP(mp_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2695 COPYMAP(mp_ass_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2696 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2697 |
|
20384
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2698 if (type->tp_as_buffer != NULL && base->tp_as_buffer != NULL) { |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2699 basebase = base->tp_base; |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2700 if (basebase->tp_as_buffer == NULL) |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2701 basebase = NULL; |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2702 COPYBUF(bf_getreadbuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2703 COPYBUF(bf_getwritebuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2704 COPYBUF(bf_getsegcount); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2705 COPYBUF(bf_getcharbuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2706 } |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
2707 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2708 basebase = base->tp_base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2709 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2710 COPYSLOT(tp_dealloc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2711 COPYSLOT(tp_print); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2712 if (type->tp_getattr == NULL && type->tp_getattro == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2713 type->tp_getattr = base->tp_getattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2714 type->tp_getattro = base->tp_getattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2715 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2716 if (type->tp_setattr == NULL && type->tp_setattro == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2717 type->tp_setattr = base->tp_setattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2718 type->tp_setattro = base->tp_setattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2719 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2720 /* tp_compare see tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2721 COPYSLOT(tp_repr); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2722 /* tp_hash see tp_richcompare */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2723 COPYSLOT(tp_call); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2724 COPYSLOT(tp_str); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2725 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE) { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2726 if (type->tp_compare == NULL && |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2727 type->tp_richcompare == NULL && |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2728 type->tp_hash == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2729 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2730 type->tp_compare = base->tp_compare; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2731 type->tp_richcompare = base->tp_richcompare; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2732 type->tp_hash = base->tp_hash; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2733 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2734 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2735 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2736 COPYSLOT(tp_compare); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2737 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2738 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_ITER) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2739 COPYSLOT(tp_iter); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2740 COPYSLOT(tp_iternext); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2741 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2742 if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2743 COPYSLOT(tp_descr_get); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2744 COPYSLOT(tp_descr_set); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2745 COPYSLOT(tp_dictoffset); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2746 COPYSLOT(tp_init); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2747 COPYSLOT(tp_alloc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2748 COPYSLOT(tp_free); |
|
22848
e589e473f232
Inherit tp_new and tp_is_gc.
Guido van Rossum <guido@python.org>
parents:
22834
diff
changeset
|
2749 COPYSLOT(tp_is_gc); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2750 } |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2751 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2752 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
2753 static int add_operators(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2754 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2755 int |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
2756 PyType_Ready(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2757 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2758 PyObject *dict, *bases; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2759 PyTypeObject *base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2760 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2761 |
|
23756
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
2762 if (type->tp_flags & Py_TPFLAGS_READY) { |
|
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
2763 assert(type->tp_dict != NULL); |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2764 return 0; |
|
23756
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
2765 } |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2766 assert((type->tp_flags & Py_TPFLAGS_READYING) == 0); |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2767 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2768 type->tp_flags |= Py_TPFLAGS_READYING; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2769 |
|
22871
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2770 /* Initialize tp_base (defaults to BaseObject unless that's us) */ |
|
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2771 base = type->tp_base; |
|
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2772 if (base == NULL && type != &PyBaseObject_Type) |
|
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2773 base = type->tp_base = &PyBaseObject_Type; |
|
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2774 |
|
24825
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2775 /* Initialize the base class */ |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2776 if (base && base->tp_dict == NULL) { |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2777 if (PyType_Ready(base) < 0) |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2778 goto error; |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2779 } |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
2780 |
|
21451
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2781 /* Initialize ob_type if NULL. This means extensions that want to be |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2782 compilable separately on Windows can call PyType_Ready() instead of |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2783 initializing the ob_type field of their type objects. */ |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
2784 if (type->ob_type == NULL) |
|
22871
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
2785 type->ob_type = base->ob_type; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2786 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2787 /* Initialize tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2788 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2789 if (bases == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2790 if (base == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2791 bases = PyTuple_New(0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2792 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2793 bases = Py_BuildValue("(O)", base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2794 if (bases == NULL) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2795 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2796 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2797 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2798 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2799 /* Initialize tp_dict */ |
|
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2800 dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2801 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2802 dict = PyDict_New(); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2803 if (dict == NULL) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2804 goto error; |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2805 type->tp_dict = dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2806 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2807 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2808 /* Add type-specific descriptors to tp_dict */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2809 if (add_operators(type) < 0) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2810 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2811 if (type->tp_methods != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2812 if (add_methods(type, type->tp_methods) < 0) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2813 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2814 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2815 if (type->tp_members != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2816 if (add_members(type, type->tp_members) < 0) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2817 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2818 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2819 if (type->tp_getset != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2820 if (add_getset(type, type->tp_getset) < 0) |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2821 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2822 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2823 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2824 /* Calculate method resolution order */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2825 if (mro_internal(type) < 0) { |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2826 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2827 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2828 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2829 /* Inherit special flags from dominant base */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2830 if (type->tp_base != NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2831 inherit_special(type, type->tp_base); |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2832 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2833 /* Initialize tp_dict properly */ |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2834 bases = type->tp_mro; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2835 assert(bases != NULL); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2836 assert(PyTuple_Check(bases)); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2837 n = PyTuple_GET_SIZE(bases); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2838 for (i = 1; i < n; i++) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2839 PyObject *b = PyTuple_GET_ITEM(bases, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2840 if (PyType_Check(b)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2841 inherit_slots(type, (PyTypeObject *)b); |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2842 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2843 |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2844 /* if the type dictionary doesn't contain a __doc__, set it from |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2845 the tp_doc slot. |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2846 */ |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2847 if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2848 if (type->tp_doc != NULL) { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2849 PyObject *doc = PyString_FromString(type->tp_doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2850 PyDict_SetItemString(type->tp_dict, "__doc__", doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2851 Py_DECREF(doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2852 } else { |
|
22774
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
2853 PyDict_SetItemString(type->tp_dict, |
|
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
2854 "__doc__", Py_None); |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2855 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2856 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2857 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2858 /* Some more special stuff */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2859 base = type->tp_base; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2860 if (base != NULL) { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2861 if (type->tp_as_number == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2862 type->tp_as_number = base->tp_as_number; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2863 if (type->tp_as_sequence == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2864 type->tp_as_sequence = base->tp_as_sequence; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2865 if (type->tp_as_mapping == NULL) |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2866 type->tp_as_mapping = base->tp_as_mapping; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2867 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2868 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2869 /* Link into each base class's list of subclasses */ |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2870 bases = type->tp_bases; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2871 n = PyTuple_GET_SIZE(bases); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2872 for (i = 0; i < n; i++) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2873 PyObject *b = PyTuple_GET_ITEM(bases, i); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2874 if (PyType_Check(b) && |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
2875 add_subclass((PyTypeObject *)b, type) < 0) |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2876 goto error; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2877 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2878 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2879 /* All done -- set the ready flag */ |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2880 assert(type->tp_dict != NULL); |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2881 type->tp_flags = |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2882 (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2883 return 0; |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2884 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2885 error: |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2886 type->tp_flags &= ~Py_TPFLAGS_READYING; |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2887 return -1; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2888 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2889 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2890 static int |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2891 add_subclass(PyTypeObject *base, PyTypeObject *type) |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2892 { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2893 int i; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2894 PyObject *list, *ref, *new; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2895 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2896 list = base->tp_subclasses; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2897 if (list == NULL) { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2898 base->tp_subclasses = list = PyList_New(0); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2899 if (list == NULL) |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2900 return -1; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2901 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2902 assert(PyList_Check(list)); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2903 new = PyWeakref_NewRef((PyObject *)type, NULL); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2904 i = PyList_GET_SIZE(list); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2905 while (--i >= 0) { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2906 ref = PyList_GET_ITEM(list, i); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2907 assert(PyWeakref_CheckRef(ref)); |
|
25839
243503926c81
Sigh. That wasn't a memory leak, that was Guido committing before
Guido van Rossum <guido@python.org>
parents:
25837
diff
changeset
|
2908 if (PyWeakref_GET_OBJECT(ref) == Py_None) |
|
243503926c81
Sigh. That wasn't a memory leak, that was Guido committing before
Guido van Rossum <guido@python.org>
parents:
25837
diff
changeset
|
2909 return PyList_SetItem(list, i, new); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2910 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2911 i = PyList_Append(list, new); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2912 Py_DECREF(new); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2913 return i; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2914 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2915 |
| 26421 | 2916 static void |
| 2917 remove_subclass(PyTypeObject *base, PyTypeObject *type) | |
| 2918 { | |
| 2919 int i; | |
| 2920 PyObject *list, *ref; | |
| 2921 | |
| 2922 list = base->tp_subclasses; | |
| 2923 if (list == NULL) { | |
| 2924 return; | |
| 2925 } | |
| 2926 assert(PyList_Check(list)); | |
| 2927 i = PyList_GET_SIZE(list); | |
| 2928 while (--i >= 0) { | |
| 2929 ref = PyList_GET_ITEM(list, i); | |
| 2930 assert(PyWeakref_CheckRef(ref)); | |
| 2931 if (PyWeakref_GET_OBJECT(ref) == (PyObject*)type) { | |
| 2932 /* this can't fail, right? */ | |
| 2933 PySequence_DelItem(list, i); | |
| 2934 return; | |
| 2935 } | |
| 2936 } | |
| 2937 } | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2938 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2939 /* Generic wrappers for overloadable 'operators' such as __getitem__ */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2940 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2941 /* There's a wrapper *function* for each distinct function typedef used |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2942 for type object slots (e.g. binaryfunc, ternaryfunc, etc.). There's a |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2943 wrapper *table* for each distinct operation (e.g. __len__, __add__). |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2944 Most tables have only one entry; the tables for binary operators have two |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2945 entries, one regular and one with reversed arguments. */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2946 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2947 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2948 wrap_inquiry(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2949 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2950 inquiry func = (inquiry)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2951 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2952 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2953 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2954 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2955 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2956 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2957 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2958 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2959 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2960 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2961 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2962 wrap_binaryfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2963 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2964 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2965 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2966 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2967 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2968 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2969 return (*func)(self, other); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2970 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2971 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2972 static PyObject * |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2973 wrap_binaryfunc_l(PyObject *self, PyObject *args, void *wrapped) |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2974 { |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2975 binaryfunc func = (binaryfunc)wrapped; |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2976 PyObject *other; |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2977 |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2978 if (!PyArg_ParseTuple(args, "O", &other)) |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2979 return NULL; |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2980 if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) && |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2981 !PyType_IsSubtype(other->ob_type, self->ob_type)) { |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2982 Py_INCREF(Py_NotImplemented); |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2983 return Py_NotImplemented; |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2984 } |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2985 return (*func)(self, other); |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2986 } |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2987 |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2988 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2989 wrap_binaryfunc_r(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2990 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2991 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2992 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2993 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2994 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2995 return NULL; |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2996 if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) && |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2997 !PyType_IsSubtype(other->ob_type, self->ob_type)) { |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2998 Py_INCREF(Py_NotImplemented); |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2999 return Py_NotImplemented; |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
3000 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3001 return (*func)(other, self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3002 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3003 |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3004 static PyObject * |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3005 wrap_coercefunc(PyObject *self, PyObject *args, void *wrapped) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3006 { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3007 coercion func = (coercion)wrapped; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3008 PyObject *other, *res; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3009 int ok; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3010 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3011 if (!PyArg_ParseTuple(args, "O", &other)) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3012 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3013 ok = func(&self, &other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3014 if (ok < 0) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3015 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3016 if (ok > 0) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3017 Py_INCREF(Py_NotImplemented); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3018 return Py_NotImplemented; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3019 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3020 res = PyTuple_New(2); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3021 if (res == NULL) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3022 Py_DECREF(self); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3023 Py_DECREF(other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3024 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3025 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3026 PyTuple_SET_ITEM(res, 0, self); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3027 PyTuple_SET_ITEM(res, 1, other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3028 return res; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3029 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3030 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3031 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3032 wrap_ternaryfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3033 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3034 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3035 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3036 PyObject *third = Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3037 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3038 /* Note: This wrapper only works for __pow__() */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3039 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3040 if (!PyArg_ParseTuple(args, "O|O", &other, &third)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3041 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3042 return (*func)(self, other, third); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3043 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3044 |
|
20168
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3045 static PyObject * |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3046 wrap_ternaryfunc_r(PyObject *self, PyObject *args, void *wrapped) |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3047 { |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3048 ternaryfunc func = (ternaryfunc)wrapped; |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3049 PyObject *other; |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3050 PyObject *third = Py_None; |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3051 |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3052 /* Note: This wrapper only works for __pow__() */ |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3053 |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3054 if (!PyArg_ParseTuple(args, "O|O", &other, &third)) |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3055 return NULL; |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3056 return (*func)(other, self, third); |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3057 } |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
3058 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3059 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3060 wrap_unaryfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3061 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3062 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3063 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3064 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3065 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3066 return (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3067 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3068 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3069 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3070 wrap_intargfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3071 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3072 intargfunc func = (intargfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3073 int i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3074 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3075 if (!PyArg_ParseTuple(args, "i", &i)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3076 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3077 return (*func)(self, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3078 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3079 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3080 static int |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3081 getindex(PyObject *self, PyObject *arg) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3082 { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3083 int i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3084 |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3085 i = PyInt_AsLong(arg); |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3086 if (i == -1 && PyErr_Occurred()) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3087 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3088 if (i < 0) { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3089 PySequenceMethods *sq = self->ob_type->tp_as_sequence; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3090 if (sq && sq->sq_length) { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3091 int n = (*sq->sq_length)(self); |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3092 if (n < 0) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3093 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3094 i += n; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3095 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3096 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3097 return i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3098 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3099 |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3100 static PyObject * |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3101 wrap_sq_item(PyObject *self, PyObject *args, void *wrapped) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3102 { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3103 intargfunc func = (intargfunc)wrapped; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3104 PyObject *arg; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3105 int i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3106 |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3107 if (PyTuple_GET_SIZE(args) == 1) { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3108 arg = PyTuple_GET_ITEM(args, 0); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3109 i = getindex(self, arg); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3110 if (i == -1 && PyErr_Occurred()) |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3111 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3112 return (*func)(self, i); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3113 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3114 PyArg_ParseTuple(args, "O", &arg); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3115 assert(PyErr_Occurred()); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3116 return NULL; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3117 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3118 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3119 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3120 wrap_intintargfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3121 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3122 intintargfunc func = (intintargfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3123 int i, j; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3124 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3125 if (!PyArg_ParseTuple(args, "ii", &i, &j)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3126 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3127 return (*func)(self, i, j); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3128 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3129 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3130 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3131 wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3132 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3133 intobjargproc func = (intobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3134 int i, res; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3135 PyObject *arg, *value; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3136 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3137 if (!PyArg_ParseTuple(args, "OO", &arg, &value)) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3138 return NULL; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3139 i = getindex(self, arg); |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3140 if (i == -1 && PyErr_Occurred()) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3141 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3142 res = (*func)(self, i, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3143 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3144 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3145 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3146 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3147 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3148 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3149 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3150 wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped) |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3151 { |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3152 intobjargproc func = (intobjargproc)wrapped; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3153 int i, res; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3154 PyObject *arg; |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3155 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3156 if (!PyArg_ParseTuple(args, "O", &arg)) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3157 return NULL; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3158 i = getindex(self, arg); |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
3159 if (i == -1 && PyErr_Occurred()) |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3160 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3161 res = (*func)(self, i, NULL); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3162 if (res == -1 && PyErr_Occurred()) |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3163 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3164 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3165 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3166 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3167 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3168 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3169 wrap_intintobjargproc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3170 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3171 intintobjargproc func = (intintobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3172 int i, j, res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3173 PyObject *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3174 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3175 if (!PyArg_ParseTuple(args, "iiO", &i, &j, &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3176 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3177 res = (*func)(self, i, j, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3178 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3179 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3180 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3181 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3182 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3183 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3184 static PyObject * |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3185 wrap_delslice(PyObject *self, PyObject *args, void *wrapped) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3186 { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3187 intintobjargproc func = (intintobjargproc)wrapped; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3188 int i, j, res; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3189 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3190 if (!PyArg_ParseTuple(args, "ii", &i, &j)) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3191 return NULL; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3192 res = (*func)(self, i, j, NULL); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3193 if (res == -1 && PyErr_Occurred()) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3194 return NULL; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3195 Py_INCREF(Py_None); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3196 return Py_None; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3197 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3198 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3199 /* XXX objobjproc is a misnomer; should be objargpred */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3200 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3201 wrap_objobjproc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3202 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3203 objobjproc func = (objobjproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3204 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3205 PyObject *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3206 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3207 if (!PyArg_ParseTuple(args, "O", &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3208 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3209 res = (*func)(self, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3210 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3211 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3212 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3213 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3214 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3215 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3216 wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3217 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3218 objobjargproc func = (objobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3219 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3220 PyObject *key, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3221 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3222 if (!PyArg_ParseTuple(args, "OO", &key, &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3223 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3224 res = (*func)(self, key, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3225 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3226 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3227 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3228 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3229 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3230 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3231 static PyObject * |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3232 wrap_delitem(PyObject *self, PyObject *args, void *wrapped) |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3233 { |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3234 objobjargproc func = (objobjargproc)wrapped; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3235 int res; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3236 PyObject *key; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3237 |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3238 if (!PyArg_ParseTuple(args, "O", &key)) |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3239 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3240 res = (*func)(self, key, NULL); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3241 if (res == -1 && PyErr_Occurred()) |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3242 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3243 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3244 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3245 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
3246 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3247 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3248 wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3249 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3250 cmpfunc func = (cmpfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3251 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3252 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3253 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3254 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3255 return NULL; |
|
20063
9a599b1d9d1c
Another comparison patch-up: comparing a type with a dynamic metatype
Guido van Rossum <guido@python.org>
parents:
20056
diff
changeset
|
3256 if (other->ob_type->tp_compare != func && |
|
9a599b1d9d1c
Another comparison patch-up: comparing a type with a dynamic metatype
Guido van Rossum <guido@python.org>
parents:
20056
diff
changeset
|
3257 !PyType_IsSubtype(other->ob_type, self->ob_type)) { |
|
19964
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3258 PyErr_Format( |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3259 PyExc_TypeError, |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3260 "%s.__cmp__(x,y) requires y to be a '%s', not a '%s'", |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3261 self->ob_type->tp_name, |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3262 self->ob_type->tp_name, |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3263 other->ob_type->tp_name); |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3264 return NULL; |
|
43e5fd54f8c9
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
Guido van Rossum <guido@python.org>
parents:
19950
diff
changeset
|
3265 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3266 res = (*func)(self, other); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3267 if (PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3268 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3269 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3270 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3271 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3272 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3273 wrap_setattr(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3274 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3275 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3276 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3277 PyObject *name, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3278 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3279 if (!PyArg_ParseTuple(args, "OO", &name, &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3280 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3281 res = (*func)(self, name, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3282 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3283 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3284 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3285 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3286 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3287 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3288 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3289 wrap_delattr(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3290 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3291 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3292 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3293 PyObject *name; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3294 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3295 if (!PyArg_ParseTuple(args, "O", &name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3296 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3297 res = (*func)(self, name, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3298 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3299 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3300 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3301 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3302 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3303 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3304 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3305 wrap_hashfunc(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3306 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3307 hashfunc func = (hashfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3308 long res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3309 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3310 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3311 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3312 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3313 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3314 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3315 return PyInt_FromLong(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3316 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3317 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3318 static PyObject * |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3319 wrap_call(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3320 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3321 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3322 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3323 return (*func)(self, args, kwds); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3324 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3325 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3326 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3327 wrap_richcmpfunc(PyObject *self, PyObject *args, void *wrapped, int op) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3328 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3329 richcmpfunc func = (richcmpfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3330 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3331 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3332 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3333 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3334 return (*func)(self, other, op); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3335 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3336 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3337 #undef RICHCMP_WRAPPER |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3338 #define RICHCMP_WRAPPER(NAME, OP) \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3339 static PyObject * \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3340 richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3341 { \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3342 return wrap_richcmpfunc(self, args, wrapped, OP); \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3343 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3344 |
|
19070
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3345 RICHCMP_WRAPPER(lt, Py_LT) |
|
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3346 RICHCMP_WRAPPER(le, Py_LE) |
|
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3347 RICHCMP_WRAPPER(eq, Py_EQ) |
|
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3348 RICHCMP_WRAPPER(ne, Py_NE) |
|
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3349 RICHCMP_WRAPPER(gt, Py_GT) |
|
39a73c6773f1
Removed extraneous semicolons that caused a gazzilion "empty declaration" warnings in the MetroWerks compiler.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19040
diff
changeset
|
3350 RICHCMP_WRAPPER(ge, Py_GE) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3351 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3352 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3353 wrap_next(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3354 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3355 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3356 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3357 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3358 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3359 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3360 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3361 if (res == NULL && !PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3362 PyErr_SetNone(PyExc_StopIteration); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3363 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3364 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3365 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3366 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3367 wrap_descr_get(PyObject *self, PyObject *args, void *wrapped) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3368 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3369 descrgetfunc func = (descrgetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3370 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3371 PyObject *type = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3372 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3373 if (!PyArg_ParseTuple(args, "O|O", &obj, &type)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3374 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3375 return (*func)(self, obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3376 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3377 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3378 static PyObject * |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3379 wrap_descr_set(PyObject *self, PyObject *args, void *wrapped) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3380 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3381 descrsetfunc func = (descrsetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3382 PyObject *obj, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3383 int ret; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3384 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3385 if (!PyArg_ParseTuple(args, "OO", &obj, &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3386 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3387 ret = (*func)(self, obj, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3388 if (ret < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3389 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3390 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3391 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3392 } |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
3393 |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3394 static PyObject * |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3395 wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped) |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3396 { |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3397 descrsetfunc func = (descrsetfunc)wrapped; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3398 PyObject *obj; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3399 int ret; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3400 |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3401 if (!PyArg_ParseTuple(args, "O", &obj)) |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3402 return NULL; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3403 ret = (*func)(self, obj, NULL); |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3404 if (ret < 0) |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3405 return NULL; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3406 Py_INCREF(Py_None); |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3407 return Py_None; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
3408 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3409 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3410 static PyObject * |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3411 wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3412 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3413 initproc func = (initproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3414 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3415 if (func(self, args, kwds) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3416 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3417 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3418 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3419 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3420 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3421 static PyObject * |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3422 tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3423 { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3424 PyTypeObject *type, *subtype, *staticbase; |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3425 PyObject *arg0, *res; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3426 |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3427 if (self == NULL || !PyType_Check(self)) |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3428 Py_FatalError("__new__() called with non-type 'self'"); |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3429 type = (PyTypeObject *)self; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3430 if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3431 PyErr_Format(PyExc_TypeError, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3432 "%s.__new__(): not enough arguments", |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3433 type->tp_name); |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3434 return NULL; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3435 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3436 arg0 = PyTuple_GET_ITEM(args, 0); |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3437 if (!PyType_Check(arg0)) { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3438 PyErr_Format(PyExc_TypeError, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3439 "%s.__new__(X): X is not a type object (%s)", |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3440 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3441 arg0->ob_type->tp_name); |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3442 return NULL; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3443 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3444 subtype = (PyTypeObject *)arg0; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3445 if (!PyType_IsSubtype(subtype, type)) { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3446 PyErr_Format(PyExc_TypeError, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3447 "%s.__new__(%s): %s is not a subtype of %s", |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3448 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3449 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3450 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3451 type->tp_name); |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3452 return NULL; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3453 } |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3454 |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3455 /* Check that the use doesn't do something silly and unsafe like |
|
20754
272336648d1f
Rename "dictionary" (type and constructor) to "dict".
Tim Peters <tim.peters@gmail.com>
parents:
20753
diff
changeset
|
3456 object.__new__(dict). To do this, we check that the |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3457 most derived base that's not a heap type is this type. */ |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3458 staticbase = subtype; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3459 while (staticbase && (staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE)) |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3460 staticbase = staticbase->tp_base; |
|
19914
2027dc124edd
tp_new_wrapper(): A subtle change in the check for safe use.
Guido van Rossum <guido@python.org>
parents:
19913
diff
changeset
|
3461 if (staticbase->tp_new != type->tp_new) { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3462 PyErr_Format(PyExc_TypeError, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3463 "%s.__new__(%s) is not safe, use %s.__new__()", |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3464 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3465 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3466 staticbase == NULL ? "?" : staticbase->tp_name); |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3467 return NULL; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3468 } |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
3469 |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3470 args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3471 if (args == NULL) |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3472 return NULL; |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3473 res = type->tp_new(subtype, args, kwds); |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3474 Py_DECREF(args); |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3475 return res; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3476 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3477 |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3478 static struct PyMethodDef tp_new_methoddef[] = { |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3479 {"__new__", (PyCFunction)tp_new_wrapper, METH_KEYWORDS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
3480 PyDoc_STR("T.__new__(S, ...) -> " |
|
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
3481 "a new object with type S, a subtype of T")}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3482 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3483 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3484 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3485 static int |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3486 add_tp_new_wrapper(PyTypeObject *type) |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3487 { |
| 19036 | 3488 PyObject *func; |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3489 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3490 if (PyDict_GetItemString(type->tp_dict, "__new__") != NULL) |
| 19036 | 3491 return 0; |
| 3492 func = PyCFunction_New(tp_new_methoddef, (PyObject *)type); | |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3493 if (func == NULL) |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3494 return -1; |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3495 return PyDict_SetItemString(type->tp_dict, "__new__", func); |
|
19011
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3496 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
3497 |
| 19036 | 3498 /* Slot wrappers that call the corresponding __foo__ slot. See comments |
| 3499 below at override_slots() for more explanation. */ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3500 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3501 #define SLOT0(FUNCNAME, OPSTR) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3502 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3503 FUNCNAME(PyObject *self) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3504 { \ |
|
19540
e141b392b61d
Fix a typo in SLOT0 macro for the declaration of cache_str.
Guido van Rossum <guido@python.org>
parents:
19538
diff
changeset
|
3505 static PyObject *cache_str; \ |
| 19911 | 3506 return call_method(self, OPSTR, &cache_str, "()"); \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3507 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3508 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3509 #define SLOT1(FUNCNAME, OPSTR, ARG1TYPE, ARGCODES) \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3510 static PyObject * \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3511 FUNCNAME(PyObject *self, ARG1TYPE arg1) \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3512 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3513 static PyObject *cache_str; \ |
| 19911 | 3514 return call_method(self, OPSTR, &cache_str, "(" ARGCODES ")", arg1); \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3515 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3516 |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3517 /* Boolean helper for SLOT1BINFULL(). |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3518 right.__class__ is a nontrivial subclass of left.__class__. */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3519 static int |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3520 method_is_overloaded(PyObject *left, PyObject *right, char *name) |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3521 { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3522 PyObject *a, *b; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3523 int ok; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3524 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3525 b = PyObject_GetAttrString((PyObject *)(right->ob_type), name); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3526 if (b == NULL) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3527 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3528 /* If right doesn't have it, it's not overloaded */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3529 return 0; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3530 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3531 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3532 a = PyObject_GetAttrString((PyObject *)(left->ob_type), name); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3533 if (a == NULL) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3534 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3535 Py_DECREF(b); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3536 /* If right has it but left doesn't, it's overloaded */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3537 return 1; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3538 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3539 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3540 ok = PyObject_RichCompareBool(a, b, Py_NE); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3541 Py_DECREF(a); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3542 Py_DECREF(b); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3543 if (ok < 0) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3544 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3545 return 0; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3546 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3547 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3548 return ok; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3549 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3550 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3551 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3552 #define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR, ROPSTR) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3553 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3554 FUNCNAME(PyObject *self, PyObject *other) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3555 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3556 static PyObject *cache_str, *rcache_str; \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3557 int do_other = self->ob_type != other->ob_type && \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3558 other->ob_type->tp_as_number != NULL && \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3559 other->ob_type->tp_as_number->SLOTNAME == TESTFUNC; \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3560 if (self->ob_type->tp_as_number != NULL && \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3561 self->ob_type->tp_as_number->SLOTNAME == TESTFUNC) { \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3562 PyObject *r; \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3563 if (do_other && \ |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3564 PyType_IsSubtype(other->ob_type, self->ob_type) && \ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
3565 method_is_overloaded(self, other, ROPSTR)) { \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3566 r = call_maybe( \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3567 other, ROPSTR, &rcache_str, "(O)", self); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3568 if (r != Py_NotImplemented) \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3569 return r; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3570 Py_DECREF(r); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3571 do_other = 0; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3572 } \ |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
3573 r = call_maybe( \ |
| 19911 | 3574 self, OPSTR, &cache_str, "(O)", other); \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3575 if (r != Py_NotImplemented || \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3576 other->ob_type == self->ob_type) \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3577 return r; \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3578 Py_DECREF(r); \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3579 } \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3580 if (do_other) { \ |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
3581 return call_maybe( \ |
| 19911 | 3582 other, ROPSTR, &rcache_str, "(O)", self); \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3583 } \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3584 Py_INCREF(Py_NotImplemented); \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3585 return Py_NotImplemented; \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3586 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3587 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3588 #define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3589 SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR) |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3590 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3591 #define SLOT2(FUNCNAME, OPSTR, ARG1TYPE, ARG2TYPE, ARGCODES) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3592 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3593 FUNCNAME(PyObject *self, ARG1TYPE arg1, ARG2TYPE arg2) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3594 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3595 static PyObject *cache_str; \ |
| 19911 | 3596 return call_method(self, OPSTR, &cache_str, \ |
| 3597 "(" ARGCODES ")", arg1, arg2); \ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3598 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3599 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3600 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3601 slot_sq_length(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3602 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3603 static PyObject *len_str; |
| 19911 | 3604 PyObject *res = call_method(self, "__len__", &len_str, "()"); |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
3605 int len; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3606 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3607 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3608 return -1; |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
3609 len = (int)PyInt_AsLong(res); |
|
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
3610 Py_DECREF(res); |
|
24381
d8a682d4c692
Don't be so hasty. If PyInt_AsLong() raises an error, don't set ValueError.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24376
diff
changeset
|
3611 if (len == -1 && PyErr_Occurred()) |
|
d8a682d4c692
Don't be so hasty. If PyInt_AsLong() raises an error, don't set ValueError.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24376
diff
changeset
|
3612 return -1; |
|
24376
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
3613 if (len < 0) { |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
3614 PyErr_SetString(PyExc_ValueError, |
|
24376
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
3615 "__len__() should return >= 0"); |
|
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
3616 return -1; |
|
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
3617 } |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
3618 return len; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3619 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3620 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3621 SLOT1(slot_sq_concat, "__add__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3622 SLOT1(slot_sq_repeat, "__mul__", int, "i") |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3623 |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3624 /* Super-optimized version of slot_sq_item. |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3625 Other slots could do the same... */ |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3626 static PyObject * |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3627 slot_sq_item(PyObject *self, int i) |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3628 { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3629 static PyObject *getitem_str; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3630 PyObject *func, *args = NULL, *ival = NULL, *retval = NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3631 descrgetfunc f; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3632 |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3633 if (getitem_str == NULL) { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3634 getitem_str = PyString_InternFromString("__getitem__"); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3635 if (getitem_str == NULL) |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3636 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3637 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3638 func = _PyType_Lookup(self->ob_type, getitem_str); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3639 if (func != NULL) { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3640 if ((f = func->ob_type->tp_descr_get) == NULL) |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3641 Py_INCREF(func); |
|
25853
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
3642 else { |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3643 func = f(func, self, (PyObject *)(self->ob_type)); |
|
25853
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
3644 if (func == NULL) { |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
3645 return NULL; |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
3646 } |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
3647 } |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3648 ival = PyInt_FromLong(i); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3649 if (ival != NULL) { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3650 args = PyTuple_New(1); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3651 if (args != NULL) { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3652 PyTuple_SET_ITEM(args, 0, ival); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3653 retval = PyObject_Call(func, args, NULL); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3654 Py_XDECREF(args); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3655 Py_XDECREF(func); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3656 return retval; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3657 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3658 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3659 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3660 else { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3661 PyErr_SetObject(PyExc_AttributeError, getitem_str); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3662 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3663 Py_XDECREF(args); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3664 Py_XDECREF(ival); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3665 Py_XDECREF(func); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3666 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3667 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
3668 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3669 SLOT2(slot_sq_slice, "__getslice__", int, int, "ii") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3670 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3671 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3672 slot_sq_ass_item(PyObject *self, int index, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3673 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3674 PyObject *res; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3675 static PyObject *delitem_str, *setitem_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3676 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3677 if (value == NULL) |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3678 res = call_method(self, "__delitem__", &delitem_str, |
| 19911 | 3679 "(i)", index); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3680 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3681 res = call_method(self, "__setitem__", &setitem_str, |
| 19911 | 3682 "(iO)", index, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3683 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3684 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3685 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3686 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3687 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3688 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3689 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3690 slot_sq_ass_slice(PyObject *self, int i, int j, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3691 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3692 PyObject *res; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3693 static PyObject *delslice_str, *setslice_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3694 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3695 if (value == NULL) |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3696 res = call_method(self, "__delslice__", &delslice_str, |
| 19911 | 3697 "(ii)", i, j); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3698 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3699 res = call_method(self, "__setslice__", &setslice_str, |
| 19911 | 3700 "(iiO)", i, j, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3701 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3702 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3703 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3704 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3705 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3706 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3707 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3708 slot_sq_contains(PyObject *self, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3709 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3710 PyObject *func, *res, *args; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3711 static PyObject *contains_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3712 |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3713 func = lookup_maybe(self, "__contains__", &contains_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3714 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3715 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3716 args = Py_BuildValue("(O)", value); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3717 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3718 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3719 else { |
| 19911 | 3720 res = PyObject_Call(func, args, NULL); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3721 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3722 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3723 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3724 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3725 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3726 return PyObject_IsTrue(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3727 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3728 else if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3729 return -1; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3730 else { |
|
19808
0584c9132525
Generalize operator.indexOf (PySequence_Index) to work with any
Tim Peters <tim.peters@gmail.com>
parents:
19803
diff
changeset
|
3731 return _PySequence_IterSearch(self, value, |
|
0584c9132525
Generalize operator.indexOf (PySequence_Index) to work with any
Tim Peters <tim.peters@gmail.com>
parents:
19803
diff
changeset
|
3732 PY_ITERSEARCH_CONTAINS); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3733 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3734 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3735 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3736 SLOT1(slot_sq_inplace_concat, "__iadd__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3737 SLOT1(slot_sq_inplace_repeat, "__imul__", int, "i") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3738 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3739 #define slot_mp_length slot_sq_length |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3740 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3741 SLOT1(slot_mp_subscript, "__getitem__", PyObject *, "O") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3742 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3743 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3744 slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3745 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3746 PyObject *res; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3747 static PyObject *delitem_str, *setitem_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3748 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3749 if (value == NULL) |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3750 res = call_method(self, "__delitem__", &delitem_str, |
| 19911 | 3751 "(O)", key); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3752 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3753 res = call_method(self, "__setitem__", &setitem_str, |
| 19911 | 3754 "(OO)", key, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3755 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3756 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3757 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3758 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3759 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3760 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3761 SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3762 SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3763 SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3764 SLOT1BIN(slot_nb_divide, nb_divide, "__div__", "__rdiv__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3765 SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3766 SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3767 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
3768 static PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *); |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3769 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3770 SLOT1BINFULL(slot_nb_power_binary, slot_nb_power, |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3771 nb_power, "__pow__", "__rpow__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3772 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3773 static PyObject * |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3774 slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3775 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3776 static PyObject *pow_str; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3777 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3778 if (modulus == Py_None) |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3779 return slot_nb_power_binary(self, other); |
|
23753
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3780 /* Three-arg power doesn't use __rpow__. But ternary_op |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3781 can call this when the second argument's type uses |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3782 slot_nb_power, so check before calling self.__pow__. */ |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3783 if (self->ob_type->tp_as_number != NULL && |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3784 self->ob_type->tp_as_number->nb_power == slot_nb_power) { |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3785 return call_method(self, "__pow__", &pow_str, |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3786 "(OO)", other, modulus); |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3787 } |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3788 Py_INCREF(Py_NotImplemented); |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
3789 return Py_NotImplemented; |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3790 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3791 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3792 SLOT0(slot_nb_negative, "__neg__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3793 SLOT0(slot_nb_positive, "__pos__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3794 SLOT0(slot_nb_absolute, "__abs__") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3795 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3796 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3797 slot_nb_nonzero(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3798 { |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3799 PyObject *func, *args; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3800 static PyObject *nonzero_str, *len_str; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3801 int result = -1; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3802 |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3803 func = lookup_maybe(self, "__nonzero__", &nonzero_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3804 if (func == NULL) { |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3805 if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3806 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3807 func = lookup_maybe(self, "__len__", &len_str); |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3808 if (func == NULL) |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3809 return PyErr_Occurred() ? -1 : 1; |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3810 } |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3811 args = PyTuple_New(0); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3812 if (args != NULL) { |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3813 PyObject *temp = PyObject_Call(func, args, NULL); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3814 Py_DECREF(args); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3815 if (temp != NULL) { |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3816 result = PyObject_IsTrue(temp); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3817 Py_DECREF(temp); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3818 } |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3819 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3820 Py_DECREF(func); |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
3821 return result; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3822 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3823 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3824 SLOT0(slot_nb_invert, "__invert__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3825 SLOT1BIN(slot_nb_lshift, nb_lshift, "__lshift__", "__rlshift__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3826 SLOT1BIN(slot_nb_rshift, nb_rshift, "__rshift__", "__rrshift__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3827 SLOT1BIN(slot_nb_and, nb_and, "__and__", "__rand__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3828 SLOT1BIN(slot_nb_xor, nb_xor, "__xor__", "__rxor__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3829 SLOT1BIN(slot_nb_or, nb_or, "__or__", "__ror__") |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3830 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3831 static int |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3832 slot_nb_coerce(PyObject **a, PyObject **b) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3833 { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3834 static PyObject *coerce_str; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3835 PyObject *self = *a, *other = *b; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3836 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3837 if (self->ob_type->tp_as_number != NULL && |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3838 self->ob_type->tp_as_number->nb_coerce == slot_nb_coerce) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3839 PyObject *r; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3840 r = call_maybe( |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3841 self, "__coerce__", &coerce_str, "(O)", other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3842 if (r == NULL) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3843 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3844 if (r == Py_NotImplemented) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3845 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3846 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3847 else { |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3848 if (!PyTuple_Check(r) || PyTuple_GET_SIZE(r) != 2) { |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3849 PyErr_SetString(PyExc_TypeError, |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3850 "__coerce__ didn't return a 2-tuple"); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3851 Py_DECREF(r); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3852 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3853 } |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3854 *a = PyTuple_GET_ITEM(r, 0); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3855 Py_INCREF(*a); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3856 *b = PyTuple_GET_ITEM(r, 1); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3857 Py_INCREF(*b); |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3858 Py_DECREF(r); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
3859 return 0; |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3860 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3861 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3862 if (other->ob_type->tp_as_number != NULL && |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3863 other->ob_type->tp_as_number->nb_coerce == slot_nb_coerce) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3864 PyObject *r; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3865 r = call_maybe( |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3866 other, "__coerce__", &coerce_str, "(O)", self); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3867 if (r == NULL) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3868 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3869 if (r == Py_NotImplemented) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3870 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3871 return 1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3872 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3873 if (!PyTuple_Check(r) || PyTuple_GET_SIZE(r) != 2) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3874 PyErr_SetString(PyExc_TypeError, |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3875 "__coerce__ didn't return a 2-tuple"); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3876 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3877 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3878 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3879 *a = PyTuple_GET_ITEM(r, 1); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3880 Py_INCREF(*a); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3881 *b = PyTuple_GET_ITEM(r, 0); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3882 Py_INCREF(*b); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3883 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3884 return 0; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3885 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3886 return 1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3887 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
3888 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3889 SLOT0(slot_nb_int, "__int__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3890 SLOT0(slot_nb_long, "__long__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3891 SLOT0(slot_nb_float, "__float__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3892 SLOT0(slot_nb_oct, "__oct__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3893 SLOT0(slot_nb_hex, "__hex__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3894 SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3895 SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3896 SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3897 SLOT1(slot_nb_inplace_divide, "__idiv__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3898 SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O") |
|
25794
001b789f1f84
For some reason (probably cut and paste), __ipow__ for new-style
Guido van Rossum <guido@python.org>
parents:
25793
diff
changeset
|
3899 SLOT1(slot_nb_inplace_power, "__ipow__", PyObject *, "O") |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3900 SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3901 SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3902 SLOT1(slot_nb_inplace_and, "__iand__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3903 SLOT1(slot_nb_inplace_xor, "__ixor__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3904 SLOT1(slot_nb_inplace_or, "__ior__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3905 SLOT1BIN(slot_nb_floor_divide, nb_floor_divide, |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3906 "__floordiv__", "__rfloordiv__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3907 SLOT1BIN(slot_nb_true_divide, nb_true_divide, "__truediv__", "__rtruediv__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3908 SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
3909 SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *, "O") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3910 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3911 static int |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3912 half_compare(PyObject *self, PyObject *other) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3913 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3914 PyObject *func, *args, *res; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3915 static PyObject *cmp_str; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3916 int c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3917 |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3918 func = lookup_method(self, "__cmp__", &cmp_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3919 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3920 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3921 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3922 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3923 args = Py_BuildValue("(O)", other); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3924 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3925 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3926 else { |
| 19911 | 3927 res = PyObject_Call(func, args, NULL); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3928 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3929 } |
|
23967
1a8096bb4c48
Fix SF bug 572567: Memory leak in object comparison.
Raymond Hettinger <python@rcn.com>
parents:
23950
diff
changeset
|
3930 Py_DECREF(func); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3931 if (res != Py_NotImplemented) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3932 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3933 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3934 c = PyInt_AsLong(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3935 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3936 if (c == -1 && PyErr_Occurred()) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3937 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3938 return (c < 0) ? -1 : (c > 0) ? 1 : 0; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3939 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3940 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3941 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3942 return 2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3943 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3944 |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3945 /* This slot is published for the benefit of try_3way_compare in object.c */ |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3946 int |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3947 _PyObject_SlotCompare(PyObject *self, PyObject *other) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3948 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3949 int c; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3950 |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3951 if (self->ob_type->tp_compare == _PyObject_SlotCompare) { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3952 c = half_compare(self, other); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3953 if (c <= 1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3954 return c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3955 } |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3956 if (other->ob_type->tp_compare == _PyObject_SlotCompare) { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3957 c = half_compare(other, self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3958 if (c < -1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3959 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3960 if (c <= 1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3961 return -c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3962 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3963 return (void *)self < (void *)other ? -1 : |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3964 (void *)self > (void *)other ? 1 : 0; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3965 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3966 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3967 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3968 slot_tp_repr(PyObject *self) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3969 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3970 PyObject *func, *res; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3971 static PyObject *repr_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3972 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3973 func = lookup_method(self, "__repr__", &repr_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3974 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3975 res = PyEval_CallObject(func, NULL); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3976 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3977 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3978 } |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
3979 PyErr_Clear(); |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
3980 return PyString_FromFormat("<%s object at %p>", |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
3981 self->ob_type->tp_name, self); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3982 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3983 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3984 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3985 slot_tp_str(PyObject *self) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3986 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3987 PyObject *func, *res; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3988 static PyObject *str_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3989 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
3990 func = lookup_method(self, "__str__", &str_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3991 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3992 res = PyEval_CallObject(func, NULL); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3993 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3994 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3995 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3996 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3997 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3998 return slot_tp_repr(self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3999 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4000 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4001 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4002 static long |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4003 slot_tp_hash(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4004 { |
|
26559
0dbf98ee118e
slot_tp_hash(): In the normal path, this leaked a reference to the
Tim Peters <tim.peters@gmail.com>
parents:
26448
diff
changeset
|
4005 PyObject *func; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4006 static PyObject *hash_str, *eq_str, *cmp_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4007 long h; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4008 |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4009 func = lookup_method(self, "__hash__", &hash_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4010 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4011 if (func != NULL) { |
|
26559
0dbf98ee118e
slot_tp_hash(): In the normal path, this leaked a reference to the
Tim Peters <tim.peters@gmail.com>
parents:
26448
diff
changeset
|
4012 PyObject *res = PyEval_CallObject(func, NULL); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4013 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4014 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4015 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4016 h = PyInt_AsLong(res); |
|
26559
0dbf98ee118e
slot_tp_hash(): In the normal path, this leaked a reference to the
Tim Peters <tim.peters@gmail.com>
parents:
26448
diff
changeset
|
4017 Py_DECREF(res); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4018 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4019 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4020 PyErr_Clear(); |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4021 func = lookup_method(self, "__eq__", &eq_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4022 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4023 PyErr_Clear(); |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4024 func = lookup_method(self, "__cmp__", &cmp_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4025 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4026 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4027 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4028 PyErr_SetString(PyExc_TypeError, "unhashable type"); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4029 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4030 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4031 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4032 h = _Py_HashPointer((void *)self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4033 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4034 if (h == -1 && !PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4035 h = -2; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4036 return h; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4037 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4038 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4039 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4040 slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4041 { |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4042 static PyObject *call_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4043 PyObject *meth = lookup_method(self, "__call__", &call_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4044 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4045 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4046 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4047 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4048 res = PyObject_Call(meth, args, kwds); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4049 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4050 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4051 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4052 |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4053 /* There are two slot dispatch functions for tp_getattro. |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4054 |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4055 - slot_tp_getattro() is used when __getattribute__ is overridden |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4056 but no __getattr__ hook is present; |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4057 |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4058 - slot_tp_getattr_hook() is used when a __getattr__ hook is present. |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4059 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4060 The code in update_one_slot() always installs slot_tp_getattr_hook(); this |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4061 detects the absence of __getattr__ and then installs the simpler slot if |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4062 necessary. */ |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4063 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4064 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4065 slot_tp_getattro(PyObject *self, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4066 { |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4067 static PyObject *getattribute_str = NULL; |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4068 return call_method(self, "__getattribute__", &getattribute_str, |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4069 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4070 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4071 |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4072 static PyObject * |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4073 slot_tp_getattr_hook(PyObject *self, PyObject *name) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4074 { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4075 PyTypeObject *tp = self->ob_type; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4076 PyObject *getattr, *getattribute, *res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4077 static PyObject *getattribute_str = NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4078 static PyObject *getattr_str = NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4079 |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4080 if (getattr_str == NULL) { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4081 getattr_str = PyString_InternFromString("__getattr__"); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4082 if (getattr_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4083 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4084 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4085 if (getattribute_str == NULL) { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4086 getattribute_str = |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4087 PyString_InternFromString("__getattribute__"); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4088 if (getattribute_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4089 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4090 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4091 getattr = _PyType_Lookup(tp, getattr_str); |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4092 if (getattr == NULL) { |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4093 /* No __getattr__ hook: use a simpler dispatcher */ |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4094 tp->tp_getattro = slot_tp_getattro; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4095 return slot_tp_getattro(self, name); |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4096 } |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4097 getattribute = _PyType_Lookup(tp, getattribute_str); |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4098 if (getattribute == NULL || |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4099 (getattribute->ob_type == &PyWrapperDescr_Type && |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4100 ((PyWrapperDescrObject *)getattribute)->d_wrapped == |
|
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4101 (void *)PyObject_GenericGetAttr)) |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4102 res = PyObject_GenericGetAttr(self, name); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4103 else |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4104 res = PyObject_CallFunction(getattribute, "OO", self, name); |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4105 if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4106 PyErr_Clear(); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4107 res = PyObject_CallFunction(getattr, "OO", self, name); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4108 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4109 return res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4110 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4111 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4112 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4113 slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4114 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4115 PyObject *res; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4116 static PyObject *delattr_str, *setattr_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4117 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4118 if (value == NULL) |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4119 res = call_method(self, "__delattr__", &delattr_str, |
| 19911 | 4120 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4121 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4122 res = call_method(self, "__setattr__", &setattr_str, |
| 19911 | 4123 "(OO)", name, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4124 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4125 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4126 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4127 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4128 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4129 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4130 /* Map rich comparison operators to their __xx__ namesakes */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4131 static char *name_op[] = { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4132 "__lt__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4133 "__le__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4134 "__eq__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4135 "__ne__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4136 "__gt__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4137 "__ge__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4138 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4139 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4140 static PyObject * |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4141 half_richcompare(PyObject *self, PyObject *other, int op) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4142 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4143 PyObject *func, *args, *res; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4144 static PyObject *op_str[6]; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4145 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4146 func = lookup_method(self, name_op[op], &op_str[op]); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4147 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4148 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4149 Py_INCREF(Py_NotImplemented); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4150 return Py_NotImplemented; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4151 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4152 args = Py_BuildValue("(O)", other); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4153 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4154 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4155 else { |
| 19911 | 4156 res = PyObject_Call(func, args, NULL); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4157 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4158 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4159 Py_DECREF(func); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4160 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4161 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4162 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4163 /* Map rich comparison operators to their swapped version, e.g. LT --> GT */ |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4164 static int swapped_op[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE}; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4165 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4166 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4167 slot_tp_richcompare(PyObject *self, PyObject *other, int op) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4168 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4169 PyObject *res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4170 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4171 if (self->ob_type->tp_richcompare == slot_tp_richcompare) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4172 res = half_richcompare(self, other, op); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4173 if (res != Py_NotImplemented) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4174 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4175 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4176 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4177 if (other->ob_type->tp_richcompare == slot_tp_richcompare) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4178 res = half_richcompare(other, self, swapped_op[op]); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4179 if (res != Py_NotImplemented) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4180 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4181 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4182 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4183 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4184 Py_INCREF(Py_NotImplemented); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4185 return Py_NotImplemented; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4186 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4187 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4188 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4189 slot_tp_iter(PyObject *self) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4190 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4191 PyObject *func, *res; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4192 static PyObject *iter_str, *getitem_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4193 |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4194 func = lookup_method(self, "__iter__", &iter_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4195 if (func != NULL) { |
|
24867
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4196 PyObject *args; |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4197 args = res = PyTuple_New(0); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4198 if (args != NULL) { |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4199 res = PyObject_Call(func, args, NULL); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4200 Py_DECREF(args); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4201 } |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4202 Py_DECREF(func); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
4203 return res; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4204 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4205 PyErr_Clear(); |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4206 func = lookup_method(self, "__getitem__", &getitem_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4207 if (func == NULL) { |
|
22774
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
4208 PyErr_SetString(PyExc_TypeError, |
|
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
4209 "iteration over non-sequence"); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4210 return NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4211 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4212 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4213 return PySeqIter_New(self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4214 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4215 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4216 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4217 slot_tp_iternext(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4218 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4219 static PyObject *next_str; |
| 19911 | 4220 return call_method(self, "next", &next_str, "()"); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4221 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4222 |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4223 static PyObject * |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4224 slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4225 { |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4226 PyTypeObject *tp = self->ob_type; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4227 PyObject *get; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4228 static PyObject *get_str = NULL; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4229 |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4230 if (get_str == NULL) { |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4231 get_str = PyString_InternFromString("__get__"); |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4232 if (get_str == NULL) |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4233 return NULL; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4234 } |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4235 get = _PyType_Lookup(tp, get_str); |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4236 if (get == NULL) { |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4237 /* Avoid further slowdowns */ |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4238 if (tp->tp_descr_get == slot_tp_descr_get) |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4239 tp->tp_descr_get = NULL; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4240 Py_INCREF(self); |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4241 return self; |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4242 } |
|
19464
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4243 if (obj == NULL) |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4244 obj = Py_None; |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4245 if (type == NULL) |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4246 type = Py_None; |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4247 return PyObject_CallFunction(get, "OOO", self, obj, type); |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
4248 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4249 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4250 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4251 slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4252 { |
|
19464
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4253 PyObject *res; |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4254 static PyObject *del_str, *set_str; |
|
19464
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4255 |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4256 if (value == NULL) |
|
21142
842b280421ba
Fix for SF bug #485678.
Guido van Rossum <guido@python.org>
parents:
20978
diff
changeset
|
4257 res = call_method(self, "__delete__", &del_str, |
| 19911 | 4258 "(O)", target); |
|
19464
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
4259 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4260 res = call_method(self, "__set__", &set_str, |
| 19911 | 4261 "(OO)", target, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4262 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4263 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4264 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4265 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4266 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4267 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4268 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4269 slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4270 { |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4271 static PyObject *init_str; |
|
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
4272 PyObject *meth = lookup_method(self, "__init__", &init_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4273 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4274 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4275 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4276 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4277 res = PyObject_Call(meth, args, kwds); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4278 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4279 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4280 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4281 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4282 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4283 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4284 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4285 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4286 slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4287 { |
|
24680
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4288 static PyObject *new_str; |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4289 PyObject *func; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4290 PyObject *newargs, *x; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4291 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4292 |
|
24680
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4293 if (new_str == NULL) { |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4294 new_str = PyString_InternFromString("__new__"); |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4295 if (new_str == NULL) |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4296 return NULL; |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4297 } |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
4298 func = PyObject_GetAttr((PyObject *)type, new_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4299 if (func == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4300 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4301 assert(PyTuple_Check(args)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4302 n = PyTuple_GET_SIZE(args); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4303 newargs = PyTuple_New(n+1); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4304 if (newargs == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4305 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4306 Py_INCREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4307 PyTuple_SET_ITEM(newargs, 0, (PyObject *)type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4308 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4309 x = PyTuple_GET_ITEM(args, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4310 Py_INCREF(x); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4311 PyTuple_SET_ITEM(newargs, i+1, x); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4312 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4313 x = PyObject_Call(func, newargs, kwds); |
|
20195
3408d929bb94
slot_tp_new(): newargs was leaking.
Guido van Rossum <guido@python.org>
parents:
20190
diff
changeset
|
4314 Py_DECREF(newargs); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4315 Py_DECREF(func); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4316 return x; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4317 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4318 |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4319 static void |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4320 slot_tp_del(PyObject *self) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4321 { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4322 static PyObject *del_str = NULL; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4323 PyObject *del, *res; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4324 PyObject *error_type, *error_value, *error_traceback; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4325 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4326 /* Temporarily resurrect the object. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4327 assert(self->ob_refcnt == 0); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4328 self->ob_refcnt = 1; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4329 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4330 /* Save the current exception, if any. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4331 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4332 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4333 /* Execute __del__ method, if any. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4334 del = lookup_maybe(self, "__del__", &del_str); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4335 if (del != NULL) { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4336 res = PyEval_CallObject(del, NULL); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4337 if (res == NULL) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4338 PyErr_WriteUnraisable(del); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4339 else |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4340 Py_DECREF(res); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4341 Py_DECREF(del); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4342 } |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4343 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4344 /* Restore the saved exception. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4345 PyErr_Restore(error_type, error_value, error_traceback); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4346 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4347 /* Undo the temporary resurrection; can't use DECREF here, it would |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4348 * cause a recursive call. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4349 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4350 assert(self->ob_refcnt > 0); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4351 if (--self->ob_refcnt == 0) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4352 return; /* this is the normal path out */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4353 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4354 /* __del__ resurrected it! Make it look like the original Py_DECREF |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4355 * never happened. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4356 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4357 { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4358 int refcnt = self->ob_refcnt; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4359 _Py_NewReference(self); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4360 self->ob_refcnt = refcnt; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4361 } |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4362 assert(!PyType_IS_GC(self->ob_type) || |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4363 _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4364 /* If Py_REF_DEBUG, the original decref dropped _Py_RefTotal, but |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4365 * _Py_NewReference bumped it again, so that's a wash. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4366 * If Py_TRACE_REFS, _Py_NewReference re-added self to the object |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4367 * chain, so no more to do there either. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4368 * If COUNT_ALLOCS, the original decref bumped tp_frees, and |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4369 * _Py_NewReference bumped tp_allocs: both of those need to be |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4370 * undone. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4371 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4372 #ifdef COUNT_ALLOCS |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4373 --self->ob_type->tp_frees; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4374 --self->ob_type->tp_allocs; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4375 #endif |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4376 } |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4377 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4378 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4379 /* Table mapping __foo__ names to tp_foo offsets and slot_tp_foo wrapper |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4380 functions. The offsets here are relative to the 'etype' structure, which |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4381 incorporates the additional structures used for numbers, sequences and |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4382 mappings. Note that multiple names may map to the same slot (e.g. __eq__, |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4383 __ne__ etc. all map to tp_richcompare) and one name may map to multiple |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4384 slots (e.g. __str__ affects tp_str as well as tp_repr). The table is |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4385 terminated with an all-zero entry. (This table is further initialized and |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4386 sorted in init_slotdefs() below.) */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4387 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4388 typedef struct wrapperbase slotdef; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4389 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4390 #undef TPSLOT |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4391 #undef FLSLOT |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4392 #undef ETSLOT |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4393 #undef SQSLOT |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4394 #undef MPSLOT |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4395 #undef NBSLOT |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4396 #undef UNSLOT |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4397 #undef IBSLOT |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4398 #undef BINSLOT |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4399 #undef RBINSLOT |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4400 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4401 #define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
4402 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
4403 PyDoc_STR(DOC)} |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4404 #define FLSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, FLAGS) \ |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4405 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
4406 PyDoc_STR(DOC), FLAGS} |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4407 #define ETSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
4408 {NAME, offsetof(etype, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
4409 PyDoc_STR(DOC)} |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4410 #define SQSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4411 ETSLOT(NAME, as_sequence.SLOT, FUNCTION, WRAPPER, DOC) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4412 #define MPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4413 ETSLOT(NAME, as_mapping.SLOT, FUNCTION, WRAPPER, DOC) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4414 #define NBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4415 ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, DOC) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4416 #define UNSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4417 ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4418 "x." NAME "() <==> " DOC) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4419 #define IBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4420 ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4421 "x." NAME "(y) <==> x" DOC "y") |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4422 #define BINSLOT(NAME, SLOT, FUNCTION, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4423 ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4424 "x." NAME "(y) <==> x" DOC "y") |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4425 #define RBINSLOT(NAME, SLOT, FUNCTION, DOC) \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4426 ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4427 "x." NAME "(y) <==> y" DOC "x") |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4428 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4429 static slotdef slotdefs[] = { |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4430 SQSLOT("__len__", sq_length, slot_sq_length, wrap_inquiry, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4431 "x.__len__() <==> len(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4432 SQSLOT("__add__", sq_concat, slot_sq_concat, wrap_binaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4433 "x.__add__(y) <==> x+y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4434 SQSLOT("__mul__", sq_repeat, slot_sq_repeat, wrap_intargfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4435 "x.__mul__(n) <==> x*n"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4436 SQSLOT("__rmul__", sq_repeat, slot_sq_repeat, wrap_intargfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4437 "x.__rmul__(n) <==> n*x"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4438 SQSLOT("__getitem__", sq_item, slot_sq_item, wrap_sq_item, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4439 "x.__getitem__(y) <==> x[y]"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4440 SQSLOT("__getslice__", sq_slice, slot_sq_slice, wrap_intintargfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4441 "x.__getslice__(i, j) <==> x[i:j]"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4442 SQSLOT("__setitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_setitem, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4443 "x.__setitem__(i, y) <==> x[i]=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4444 SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4445 "x.__delitem__(y) <==> del x[y]"), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4446 SQSLOT("__setslice__", sq_ass_slice, slot_sq_ass_slice, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4447 wrap_intintobjargproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4448 "x.__setslice__(i, j, y) <==> x[i:j]=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4449 SQSLOT("__delslice__", sq_ass_slice, slot_sq_ass_slice, wrap_delslice, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4450 "x.__delslice__(i, j) <==> del x[i:j]"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4451 SQSLOT("__contains__", sq_contains, slot_sq_contains, wrap_objobjproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4452 "x.__contains__(y) <==> y in x"), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4453 SQSLOT("__iadd__", sq_inplace_concat, slot_sq_inplace_concat, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4454 wrap_binaryfunc, "x.__iadd__(y) <==> x+=y"), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4455 SQSLOT("__imul__", sq_inplace_repeat, slot_sq_inplace_repeat, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4456 wrap_intargfunc, "x.__imul__(y) <==> x*=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4457 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4458 MPSLOT("__len__", mp_length, slot_mp_length, wrap_inquiry, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4459 "x.__len__() <==> len(x)"), |
|
20345
67a7a99f2d5a
The slot definition table entry for mp_getitem had a bogus wrapper
Guido van Rossum <guido@python.org>
parents:
20343
diff
changeset
|
4460 MPSLOT("__getitem__", mp_subscript, slot_mp_subscript, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4461 wrap_binaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4462 "x.__getitem__(y) <==> x[y]"), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4463 MPSLOT("__setitem__", mp_ass_subscript, slot_mp_ass_subscript, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4464 wrap_objobjargproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4465 "x.__setitem__(i, y) <==> x[i]=y"), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4466 MPSLOT("__delitem__", mp_ass_subscript, slot_mp_ass_subscript, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4467 wrap_delitem, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4468 "x.__delitem__(y) <==> del x[y]"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4469 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4470 BINSLOT("__add__", nb_add, slot_nb_add, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4471 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4472 RBINSLOT("__radd__", nb_add, slot_nb_add, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4473 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4474 BINSLOT("__sub__", nb_subtract, slot_nb_subtract, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4475 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4476 RBINSLOT("__rsub__", nb_subtract, slot_nb_subtract, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4477 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4478 BINSLOT("__mul__", nb_multiply, slot_nb_multiply, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4479 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4480 RBINSLOT("__rmul__", nb_multiply, slot_nb_multiply, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4481 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4482 BINSLOT("__div__", nb_divide, slot_nb_divide, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4483 "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4484 RBINSLOT("__rdiv__", nb_divide, slot_nb_divide, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4485 "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4486 BINSLOT("__mod__", nb_remainder, slot_nb_remainder, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4487 "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4488 RBINSLOT("__rmod__", nb_remainder, slot_nb_remainder, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4489 "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4490 BINSLOT("__divmod__", nb_divmod, slot_nb_divmod, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4491 "divmod(x, y)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4492 RBINSLOT("__rdivmod__", nb_divmod, slot_nb_divmod, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4493 "divmod(y, x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4494 NBSLOT("__pow__", nb_power, slot_nb_power, wrap_ternaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4495 "x.__pow__(y[, z]) <==> pow(x, y[, z])"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4496 NBSLOT("__rpow__", nb_power, slot_nb_power, wrap_ternaryfunc_r, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4497 "y.__rpow__(x[, z]) <==> pow(x, y[, z])"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4498 UNSLOT("__neg__", nb_negative, slot_nb_negative, wrap_unaryfunc, "-x"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4499 UNSLOT("__pos__", nb_positive, slot_nb_positive, wrap_unaryfunc, "+x"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4500 UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4501 "abs(x)"), |
|
22230
fc4056b9cf18
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
21997
diff
changeset
|
4502 UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquiry, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4503 "x != 0"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4504 UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~x"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4505 BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4506 RBINSLOT("__rlshift__", nb_lshift, slot_nb_lshift, "<<"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4507 BINSLOT("__rshift__", nb_rshift, slot_nb_rshift, ">>"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4508 RBINSLOT("__rrshift__", nb_rshift, slot_nb_rshift, ">>"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4509 BINSLOT("__and__", nb_and, slot_nb_and, "&"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4510 RBINSLOT("__rand__", nb_and, slot_nb_and, "&"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4511 BINSLOT("__xor__", nb_xor, slot_nb_xor, "^"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4512 RBINSLOT("__rxor__", nb_xor, slot_nb_xor, "^"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4513 BINSLOT("__or__", nb_or, slot_nb_or, "|"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4514 RBINSLOT("__ror__", nb_or, slot_nb_or, "|"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4515 NBSLOT("__coerce__", nb_coerce, slot_nb_coerce, wrap_coercefunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4516 "x.__coerce__(y) <==> coerce(x, y)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4517 UNSLOT("__int__", nb_int, slot_nb_int, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4518 "int(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4519 UNSLOT("__long__", nb_long, slot_nb_long, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4520 "long(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4521 UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4522 "float(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4523 UNSLOT("__oct__", nb_oct, slot_nb_oct, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4524 "oct(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4525 UNSLOT("__hex__", nb_hex, slot_nb_hex, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4526 "hex(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4527 IBSLOT("__iadd__", nb_inplace_add, slot_nb_inplace_add, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4528 wrap_binaryfunc, "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4529 IBSLOT("__isub__", nb_inplace_subtract, slot_nb_inplace_subtract, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4530 wrap_binaryfunc, "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4531 IBSLOT("__imul__", nb_inplace_multiply, slot_nb_inplace_multiply, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4532 wrap_binaryfunc, "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4533 IBSLOT("__idiv__", nb_inplace_divide, slot_nb_inplace_divide, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4534 wrap_binaryfunc, "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4535 IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4536 wrap_binaryfunc, "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4537 IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power, |
|
25794
001b789f1f84
For some reason (probably cut and paste), __ipow__ for new-style
Guido van Rossum <guido@python.org>
parents:
25793
diff
changeset
|
4538 wrap_binaryfunc, "**"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4539 IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4540 wrap_binaryfunc, "<<"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4541 IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4542 wrap_binaryfunc, ">>"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4543 IBSLOT("__iand__", nb_inplace_and, slot_nb_inplace_and, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4544 wrap_binaryfunc, "&"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4545 IBSLOT("__ixor__", nb_inplace_xor, slot_nb_inplace_xor, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4546 wrap_binaryfunc, "^"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4547 IBSLOT("__ior__", nb_inplace_or, slot_nb_inplace_or, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4548 wrap_binaryfunc, "|"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4549 BINSLOT("__floordiv__", nb_floor_divide, slot_nb_floor_divide, "//"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4550 RBINSLOT("__rfloordiv__", nb_floor_divide, slot_nb_floor_divide, "//"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4551 BINSLOT("__truediv__", nb_true_divide, slot_nb_true_divide, "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4552 RBINSLOT("__rtruediv__", nb_true_divide, slot_nb_true_divide, "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4553 IBSLOT("__ifloordiv__", nb_inplace_floor_divide, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4554 slot_nb_inplace_floor_divide, wrap_binaryfunc, "//"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4555 IBSLOT("__itruediv__", nb_inplace_true_divide, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4556 slot_nb_inplace_true_divide, wrap_binaryfunc, "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4557 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4558 TPSLOT("__str__", tp_str, slot_tp_str, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4559 "x.__str__() <==> str(x)"), |
|
20737
00a581bdedeb
When overriding __str__ or __repr__, set the tp_print slot to NULL.
Guido van Rossum <guido@python.org>
parents:
20725
diff
changeset
|
4560 TPSLOT("__str__", tp_print, NULL, NULL, ""), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4561 TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4562 "x.__repr__() <==> repr(x)"), |
|
20737
00a581bdedeb
When overriding __str__ or __repr__, set the tp_print slot to NULL.
Guido van Rossum <guido@python.org>
parents:
20725
diff
changeset
|
4563 TPSLOT("__repr__", tp_print, NULL, NULL, ""), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4564 TPSLOT("__cmp__", tp_compare, _PyObject_SlotCompare, wrap_cmpfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4565 "x.__cmp__(y) <==> cmp(x,y)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4566 TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4567 "x.__hash__() <==> hash(x)"), |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4568 FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)wrap_call, |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4569 "x.__call__(...) <==> x(...)", PyWrapperFlag_KEYWORDS), |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4570 TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4571 wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4572 TPSLOT("__getattribute__", tp_getattr, NULL, NULL, ""), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4573 TPSLOT("__getattr__", tp_getattro, slot_tp_getattr_hook, NULL, ""), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4574 TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4575 TPSLOT("__setattr__", tp_setattro, slot_tp_setattro, wrap_setattr, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4576 "x.__setattr__('name', value) <==> x.name = value"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4577 TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4578 TPSLOT("__delattr__", tp_setattro, slot_tp_setattro, wrap_delattr, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4579 "x.__delattr__('name') <==> del x.name"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4580 TPSLOT("__delattr__", tp_setattr, NULL, NULL, ""), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4581 TPSLOT("__lt__", tp_richcompare, slot_tp_richcompare, richcmp_lt, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4582 "x.__lt__(y) <==> x<y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4583 TPSLOT("__le__", tp_richcompare, slot_tp_richcompare, richcmp_le, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4584 "x.__le__(y) <==> x<=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4585 TPSLOT("__eq__", tp_richcompare, slot_tp_richcompare, richcmp_eq, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4586 "x.__eq__(y) <==> x==y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4587 TPSLOT("__ne__", tp_richcompare, slot_tp_richcompare, richcmp_ne, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4588 "x.__ne__(y) <==> x!=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4589 TPSLOT("__gt__", tp_richcompare, slot_tp_richcompare, richcmp_gt, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4590 "x.__gt__(y) <==> x>y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4591 TPSLOT("__ge__", tp_richcompare, slot_tp_richcompare, richcmp_ge, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4592 "x.__ge__(y) <==> x>=y"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4593 TPSLOT("__iter__", tp_iter, slot_tp_iter, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4594 "x.__iter__() <==> iter(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4595 TPSLOT("next", tp_iternext, slot_tp_iternext, wrap_next, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4596 "x.next() -> the next value, or raise StopIteration"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4597 TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4598 "descr.__get__(obj[, type]) -> value"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4599 TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4600 "descr.__set__(obj, value)"), |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4601 TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set, |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4602 wrap_descr_delete, "descr.__delete__(obj)"), |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4603 FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)wrap_init, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4604 "x.__init__(...) initializes x; " |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4605 "see x.__class__.__doc__ for signature", |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4606 PyWrapperFlag_KEYWORDS), |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4607 TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""), |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
4608 TPSLOT("__del__", tp_del, slot_tp_del, NULL, ""), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4609 {NULL} |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4610 }; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4611 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4612 /* Given a type pointer and an offset gotten from a slotdef entry, return a |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4613 pointer to the actual slot. This is not quite the same as simply adding |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4614 the offset to the type pointer, since it takes care to indirect through the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4615 proper indirection pointer (as_buffer, etc.); it returns NULL if the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4616 indirection pointer is NULL. */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4617 static void ** |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4618 slotptr(PyTypeObject *type, int offset) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4619 { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4620 char *ptr; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4621 |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4622 /* Note: this depends on the order of the members of etype! */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4623 assert(offset >= 0); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4624 assert(offset < offsetof(etype, as_buffer)); |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4625 if (offset >= offsetof(etype, as_sequence)) { |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4626 ptr = (void *)type->tp_as_sequence; |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4627 offset -= offsetof(etype, as_sequence); |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4628 } |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4629 else if (offset >= offsetof(etype, as_mapping)) { |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4630 ptr = (void *)type->tp_as_mapping; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4631 offset -= offsetof(etype, as_mapping); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4632 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4633 else if (offset >= offsetof(etype, as_number)) { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4634 ptr = (void *)type->tp_as_number; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4635 offset -= offsetof(etype, as_number); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4636 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4637 else { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4638 ptr = (void *)type; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4639 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4640 if (ptr != NULL) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4641 ptr += offset; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4642 return (void **)ptr; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4643 } |
| 19036 | 4644 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4645 /* Length of array of slotdef pointers used to store slots with the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4646 same __name__. There should be at most MAX_EQUIV-1 slotdef entries with |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4647 the same __name__, for any __name__. Since that's a static property, it is |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4648 appropriate to declare fixed-size arrays for this. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4649 #define MAX_EQUIV 10 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4650 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4651 /* Return a slot pointer for a given name, but ONLY if the attribute has |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4652 exactly one slot function. The name must be an interned string. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4653 static void ** |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4654 resolve_slotdups(PyTypeObject *type, PyObject *name) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4655 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4656 /* XXX Maybe this could be optimized more -- but is it worth it? */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4657 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4658 /* pname and ptrs act as a little cache */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4659 static PyObject *pname; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4660 static slotdef *ptrs[MAX_EQUIV]; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4661 slotdef *p, **pp; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4662 void **res, **ptr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4663 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4664 if (pname != name) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4665 /* Collect all slotdefs that match name into ptrs. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4666 pname = name; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4667 pp = ptrs; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4668 for (p = slotdefs; p->name_strobj; p++) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4669 if (p->name_strobj == name) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4670 *pp++ = p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4671 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4672 *pp = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4673 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4674 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4675 /* Look in all matching slots of the type; if exactly one of these has |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4676 a filled-in slot, return its value. Otherwise return NULL. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4677 res = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4678 for (pp = ptrs; *pp; pp++) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4679 ptr = slotptr(type, (*pp)->offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4680 if (ptr == NULL || *ptr == NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4681 continue; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4682 if (res != NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4683 return NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4684 res = ptr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4685 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4686 return res; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4687 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4688 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4689 /* Common code for update_these_slots() and fixup_slot_dispatchers(). This |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4690 does some incredibly complex thinking and then sticks something into the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4691 slot. (It sees if the adjacent slotdefs for the same slot have conflicting |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4692 interests, and then stores a generic wrapper or a specific function into |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4693 the slot.) Return a pointer to the next slotdef with a different offset, |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4694 because that's convenient for fixup_slot_dispatchers(). */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4695 static slotdef * |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4696 update_one_slot(PyTypeObject *type, slotdef *p) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4697 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4698 PyObject *descr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4699 PyWrapperDescrObject *d; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4700 void *generic = NULL, *specific = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4701 int use_generic = 0; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4702 int offset = p->offset; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4703 void **ptr = slotptr(type, offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4704 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4705 if (ptr == NULL) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4706 do { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4707 ++p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4708 } while (p->offset == offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4709 return p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4710 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4711 do { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4712 descr = _PyType_Lookup(type, p->name_strobj); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4713 if (descr == NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4714 continue; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4715 if (descr->ob_type == &PyWrapperDescr_Type) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4716 void **tptr = resolve_slotdups(type, p->name_strobj); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4717 if (tptr == NULL || tptr == ptr) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4718 generic = p->function; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4719 d = (PyWrapperDescrObject *)descr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4720 if (d->d_base->wrapper == p->wrapper && |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4721 PyType_IsSubtype(type, d->d_type)) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4722 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4723 if (specific == NULL || |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4724 specific == d->d_wrapped) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4725 specific = d->d_wrapped; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4726 else |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4727 use_generic = 1; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4728 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4729 } |
|
24685
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4730 else if (descr->ob_type == &PyCFunction_Type && |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4731 PyCFunction_GET_FUNCTION(descr) == |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4732 (PyCFunction)tp_new_wrapper && |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4733 strcmp(p->name, "__new__") == 0) |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4734 { |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4735 /* The __new__ wrapper is not a wrapper descriptor, |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4736 so must be special-cased differently. |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4737 If we don't do this, creating an instance will |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4738 always use slot_tp_new which will look up |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4739 __new__ in the MRO which will call tp_new_wrapper |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4740 which will look through the base classes looking |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4741 for a static base and call its tp_new (usually |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4742 PyType_GenericNew), after performing various |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4743 sanity checks and constructing a new argument |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4744 list. Cut all that nonsense short -- this speeds |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4745 up instance creation tremendously. */ |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4746 specific = type->tp_new; |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4747 /* XXX I'm not 100% sure that there isn't a hole |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4748 in this reasoning that requires additional |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4749 sanity checks. I'll buy the first person to |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4750 point out a bug in this reasoning a beer. */ |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
4751 } |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4752 else { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4753 use_generic = 1; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4754 generic = p->function; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4755 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4756 } while ((++p)->offset == offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4757 if (specific && !use_generic) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4758 *ptr = specific; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4759 else |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4760 *ptr = generic; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4761 return p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4762 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4763 |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
4764 static int recurse_down_subclasses(PyTypeObject *type, slotdef **pp, |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
4765 PyObject *name); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4766 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4767 /* In the type, update the slots whose slotdefs are gathered in the pp0 array, |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4768 and then do the same for all this type's subtypes. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4769 static int |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4770 update_these_slots(PyTypeObject *type, slotdef **pp0, PyObject *name) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4771 { |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4772 slotdef **pp; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4773 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4774 for (pp = pp0; *pp; pp++) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4775 update_one_slot(type, *pp); |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4776 return recurse_down_subclasses(type, pp0, name); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4777 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4778 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4779 /* Update the slots whose slotdefs are gathered in the pp array in all (direct |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4780 or indirect) subclasses of type. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4781 static int |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4782 recurse_down_subclasses(PyTypeObject *type, slotdef **pp, PyObject *name) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4783 { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4784 PyTypeObject *subclass; |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4785 PyObject *ref, *subclasses, *dict; |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4786 int i, n; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4787 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4788 subclasses = type->tp_subclasses; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4789 if (subclasses == NULL) |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4790 return 0; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4791 assert(PyList_Check(subclasses)); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4792 n = PyList_GET_SIZE(subclasses); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4793 for (i = 0; i < n; i++) { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4794 ref = PyList_GET_ITEM(subclasses, i); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4795 assert(PyWeakref_CheckRef(ref)); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4796 subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref); |
|
23856
868cfbdca909
Inexplicably, recurse_down_subclasses() was comparing the object
Guido van Rossum <guido@python.org>
parents:
23832
diff
changeset
|
4797 assert(subclass != NULL); |
|
868cfbdca909
Inexplicably, recurse_down_subclasses() was comparing the object
Guido van Rossum <guido@python.org>
parents:
23832
diff
changeset
|
4798 if ((PyObject *)subclass == Py_None) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4799 continue; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4800 assert(PyType_Check(subclass)); |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4801 /* Avoid recursing down into unaffected classes */ |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4802 dict = subclass->tp_dict; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4803 if (dict != NULL && PyDict_Check(dict) && |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4804 PyDict_GetItem(dict, name) != NULL) |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4805 continue; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4806 if (update_these_slots(subclass, pp, name) < 0) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4807 return -1; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4808 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4809 return 0; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4810 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4811 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4812 /* Comparison function for qsort() to compare slotdefs by their offset, and |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4813 for equal offset by their address (to force a stable sort). */ |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4814 static int |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4815 slotdef_cmp(const void *aa, const void *bb) |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4816 { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4817 const slotdef *a = (const slotdef *)aa, *b = (const slotdef *)bb; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4818 int c = a->offset - b->offset; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4819 if (c != 0) |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4820 return c; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4821 else |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4822 return a - b; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4823 } |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4824 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4825 /* Initialize the slotdefs table by adding interned string objects for the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4826 names and sorting the entries. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4827 static void |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4828 init_slotdefs(void) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4829 { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4830 slotdef *p; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4831 static int initialized = 0; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4832 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4833 if (initialized) |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4834 return; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4835 for (p = slotdefs; p->name; p++) { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4836 p->name_strobj = PyString_InternFromString(p->name); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4837 if (!p->name_strobj) |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4838 Py_FatalError("Out of memory interning slotdef names"); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4839 } |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4840 qsort((void *)slotdefs, (size_t)(p-slotdefs), sizeof(slotdef), |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4841 slotdef_cmp); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4842 initialized = 1; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4843 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4844 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4845 /* Update the slots after assignment to a class (type) attribute. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4846 static int |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4847 update_slot(PyTypeObject *type, PyObject *name) |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4848 { |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4849 slotdef *ptrs[MAX_EQUIV]; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4850 slotdef *p; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4851 slotdef **pp; |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4852 int offset; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4853 |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4854 init_slotdefs(); |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4855 pp = ptrs; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4856 for (p = slotdefs; p->name; p++) { |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4857 /* XXX assume name is interned! */ |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4858 if (p->name_strobj == name) |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4859 *pp++ = p; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4860 } |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4861 *pp = NULL; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4862 for (pp = ptrs; *pp; pp++) { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4863 p = *pp; |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4864 offset = p->offset; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4865 while (p > slotdefs && (p-1)->offset == offset) |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4866 --p; |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4867 *pp = p; |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4868 } |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4869 if (ptrs[0] == NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4870 return 0; /* Not an attribute that affects any slots */ |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
4871 return update_these_slots(type, ptrs, name); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4872 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
4873 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4874 /* Store the proper functions in the slot dispatches at class (type) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4875 definition time, based upon which operations the class overrides in its |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4876 dict. */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4877 static void |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4878 fixup_slot_dispatchers(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4879 { |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
4880 slotdef *p; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4881 |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
4882 init_slotdefs(); |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4883 for (p = slotdefs; p->name; ) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4884 p = update_one_slot(type, p); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4885 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4886 |
| 26421 | 4887 static void |
| 4888 update_all_slots(PyTypeObject* type) | |
| 4889 { | |
| 4890 slotdef *p; | |
| 4891 | |
| 4892 init_slotdefs(); | |
| 4893 for (p = slotdefs; p->name; p++) { | |
| 4894 /* update_slot returns int but can't actually fail */ | |
| 4895 update_slot(type, p->name_strobj); | |
| 4896 } | |
| 4897 } | |
| 4898 | |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4899 /* This function is called by PyType_Ready() to populate the type's |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4900 dictionary with method descriptors for function slots. For each |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4901 function slot (like tp_repr) that's defined in the type, one or more |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4902 corresponding descriptors are added in the type's tp_dict dictionary |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4903 under the appropriate name (like __repr__). Some function slots |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4904 cause more than one descriptor to be added (for example, the nb_add |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4905 slot adds both __add__ and __radd__ descriptors) and some function |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4906 slots compete for the same descriptor (for example both sq_item and |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4907 mp_subscript generate a __getitem__ descriptor). |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4908 |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4909 In the latter case, the first slotdef entry encoutered wins. Since |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4910 slotdef entries are sorted by the offset of the slot in the etype |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4911 struct, this gives us some control over disambiguating between |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4912 competing slots: the members of struct etype are listed from most |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4913 general to least general, so the most general slot is preferred. In |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4914 particular, because as_mapping comes before as_sequence, for a type |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4915 that defines both mp_subscript and sq_item, mp_subscript wins. |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4916 |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4917 This only adds new descriptors and doesn't overwrite entries in |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4918 tp_dict that were previously defined. The descriptors contain a |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4919 reference to the C function they must call, so that it's safe if they |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4920 are copied into a subtype's __dict__ and the subtype has a different |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4921 C function in its slot -- calling the method defined by the |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4922 descriptor will call the C function that was used to create it, |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4923 rather than the C function present in the slot when it is called. |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4924 (This is important because a subtype may have a C function in the |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4925 slot that calls the method from the dictionary, and we want to avoid |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
4926 infinite recursion here.) */ |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4927 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4928 static int |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4929 add_operators(PyTypeObject *type) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4930 { |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4931 PyObject *dict = type->tp_dict; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4932 slotdef *p; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4933 PyObject *descr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4934 void **ptr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4935 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4936 init_slotdefs(); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4937 for (p = slotdefs; p->name; p++) { |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4938 if (p->wrapper == NULL) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4939 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4940 ptr = slotptr(type, p->offset); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4941 if (!ptr || !*ptr) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4942 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4943 if (PyDict_GetItem(dict, p->name_strobj)) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4944 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4945 descr = PyDescr_NewWrapper(type, p, *ptr); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4946 if (descr == NULL) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4947 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4948 if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4949 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4950 Py_DECREF(descr); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4951 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4952 if (type->tp_new != NULL) { |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4953 if (add_tp_new_wrapper(type) < 0) |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4954 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4955 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4956 return 0; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4957 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
4958 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4959 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4960 /* Cooperative 'super' */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4961 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4962 typedef struct { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4963 PyObject_HEAD |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
4964 PyTypeObject *type; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4965 PyObject *obj; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4966 } superobject; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4967 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
4968 static PyMemberDef super_members[] = { |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
4969 {"__thisclass__", T_OBJECT, offsetof(superobject, type), READONLY, |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
4970 "the class invoking super()"}, |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
4971 {"__self__", T_OBJECT, offsetof(superobject, obj), READONLY, |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
4972 "the instance invoking super(); may be None"}, |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4973 {0} |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4974 }; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4975 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4976 static void |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4977 super_dealloc(PyObject *self) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4978 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4979 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4980 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4981 _PyObject_GC_UNTRACK(self); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4982 Py_XDECREF(su->obj); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4983 Py_XDECREF(su->type); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4984 self->ob_type->tp_free(self); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4985 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4986 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4987 static PyObject * |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4988 super_repr(PyObject *self) |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4989 { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4990 superobject *su = (superobject *)self; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4991 |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4992 if (su->obj) |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4993 return PyString_FromFormat( |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
4994 "<super: <class '%s'>, <%s object>>", |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4995 su->type ? su->type->tp_name : "NULL", |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4996 su->obj->ob_type->tp_name); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4997 else |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
4998 return PyString_FromFormat( |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
4999 "<super: <class '%s'>, NULL>", |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5000 su->type ? su->type->tp_name : "NULL"); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5001 } |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5002 |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5003 static PyObject * |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5004 super_getattro(PyObject *self, PyObject *name) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5005 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5006 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5007 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5008 if (su->obj != NULL) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5009 PyObject *mro, *res, *tmp, *dict; |
|
22770
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5010 PyTypeObject *starttype; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5011 descrgetfunc f; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5012 int i, n; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5013 |
|
22770
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5014 starttype = su->obj->ob_type; |
|
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5015 mro = starttype->tp_mro; |
|
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5016 |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5017 if (mro == NULL) |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5018 n = 0; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5019 else { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5020 assert(PyTuple_Check(mro)); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5021 n = PyTuple_GET_SIZE(mro); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5022 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5023 for (i = 0; i < n; i++) { |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5024 if ((PyObject *)(su->type) == PyTuple_GET_ITEM(mro, i)) |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5025 break; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5026 } |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5027 if (i >= n && PyType_Check(su->obj)) { |
|
22770
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5028 starttype = (PyTypeObject *)(su->obj); |
|
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5029 mro = starttype->tp_mro; |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5030 if (mro == NULL) |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5031 n = 0; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5032 else { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5033 assert(PyTuple_Check(mro)); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5034 n = PyTuple_GET_SIZE(mro); |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5035 } |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5036 for (i = 0; i < n; i++) { |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5037 if ((PyObject *)(su->type) == |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5038 PyTuple_GET_ITEM(mro, i)) |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5039 break; |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5040 } |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5041 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5042 i++; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5043 res = NULL; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5044 for (; i < n; i++) { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5045 tmp = PyTuple_GET_ITEM(mro, i); |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5046 if (PyType_Check(tmp)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5047 dict = ((PyTypeObject *)tmp)->tp_dict; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5048 else if (PyClass_Check(tmp)) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5049 dict = ((PyClassObject *)tmp)->cl_dict; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5050 else |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5051 continue; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5052 res = PyDict_GetItem(dict, name); |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5053 if (res != NULL && !PyDescr_IsData(res)) { |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5054 Py_INCREF(res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5055 f = res->ob_type->tp_descr_get; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5056 if (f != NULL) { |
|
22774
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
5057 tmp = f(res, su->obj, |
|
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
5058 (PyObject *)starttype); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5059 Py_DECREF(res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5060 res = tmp; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5061 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5062 return res; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5063 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5064 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5065 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5066 return PyObject_GenericGetAttr(self, name); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5067 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5068 |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5069 static int |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5070 supercheck(PyTypeObject *type, PyObject *obj) |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5071 { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5072 if (!PyType_IsSubtype(obj->ob_type, type) && |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5073 !(PyType_Check(obj) && |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5074 PyType_IsSubtype((PyTypeObject *)obj, type))) { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5075 PyErr_SetString(PyExc_TypeError, |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5076 "super(type, obj): " |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5077 "obj must be an instance or subtype of type"); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5078 return -1; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5079 } |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5080 else |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5081 return 0; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5082 } |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5083 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5084 static PyObject * |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5085 super_descr_get(PyObject *self, PyObject *obj, PyObject *type) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5086 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5087 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5088 superobject *new; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5089 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5090 if (obj == NULL || obj == Py_None || su->obj != NULL) { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5091 /* Not binding to an object, or already bound */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5092 Py_INCREF(self); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5093 return self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5094 } |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5095 if (su->ob_type != &PySuper_Type) |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5096 /* If su is an instance of a subclass of super, |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5097 call its type */ |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5098 return PyObject_CallFunction((PyObject *)su->ob_type, |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5099 "OO", su->type, obj); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5100 else { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5101 /* Inline the common case */ |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5102 if (supercheck(su->type, obj) < 0) |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5103 return NULL; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5104 new = (superobject *)PySuper_Type.tp_new(&PySuper_Type, |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5105 NULL, NULL); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5106 if (new == NULL) |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5107 return NULL; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5108 Py_INCREF(su->type); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5109 Py_INCREF(obj); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5110 new->type = su->type; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5111 new->obj = obj; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5112 return (PyObject *)new; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5113 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5114 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5115 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5116 static int |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5117 super_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5118 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5119 superobject *su = (superobject *)self; |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5120 PyTypeObject *type; |
|
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5121 PyObject *obj = NULL; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5122 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5123 if (!PyArg_ParseTuple(args, "O!|O:super", &PyType_Type, &type, &obj)) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5124 return -1; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5125 if (obj == Py_None) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5126 obj = NULL; |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
5127 if (obj != NULL && supercheck(type, obj) < 0) |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5128 return -1; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5129 Py_INCREF(type); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5130 Py_XINCREF(obj); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5131 su->type = type; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5132 su->obj = obj; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5133 return 0; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5134 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5135 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
5136 PyDoc_STRVAR(super_doc, |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5137 "super(type) -> unbound super object\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5138 "super(type, obj) -> bound super object; requires isinstance(obj, type)\n" |
|
19551
01a6901cd305
Fix super() so that it is usable for static methods (like __new__) as well.
Guido van Rossum <guido@python.org>
parents:
19540
diff
changeset
|
5139 "super(type, type2) -> bound super object; requires issubclass(type2, type)\n" |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5140 "Typical use to call a cooperative superclass method:\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5141 "class C(B):\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5142 " def meth(self, arg):\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
5143 " super(C, self).meth(arg)"); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5144 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5145 static int |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5146 super_traverse(PyObject *self, visitproc visit, void *arg) |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5147 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5148 superobject *su = (superobject *)self; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5149 int err; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5150 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5151 #define VISIT(SLOT) \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5152 if (SLOT) { \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5153 err = visit((PyObject *)(SLOT), arg); \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5154 if (err) \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5155 return err; \ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5156 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5157 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5158 VISIT(su->obj); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5159 VISIT(su->type); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5160 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5161 #undef VISIT |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5162 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5163 return 0; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5164 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5165 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5166 PyTypeObject PySuper_Type = { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5167 PyObject_HEAD_INIT(&PyType_Type) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5168 0, /* ob_size */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5169 "super", /* tp_name */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5170 sizeof(superobject), /* tp_basicsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5171 0, /* tp_itemsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5172 /* methods */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5173 super_dealloc, /* tp_dealloc */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5174 0, /* tp_print */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5175 0, /* tp_getattr */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5176 0, /* tp_setattr */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5177 0, /* tp_compare */ |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5178 super_repr, /* tp_repr */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5179 0, /* tp_as_number */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5180 0, /* tp_as_sequence */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5181 0, /* tp_as_mapping */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5182 0, /* tp_hash */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5183 0, /* tp_call */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5184 0, /* tp_str */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5185 super_getattro, /* tp_getattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5186 0, /* tp_setattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5187 0, /* tp_as_buffer */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5188 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5189 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5190 super_doc, /* tp_doc */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5191 super_traverse, /* tp_traverse */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5192 0, /* tp_clear */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5193 0, /* tp_richcompare */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5194 0, /* tp_weaklistoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5195 0, /* tp_iter */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5196 0, /* tp_iternext */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5197 0, /* tp_methods */ |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5198 super_members, /* tp_members */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5199 0, /* tp_getset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5200 0, /* tp_base */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5201 0, /* tp_dict */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5202 super_descr_get, /* tp_descr_get */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5203 0, /* tp_descr_set */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5204 0, /* tp_dictoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5205 super_init, /* tp_init */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5206 PyType_GenericAlloc, /* tp_alloc */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5207 PyType_GenericNew, /* tp_new */ |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
5208 PyObject_GC_Del, /* tp_free */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5209 }; |
