Mercurial > cpython-lru_cache-weakref
annotate Objects/typeobject.c @ 22194:fc6dc2ea25cf legacy-trunk
Fix leak of NotImplemented in previous checkin to PyNumber_Add().
If result == Py_NotImplemented, always DECREF it before assigning a
new value to result.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 08 Mar 2002 21:28:54 +0000 |
| parents | cb5b4a54ff12 |
| children | fc4056b9cf18 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Type object implementation */ |
| 3 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5 #include "structmember.h" |
| 6 | 6 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
7 static PyMemberDef type_members[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
8 {"__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
|
9 {"__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
|
10 {"__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
|
11 {"__weakrefoffset__", T_LONG, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
12 offsetof(PyTypeObject, tp_weaklistoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
13 {"__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
|
14 {"__dictoffset__", T_LONG, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
15 offsetof(PyTypeObject, tp_dictoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
16 {"__bases__", T_OBJECT, offsetof(PyTypeObject, tp_bases), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
17 {"__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
|
18 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
19 }; |
| 6 | 20 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
21 static PyObject * |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
22 type_name(PyTypeObject *type, void *context) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
23 { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
24 char *s; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
25 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
26 s = strrchr(type->tp_name, '.'); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
27 if (s == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
28 s = type->tp_name; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
29 else |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
30 s++; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
31 return PyString_FromString(s); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
32 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
33 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
34 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
35 type_module(PyTypeObject *type, void *context) |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
36 { |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
37 PyObject *mod; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
38 char *s; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
39 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
40 s = strrchr(type->tp_name, '.'); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
41 if (s != NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
42 return PyString_FromStringAndSize(type->tp_name, |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
43 (int)(s - type->tp_name)); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
44 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
45 return PyString_FromString("__builtin__"); |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
46 mod = PyDict_GetItemString(type->tp_dict, "__module__"); |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
47 if (mod != NULL && PyString_Check(mod)) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
48 Py_INCREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
49 return mod; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
50 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
51 PyErr_SetString(PyExc_AttributeError, "__module__"); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
52 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
53 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
54 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
55 static int |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
56 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
|
57 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
58 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
|
59 strrchr(type->tp_name, '.')) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
60 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
61 "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
|
62 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
63 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
64 if (!value) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
65 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
66 "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
|
67 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
68 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
69 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
|
70 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
71 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
72 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
73 type_dict(PyTypeObject *type, void *context) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
74 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
75 if (type->tp_dict == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
76 Py_INCREF(Py_None); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
77 return Py_None; |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
78 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
79 return PyDictProxy_New(type->tp_dict); |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
80 } |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
81 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
82 static PyGetSetDef type_getsets[] = { |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
83 {"__name__", (getter)type_name, NULL, NULL}, |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
84 {"__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
|
85 {"__dict__", (getter)type_dict, NULL, NULL}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
86 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
87 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
88 |
|
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
|
89 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
|
90 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
|
91 { |
|
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
|
92 /* 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 } |
|
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
|
98 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
99 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
100 type_repr(PyTypeObject *type) |
| 6 | 101 { |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
102 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
|
103 char *kind; |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
104 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
105 mod = type_module(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
106 if (mod == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
107 PyErr_Clear(); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
108 else if (!PyString_Check(mod)) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
109 Py_DECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
110 mod = NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
111 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
112 name = type_name(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
113 if (name == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
114 return NULL; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
115 |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
116 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
|
117 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
|
118 else |
|
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
119 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
|
120 |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
121 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
|
122 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
|
123 kind, |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
124 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
|
125 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
|
126 } |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
127 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
|
128 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
|
129 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
130 Py_XDECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
131 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
|
132 return rtn; |
| 6 | 133 } |
| 134 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
135 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
136 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
|
137 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
138 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
139 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
140 if (type->tp_new == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
141 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
142 "cannot create '%.100s' instances", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
143 type->tp_name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
144 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
145 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
146 |
|
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
|
147 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
|
148 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
|
149 /* 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
|
150 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
|
151 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
|
152 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
|
153 (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
|
154 (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
|
155 return obj; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
156 type = obj->ob_type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
157 if (type->tp_init != NULL && |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
158 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
|
159 Py_DECREF(obj); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
160 obj = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
161 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
162 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
163 return obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
164 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
165 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
166 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
167 PyType_GenericAlloc(PyTypeObject *type, int nitems) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
168 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
169 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
|
170 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
|
171 |
|
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
172 if (PyType_IS_GC(type)) |
|
20294
426b379a138b
_PyObject_VAR_SIZE: always round up to a multiple-of-pointer-size value.
Tim Peters <tim.peters@gmail.com>
parents:
20293
diff
changeset
|
173 obj = _PyObject_GC_Malloc(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
|
174 else |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
175 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
|
176 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
177 if (obj == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
178 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
|
179 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
180 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
|
181 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
182 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
|
183 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
|
184 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
185 if (type->tp_itemsize == 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
186 PyObject_INIT(obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
187 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
188 (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
|
189 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
190 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
|
191 _PyObject_GC_TRACK(obj); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
192 return obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
193 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
194 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
195 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
196 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
|
197 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
198 return type->tp_alloc(type, 0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
199 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
200 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
201 /* 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
|
202 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
203 static int |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
204 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
|
205 { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
206 PyTypeObject *type, *base; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
207 traverseproc f; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
208 int err; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
209 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
210 /* Find the nearest base with a different tp_traverse */ |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
211 type = self->ob_type; |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
212 base = type->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
|
213 while ((f = base->tp_traverse) == subtype_traverse) { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
214 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
|
215 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
|
216 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
217 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
218 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
|
219 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
|
220 if (dictptr && *dictptr) { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
221 err = visit(*dictptr, arg); |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
222 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
|
223 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
|
224 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
225 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
226 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
227 if (f) |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
228 return f(self, visit, arg); |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
229 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
|
230 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
231 |
|
20753
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
232 staticforward PyObject *lookup_maybe(PyObject *, char *, PyObject **); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
233 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
234 static int |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
235 call_finalizer(PyObject *self) |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
236 { |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
237 static PyObject *del_str = NULL; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
238 PyObject *del, *res; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
239 PyObject *error_type, *error_value, *error_traceback; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
240 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
241 /* Temporarily resurrect the object. */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
242 #ifdef Py_TRACE_REFS |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
243 #ifndef Py_REF_DEBUG |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
244 # error "Py_TRACE_REFS defined but Py_REF_DEBUG not." |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
245 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
246 /* much too complicated if Py_TRACE_REFS defined */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
247 _Py_NewReference((PyObject *)self); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
248 #ifdef COUNT_ALLOCS |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
249 /* compensate for boost in _Py_NewReference; note that |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
250 * _Py_RefTotal was also boosted; we'll knock that down later. |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
251 */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
252 self->ob_type->tp_allocs--; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
253 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
254 #else /* !Py_TRACE_REFS */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
255 /* Py_INCREF boosts _Py_RefTotal if Py_REF_DEBUG is defined */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
256 Py_INCREF(self); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
257 #endif /* !Py_TRACE_REFS */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
258 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
259 /* Save the current exception, if any. */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
260 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
261 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
262 /* Execute __del__ method, if any. */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
263 del = lookup_maybe(self, "__del__", &del_str); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
264 if (del != NULL) { |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
265 res = PyEval_CallObject(del, NULL); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
266 if (res == NULL) |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
267 PyErr_WriteUnraisable(del); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
268 else |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
269 Py_DECREF(res); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
270 Py_DECREF(del); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
271 } |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
272 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
273 /* Restore the saved exception. */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
274 PyErr_Restore(error_type, error_value, error_traceback); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
275 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
276 /* Undo the temporary resurrection; can't use DECREF here, it would |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
277 * cause a recursive call. |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
278 */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
279 #ifdef Py_REF_DEBUG |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
280 /* _Py_RefTotal was boosted either by _Py_NewReference or |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
281 * Py_INCREF above. |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
282 */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
283 _Py_RefTotal--; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
284 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
285 if (--self->ob_refcnt > 0) { |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
286 #ifdef COUNT_ALLOCS |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
287 self->ob_type->tp_frees--; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
288 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
289 _PyObject_GC_TRACK(self); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
290 return -1; /* __del__ added a reference; don't delete now */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
291 } |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
292 #ifdef Py_TRACE_REFS |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
293 _Py_ForgetReference((PyObject *)self); |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
294 #ifdef COUNT_ALLOCS |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
295 /* compensate for increment in _Py_ForgetReference */ |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
296 self->ob_type->tp_frees--; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
297 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
298 #endif |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
299 |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
300 return 0; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
301 } |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
302 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
303 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
304 subtype_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
305 { |
|
21246
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
306 PyTypeObject *type, *base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
307 destructor f; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
308 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
309 /* This exists so we can DECREF self->ob_type */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
310 |
|
20753
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
311 if (call_finalizer(self) < 0) |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
312 return; |
|
ecd64931482c
Add __del__ callbacks. They are too useful to leave out.
Guido van Rossum <guido@python.org>
parents:
20737
diff
changeset
|
313 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
314 /* Find the nearest base with a different tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
315 type = self->ob_type; |
|
21246
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
316 base = type->tp_base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
317 while ((f = base->tp_dealloc) == subtype_dealloc) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
318 base = base->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
319 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
|
320 } |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
321 |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
322 /* Clear __slots__ variables */ |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
323 if (type->tp_basicsize != base->tp_basicsize && |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
324 type->tp_itemsize == 0) |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
325 { |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
326 char *addr = ((char *)self); |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
327 char *p = addr + base->tp_basicsize; |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
328 char *q = addr + type->tp_basicsize; |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
329 for (; p < q; p += sizeof(PyObject *)) { |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
330 PyObject **pp; |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
331 if (p == addr + type->tp_dictoffset || |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
332 p == addr + type->tp_weaklistoffset) |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
333 continue; |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
334 pp = (PyObject **)p; |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
335 if (*pp != NULL) { |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
336 Py_DECREF(*pp); |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
337 *pp = NULL; |
|
21242
5c0ba6ebc62d
Fix SF bug #489581: __slots__ leak.
Guido van Rossum <guido@python.org>
parents:
21235
diff
changeset
|
338 } |
|
5c0ba6ebc62d
Fix SF bug #489581: __slots__ leak.
Guido van Rossum <guido@python.org>
parents:
21235
diff
changeset
|
339 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
340 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
341 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
342 /* 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 *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
|
350 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
351 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
352 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
353 |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
354 /* 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
|
355 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
|
356 PyObject_ClearWeakRefs(self); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
357 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
358 /* Finalize GC if the base doesn't do GC and we do */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
359 if (PyType_IS_GC(type) && !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
|
360 _PyObject_GC_UNTRACK(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
361 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
362 /* Call the base tp_dealloc() */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
363 assert(f); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
364 f(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
365 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
366 /* Can't reference self beyond this point */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
367 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
|
368 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
369 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
370 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
371 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
372 staticforward PyTypeObject *solid_base(PyTypeObject *type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
373 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
374 typedef struct { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
375 PyTypeObject type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
376 PyNumberMethods as_number; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
377 PySequenceMethods as_sequence; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
378 PyMappingMethods as_mapping; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
379 PyBufferProcs as_buffer; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
380 PyObject *name, *slots; |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
381 PyMemberDef members[1]; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
382 } etype; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
383 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
384 /* type test with subclassing support */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
385 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
386 int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
387 PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
388 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
389 PyObject *mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
390 |
|
19803
32cfce4d83dc
PyType_IsSubtype(): test tp_flags for HAVE_CLASS bit before accessing
Guido van Rossum <guido@python.org>
parents:
19630
diff
changeset
|
391 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
|
392 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
|
393 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
394 mro = a->tp_mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
395 if (mro != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
396 /* Deal with multiple inheritance without recursion |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
397 by walking the MRO tuple */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
398 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
399 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
400 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
401 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
402 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
|
403 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
404 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
405 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
406 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
407 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
408 /* 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
|
409 do { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
410 if (a == b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
411 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
412 a = a->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
413 } while (a != NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
414 return b == &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
415 } |
|
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 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
418 /* 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
|
419 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
|
420 (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
|
421 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
|
422 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
|
423 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
|
424 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
425 Two variants: |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
426 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
427 - 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
|
428 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
|
429 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
430 - 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
|
431 */ |
|
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
|
432 |
|
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
|
433 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
434 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
|
435 { |
|
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
|
436 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
|
437 |
|
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
|
438 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
|
439 *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
|
440 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
|
441 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
|
442 } |
|
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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 } |
|
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
|
451 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
|
452 } |
|
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
|
453 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
454 static PyObject * |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
455 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
|
456 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
457 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
|
458 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
|
459 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
|
460 return res; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
461 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
462 |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
463 /* 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
|
464 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
|
465 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
|
466 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
467 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
|
468 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
|
469 { |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
470 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
|
471 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
|
472 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
|
473 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
474 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
|
475 if (func == NULL) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
476 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
477 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
|
478 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
|
479 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
480 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
481 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
482 if (format && *format) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
483 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
|
484 else |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
485 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
|
486 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
487 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
488 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
489 if (args == NULL) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
490 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
491 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
492 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
|
493 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
|
494 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
495 Py_DECREF(args); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
496 Py_DECREF(func); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
497 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
498 return retval; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
499 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
500 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
501 /* 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
|
502 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
503 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
504 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
|
505 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
506 va_list va; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
507 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
|
508 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
|
509 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 if (!PyErr_Occurred()) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
514 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
|
515 return Py_NotImplemented; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
516 } |
| 19911 | 517 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
|
518 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
519 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
520 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
|
521 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
|
522 else |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
523 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
|
524 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
525 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
|
526 |
| 19911 | 527 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
|
528 return NULL; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
529 |
| 19911 | 530 assert(PyTuple_Check(args)); |
| 531 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
|
532 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
533 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
|
534 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
|
535 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
536 return retval; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
537 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
538 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
539 /* Method resolution order algorithm from "Putting Metaclasses to Work" |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
540 by Forman and Danforth (Addison-Wesley 1999). */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
541 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
542 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
543 conservative_merge(PyObject *left, PyObject *right) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
544 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
545 int left_size; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
546 int right_size; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
547 int i, j, r, ok; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
548 PyObject *temp, *rr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
549 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
550 assert(PyList_Check(left)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
551 assert(PyList_Check(right)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
552 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
553 again: |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
554 left_size = PyList_GET_SIZE(left); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
555 right_size = PyList_GET_SIZE(right); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
556 for (i = 0; i < left_size; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
557 for (j = 0; j < right_size; j++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
558 if (PyList_GET_ITEM(left, i) == |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
559 PyList_GET_ITEM(right, j)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
560 /* found a merge point */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
561 temp = PyList_New(0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
562 if (temp == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
563 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
564 for (r = 0; r < j; r++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
565 rr = PyList_GET_ITEM(right, r); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
566 ok = PySequence_Contains(left, rr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
567 if (ok < 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
568 Py_DECREF(temp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
569 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
570 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
571 if (!ok) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
572 ok = PyList_Append(temp, rr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
573 if (ok < 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
574 Py_DECREF(temp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
575 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
576 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
577 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
578 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
579 ok = PyList_SetSlice(left, i, i, temp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
580 Py_DECREF(temp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
581 if (ok < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
582 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
583 ok = PyList_SetSlice(right, 0, j+1, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
584 if (ok < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
585 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
586 goto again; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
587 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
588 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
589 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
590 return PyList_SetSlice(left, left_size, left_size, right); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
591 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
592 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
593 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
594 serious_order_disagreements(PyObject *left, PyObject *right) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
595 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
596 return 0; /* XXX later -- for now, we cheat: "don't do that" */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
597 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
598 |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
599 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
|
600 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
|
601 { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
602 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
|
603 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
|
604 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
622 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
|
623 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
624 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
625 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
|
626 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
|
627 { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
628 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
|
629 |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
637 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
|
638 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
639 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
640 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
641 mro_implementation(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
642 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
643 int i, n, ok; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
644 PyObject *bases, *result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
645 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
646 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
647 n = PyTuple_GET_SIZE(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
648 result = Py_BuildValue("[O]", (PyObject *)type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
649 if (result == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
650 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 ((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
|
657 else |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
658 parentMRO = classic_mro(base); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
659 if (parentMRO == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
660 Py_DECREF(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
661 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
662 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
663 if (serious_order_disagreements(result, parentMRO)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
664 Py_DECREF(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
665 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
666 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
667 ok = conservative_merge(result, parentMRO); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
668 Py_DECREF(parentMRO); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
669 if (ok < 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
670 Py_DECREF(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
671 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
672 } |
|
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 return result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
675 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
676 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
677 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
|
678 mro_external(PyObject *self) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
679 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
680 PyTypeObject *type = (PyTypeObject *)self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
681 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
682 return mro_implementation(type); |
|
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 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
685 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
686 mro_internal(PyTypeObject *type) |
|
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 PyObject *mro, *result, *tuple; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
689 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
690 if (type->ob_type == &PyType_Type) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
691 result = mro_implementation(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
692 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
693 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
|
694 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
|
695 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
|
696 if (mro == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
697 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
698 result = PyObject_CallObject(mro, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
699 Py_DECREF(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
700 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
701 if (result == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
702 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
703 tuple = PySequence_Tuple(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
704 Py_DECREF(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
705 type->tp_mro = tuple; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
706 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
707 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
708 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
709 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
710 /* 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
|
711 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
|
712 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
713 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
714 best_base(PyObject *bases) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
715 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
716 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
717 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
|
718 PyObject *base_proto; |
|
18933
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 assert(PyTuple_Check(bases)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
721 n = PyTuple_GET_SIZE(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
722 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
|
723 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
|
724 winner = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 continue; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
729 if (!PyType_Check(base_proto)) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
730 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
731 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
732 "bases must be types"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
733 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
734 } |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
735 base_i = (PyTypeObject *)base_proto; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
736 if (base_i->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
737 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
|
738 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
739 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
740 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
|
741 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
|
742 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
|
743 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
|
744 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
745 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
|
746 ; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
747 else if (PyType_IsSubtype(candidate, winner)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
748 winner = candidate; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
749 base = base_i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
750 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
751 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
752 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
753 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
754 "multiple bases have " |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
755 "instance lay-out conflict"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
756 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
757 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
758 } |
| 21404 | 759 if (base == NULL) |
| 760 PyErr_SetString(PyExc_TypeError, | |
| 761 "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
|
762 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
763 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
764 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
765 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
766 extra_ivars(PyTypeObject *type, PyTypeObject *base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
767 { |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
768 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
|
769 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
|
770 |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
771 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
|
772 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
|
773 /* If itemsize is involved, stricter rules */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
774 return t_size != b_size || |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
775 type->tp_itemsize != base->tp_itemsize; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
776 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
777 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
|
778 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
|
779 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
780 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
|
781 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
|
782 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
783 |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
784 return t_size != b_size; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
785 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
786 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
787 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
788 solid_base(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
789 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
790 PyTypeObject *base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
791 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
792 if (type->tp_base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
793 base = solid_base(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
794 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
795 base = &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
796 if (extra_ivars(type, base)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
797 return type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
798 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
799 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
800 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
801 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
802 staticforward void object_dealloc(PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
803 staticforward int object_init(PyObject *, PyObject *, PyObject *); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
804 staticforward int update_slot(PyTypeObject *, 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
|
805 staticforward void fixup_slot_dispatchers(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
806 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
807 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
|
808 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
|
809 { |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
810 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
|
811 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
|
812 |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
813 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
|
814 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
|
815 "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
|
816 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
|
817 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
818 dict = *dictptr; |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
819 if (dict == NULL) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
820 *dictptr = dict = PyDict_New(); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
821 Py_XINCREF(dict); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
822 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
|
823 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
824 |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
825 static int |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
826 subtype_setdict(PyObject *obj, PyObject *value, void *context) |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
827 { |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
828 PyObject **dictptr = _PyObject_GetDictPtr(obj); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
829 PyObject *dict; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
830 |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
831 if (dictptr == NULL) { |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
832 PyErr_SetString(PyExc_AttributeError, |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
833 "This object has no __dict__"); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
834 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
835 } |
|
21235
b782490da7f0
At the PythonLabs meeting someone mentioned it would make Jim really
Guido van Rossum <guido@python.org>
parents:
21192
diff
changeset
|
836 if (value != NULL && !PyDict_Check(value)) { |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
837 PyErr_SetString(PyExc_TypeError, |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
838 "__dict__ must be set to a dictionary"); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
839 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
840 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
841 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
|
842 Py_XINCREF(value); |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
843 *dictptr = value; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
844 Py_XDECREF(dict); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
845 return 0; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
846 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
847 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
848 static PyGetSetDef subtype_getsets[] = { |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
849 {"__dict__", subtype_dict, subtype_setdict, NULL}, |
|
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
|
850 {0}, |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
851 }; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
852 |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
853 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
854 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
|
855 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
856 PyObject *name, *bases, *dict; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
857 static char *kwlist[] = {"name", "bases", "dict", 0}; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
858 PyObject *slots, *tmp; |
|
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
|
859 PyTypeObject *type, *base, *tmptype, *winner; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
860 etype *et; |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
861 PyMemberDef *mp; |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
862 int i, nbases, nslots, slotoffset, add_dict, add_weak; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
863 |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
864 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
|
865 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
|
866 |
|
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
|
867 /* 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
|
868 { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
869 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
|
870 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
|
871 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
872 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
|
873 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
|
874 Py_INCREF(x->ob_type); |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
875 return (PyObject *) x->ob_type; |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
876 } |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
877 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
878 /* 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
|
879 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
|
880 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
|
881 if (nargs + nkwds != 3) { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
882 PyErr_SetString(PyExc_TypeError, |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
883 "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
|
884 return NULL; |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
885 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
886 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
887 |
|
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
|
888 /* Check arguments: (name, bases, dict) */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
889 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
|
890 &name, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
891 &PyTuple_Type, &bases, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
892 &PyDict_Type, &dict)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
893 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
894 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
895 /* 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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 winner = metatype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
901 for (i = 0; i < nbases; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
902 tmp = PyTuple_GET_ITEM(bases, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
903 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
|
904 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
|
905 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
|
906 if (PyType_IsSubtype(winner, tmptype)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
907 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
|
908 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
|
909 winner = tmptype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
910 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
911 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
912 PyErr_SetString(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
913 "metatype conflict among bases"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
914 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
915 } |
|
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
|
916 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
|
917 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
|
918 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
|
919 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
|
920 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
921 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
922 /* Adjust for empty tuple bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
923 if (nbases == 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
924 bases = Py_BuildValue("(O)", &PyBaseObject_Type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
925 if (bases == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
926 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
927 nbases = 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
928 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
929 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
930 Py_INCREF(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
931 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
932 /* 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
|
933 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
934 /* 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
|
935 base = best_base(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
936 if (base == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
937 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
938 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
|
939 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
940 "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
|
941 base->tp_name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
942 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
943 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
944 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
945 /* 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
|
946 slots = PyDict_GetItemString(dict, "__slots__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
947 nslots = 0; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
948 add_dict = 0; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
949 add_weak = 0; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
950 if (slots != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
951 /* Make it into a tuple */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
952 if (PyString_Check(slots)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
953 slots = Py_BuildValue("(O)", slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
954 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
955 slots = PySequence_Tuple(slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
956 if (slots == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
957 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
958 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
|
959 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
|
960 PyErr_Format(PyExc_TypeError, |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
961 "nonempty __slots__ " |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
962 "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
|
963 base->tp_name); |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
964 return NULL; |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
965 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
966 for (i = 0; i < nslots; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
967 if (!PyString_Check(PyTuple_GET_ITEM(slots, i))) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
968 PyErr_SetString(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
969 "__slots__ must be a sequence of strings"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
970 Py_DECREF(slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
971 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
972 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
973 /* XXX Check against null bytes in name */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
974 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
975 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
976 if (slots == NULL && base->tp_dictoffset == 0 && |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
977 (base->tp_setattro == PyObject_GenericSetAttr || |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
978 base->tp_setattro == NULL)) { |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
979 add_dict++; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
980 } |
|
19595
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
981 if (slots == NULL && base->tp_weaklistoffset == 0 && |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
982 base->tp_itemsize == 0) { |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
983 nslots++; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
984 add_weak++; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
985 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
986 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
987 /* 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
|
988 "return NULL" may leak slots! */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
989 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
990 /* Allocate the type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
991 type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
992 if (type == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
993 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
994 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
995 /* 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
|
996 et = (etype *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
997 Py_INCREF(name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
998 et->name = name; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
999 et->slots = slots; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1000 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1001 /* Initialize tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1007 /* 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
|
1008 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
|
1009 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
|
1010 (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
|
1011 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
|
1012 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
1013 /* Initialize essential fields */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 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
|
1019 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1020 /* Set tp_base and tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1021 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1022 Py_INCREF(base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1023 type->tp_base = base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1024 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1025 /* 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
|
1026 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
|
1027 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1028 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1029 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1030 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1031 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1032 /* Set __module__ in the dict */ |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1033 if (PyDict_GetItemString(dict, "__module__") == NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1034 tmp = PyEval_GetGlobals(); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1035 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1036 tmp = PyDict_GetItemString(tmp, "__name__"); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1037 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1038 if (PyDict_SetItemString(dict, "__module__", |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1039 tmp) < 0) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1040 return NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1041 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1042 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1043 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
1044 |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1045 /* Set tp_doc to a copy of dict['__doc__'], if the latter is there |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
1046 and is a string. Note that the tp_doc slot will only be used |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
1047 by C code -- python code will use the version in tp_dict, so |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
1048 it isn't that important that non string __doc__'s are ignored. |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1049 */ |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1050 { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1051 PyObject *doc = PyDict_GetItemString(dict, "__doc__"); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1052 if (doc != NULL && PyString_Check(doc)) { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1053 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
|
1054 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
|
1055 if (type->tp_doc == NULL) { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1056 Py_DECREF(type); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1057 return NULL; |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1058 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1059 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
|
1060 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1061 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1062 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1063 /* 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
|
1064 make it a static function */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1065 tmp = PyDict_GetItemString(dict, "__new__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1066 if (tmp != NULL && PyFunction_Check(tmp)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1067 tmp = PyStaticMethod_New(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1068 if (tmp == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1069 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1070 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1071 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1072 PyDict_SetItemString(dict, "__new__", tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1073 Py_DECREF(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1074 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1075 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1076 /* 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
|
1077 mp = et->members; |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1078 slotoffset = base->tp_basicsize; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1079 if (slots != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1080 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
|
1081 mp->name = PyString_AS_STRING( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1082 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
|
1083 mp->type = T_OBJECT_EX; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1084 mp->offset = slotoffset; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1085 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
|
1086 strcmp(mp->name, "__weakref__") == 0) { |
|
c18ad52dece3
Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
Guido van Rossum <guido@python.org>
parents:
21151
diff
changeset
|
1087 mp->type = T_OBJECT; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1088 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
|
1089 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1090 slotoffset += sizeof(PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1091 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1092 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1093 else { |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1094 if (add_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
|
1095 if (base->tp_itemsize) |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1096 type->tp_dictoffset = |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1097 -(long)sizeof(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
|
1098 else |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1099 type->tp_dictoffset = slotoffset; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1100 slotoffset += sizeof(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
|
1101 type->tp_getset = subtype_getsets; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1102 } |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1103 if (add_weak) { |
|
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
|
1104 assert(!base->tp_itemsize); |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1105 type->tp_weaklistoffset = slotoffset; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1106 mp->name = "__weakref__"; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1107 mp->type = T_OBJECT; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1108 mp->offset = slotoffset; |
|
19950
76133a465e03
type_new(): Didn't compile anymore, due to change in struct memberlist
Tim Peters <tim.peters@gmail.com>
parents:
19914
diff
changeset
|
1109 mp->flags = READONLY; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1110 mp++; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1111 slotoffset += sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1112 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1113 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1114 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
|
1115 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
|
1116 type->tp_members = et->members; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1117 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1118 /* Special case some slots */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1119 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
|
1120 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
|
1121 type->tp_getattro = PyObject_GenericGetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1122 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
|
1123 type->tp_setattro = PyObject_GenericSetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1124 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1125 type->tp_dealloc = subtype_dealloc; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1126 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1127 /* 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
|
1128 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
|
1129 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
|
1130 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
|
1131 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1132 /* 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
|
1133 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
|
1134 if (type->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
|
1135 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
|
1136 type->tp_traverse = subtype_traverse; |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1137 type->tp_clear = base->tp_clear; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1138 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1139 else |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1140 type->tp_free = _PyObject_Del; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1141 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1142 /* Initialize the rest */ |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1143 if (PyType_Ready(type) < 0) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1144 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1145 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1146 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1147 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
1148 /* 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
|
1149 fixup_slot_dispatchers(type); |
| 19036 | 1150 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1151 return (PyObject *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1152 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1153 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1154 /* 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
|
1155 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
|
1156 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1157 _PyType_Lookup(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1158 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1159 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
|
1160 PyObject *mro, *res, *base, *dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1161 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1162 /* 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
|
1163 mro = type->tp_mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1164 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1165 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 else { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1171 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
|
1172 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
|
1173 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1174 assert(dict && PyDict_Check(dict)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1175 res = PyDict_GetItem(dict, name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1176 if (res != NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1177 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1178 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1179 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1180 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1181 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1182 /* This is similar to PyObject_GenericGetAttr(), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1183 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
|
1184 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1185 type_getattro(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1186 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1187 PyTypeObject *metatype = type->ob_type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1188 PyObject *descr, *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1189 descrgetfunc f; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1190 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1191 /* 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
|
1192 if (type->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1193 if (PyType_Ready(type) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1194 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1195 } |
|
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 /* Get a descriptor from the metatype */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1198 descr = _PyType_Lookup(metatype, name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1199 f = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1200 if (descr != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1201 f = descr->ob_type->tp_descr_get; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1202 if (f != NULL && PyDescr_IsData(descr)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1203 return f(descr, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1204 (PyObject *)type, (PyObject *)metatype); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1205 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1206 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1207 /* Look in tp_dict of this type and its bases */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1208 res = _PyType_Lookup(type, name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1209 if (res != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1210 f = res->ob_type->tp_descr_get; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1211 if (f != NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1212 return f(res, (PyObject *)NULL, (PyObject *)type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1213 Py_INCREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1214 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1215 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1216 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1217 /* Use the descriptor from the metatype */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1218 if (f != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1219 res = f(descr, (PyObject *)type, (PyObject *)metatype); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1220 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1221 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1222 if (descr != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1223 Py_INCREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1224 return descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1225 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1226 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1227 /* Give up */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1228 PyErr_Format(PyExc_AttributeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1229 "type object '%.50s' has no attribute '%.400s'", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1230 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
|
1231 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1232 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1233 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1234 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1235 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
|
1236 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1237 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
|
1238 PyErr_Format( |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1239 PyExc_TypeError, |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1240 "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
|
1241 type->tp_name); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1242 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
|
1243 } |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1244 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
|
1245 return -1; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1246 return update_slot(type, name); |
|
18933
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 void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1250 type_dealloc(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1251 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1252 etype *et; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1253 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1254 /* 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
|
1255 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
|
1256 _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
|
1257 PyObject_ClearWeakRefs((PyObject *)type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1258 et = (etype *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1259 Py_XDECREF(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1260 Py_XDECREF(type->tp_dict); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1261 Py_XDECREF(type->tp_bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1262 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
|
1263 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
|
1264 Py_XDECREF(type->tp_subclasses); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1265 Py_XDECREF(et->name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1266 Py_XDECREF(et->slots); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1267 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
|
1268 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1269 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1270 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
|
1271 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
|
1272 { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1273 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
|
1274 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
|
1275 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 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
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 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
|
1291 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
|
1292 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1293 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1294 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1295 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
|
1296 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1297 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1298 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
|
1299 {"mro", (PyCFunction)mro_external, METH_NOARGS, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1300 "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
|
1301 {"__subclasses__", (PyCFunction)type_subclasses, METH_NOARGS, |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1302 "__subclasses__() -> list of immediate subclasses"}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1303 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1304 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1305 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1306 static char type_doc[] = |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1307 "type(object) -> the object's type\n" |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1308 "type(name, bases, dict) -> a new type"; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1309 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1310 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
|
1311 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
|
1312 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1313 etype *et; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1314 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
|
1315 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1316 if (!(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
|
1317 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
|
1318 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1319 et = (etype *)type; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1320 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1321 #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
|
1322 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
|
1323 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
|
1324 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
|
1325 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
|
1326 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1327 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1328 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
|
1329 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
|
1330 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
|
1331 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
|
1332 VISIT(type->tp_base); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1333 VISIT(type->tp_subclasses); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1334 VISIT(et->slots); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1335 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1336 #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
|
1337 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1338 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
|
1339 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1340 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1341 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
|
1342 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
|
1343 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1344 etype *et; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1345 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
|
1346 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1347 if (!(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
|
1348 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
|
1349 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1350 et = (etype *)type; |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1351 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1352 #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
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1358 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1359 CLEAR(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
|
1360 CLEAR(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
|
1361 CLEAR(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
|
1362 CLEAR(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
|
1363 CLEAR(type->tp_base); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1364 CLEAR(type->tp_subclasses); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1365 CLEAR(et->slots); |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1366 |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1367 if (type->tp_doc != NULL) { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1368 PyObject_FREE(type->tp_doc); |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1369 type->tp_doc = NULL; |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1370 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1371 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1372 #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
|
1373 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1374 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
|
1375 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1376 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1377 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
|
1378 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
|
1379 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1380 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
|
1381 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1382 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
1383 PyTypeObject PyType_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
1384 PyObject_HEAD_INIT(&PyType_Type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1385 0, /* ob_size */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1386 "type", /* tp_name */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1387 sizeof(etype), /* tp_basicsize */ |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
1388 sizeof(PyMemberDef), /* tp_itemsize */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1389 (destructor)type_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1390 0, /* tp_print */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1391 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1392 0, /* tp_setattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1393 type_compare, /* tp_compare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1394 (reprfunc)type_repr, /* tp_repr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1395 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1396 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1397 0, /* tp_as_mapping */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1398 (hashfunc)_Py_HashPointer, /* tp_hash */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1399 (ternaryfunc)type_call, /* tp_call */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1400 0, /* tp_str */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1401 (getattrofunc)type_getattro, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1402 (setattrofunc)type_setattro, /* tp_setattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1403 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
|
1404 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
|
1405 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1406 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
|
1407 (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
|
1408 (inquiry)type_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1409 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
|
1410 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
|
1411 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1412 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1413 type_methods, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1414 type_members, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1415 type_getsets, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1416 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1417 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1418 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1419 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1420 offsetof(PyTypeObject, tp_dict), /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1421 0, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1422 0, /* tp_alloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1423 type_new, /* tp_new */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1424 _PyObject_GC_Del, /* tp_free */ |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
1425 (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
|
1426 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1427 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1428 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1429 /* 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
|
1430 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1431 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1432 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
|
1433 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1434 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1435 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1436 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1437 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1438 object_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1439 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1440 self->ob_type->tp_free(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1441 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1442 |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1443 static PyObject * |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1444 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
|
1445 { |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
1446 PyTypeObject *type; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
1447 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
|
1448 |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
1449 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
|
1450 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
|
1451 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
|
1452 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
|
1453 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
|
1454 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
|
1455 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
|
1456 } |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 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
|
1461 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
|
1462 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
|
1463 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
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 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
|
1469 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
|
1470 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
|
1471 } |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1472 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1473 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1474 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
|
1475 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1476 unaryfunc f; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1477 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1478 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
|
1479 if (f == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1480 f = object_repr; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1481 return f(self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1482 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
1483 |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1484 static long |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1485 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
|
1486 { |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1487 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
|
1488 } |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
1489 |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1490 static PyObject * |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1491 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
|
1492 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1493 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
|
1494 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
|
1495 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1496 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1497 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1498 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
|
1499 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1500 return a == b || |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1501 (a != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1502 b != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1503 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
|
1504 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
|
1505 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
|
1506 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
|
1507 ((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
|
1508 (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
|
1509 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1510 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1511 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1512 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
|
1513 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1514 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
|
1515 int size; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1516 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1517 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
|
1518 return 0; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1519 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
|
1520 return 1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1521 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
|
1522 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
|
1523 size += sizeof(PyObject *); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1524 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
|
1525 size += sizeof(PyObject *); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1526 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
|
1527 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1528 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1529 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1530 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
|
1531 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1532 PyTypeObject *old = self->ob_type; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1533 PyTypeObject *new, *newbase, *oldbase; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1534 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1535 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
|
1536 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
|
1537 "__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
|
1538 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
|
1539 return -1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1540 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1541 new = (PyTypeObject *)value; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1542 newbase = new; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1543 oldbase = old; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1544 while (equiv_structs(newbase, newbase->tp_base)) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1545 newbase = newbase->tp_base; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1546 while (equiv_structs(oldbase, oldbase->tp_base)) |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1547 oldbase = oldbase->tp_base; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1548 if (newbase != oldbase && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1549 (newbase->tp_base != oldbase->tp_base || |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1550 !same_slots_added(newbase, oldbase))) { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1551 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
|
1552 "__class__ assignment: " |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1553 "'%s' object layout differs from '%s'", |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
1554 new->tp_name, |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1555 old->tp_name); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1556 return -1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1557 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1558 if (new->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1559 Py_INCREF(new); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1560 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1561 self->ob_type = new; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1562 if (old->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1563 Py_DECREF(old); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1564 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1565 return 0; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1566 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1567 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1568 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
|
1569 {"__class__", object_get_class, object_set_class, |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1570 "the object's class"}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1571 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1572 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1573 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1574 static PyObject * |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1575 object_reduce(PyObject *self, PyObject *args) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1576 { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1577 /* Call copy_reg._reduce(self) */ |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1578 static PyObject *copy_reg_str; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1579 PyObject *copy_reg, *res; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1580 |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1581 if (!copy_reg_str) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1582 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
|
1583 if (copy_reg_str == NULL) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1584 return NULL; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1585 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1586 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
|
1587 if (!copy_reg) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1588 return NULL; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1589 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
|
1590 Py_DECREF(copy_reg); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1591 return res; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1592 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1593 |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1594 static PyMethodDef object_methods[] = { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1595 {"__reduce__", object_reduce, METH_NOARGS, "helper for pickle"}, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1596 {0} |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1597 }; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1598 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1599 PyTypeObject PyBaseObject_Type = { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1600 PyObject_HEAD_INIT(&PyType_Type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1601 0, /* ob_size */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1602 "object", /* tp_name */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1603 sizeof(PyObject), /* tp_basicsize */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1604 0, /* tp_itemsize */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1605 (destructor)object_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1606 0, /* tp_print */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1607 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1608 0, /* tp_setattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1609 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
|
1610 object_repr, /* tp_repr */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1611 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1612 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1613 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
|
1614 object_hash, /* tp_hash */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1615 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
|
1616 object_str, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1617 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
|
1618 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1619 0, /* tp_as_buffer */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1620 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1621 "The most base type", /* tp_doc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1622 0, /* tp_traverse */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1623 0, /* tp_clear */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1624 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1625 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1626 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1627 0, /* tp_iternext */ |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1628 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
|
1629 0, /* tp_members */ |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
1630 object_getsets, /* tp_getset */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1631 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1632 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1633 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1634 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1635 0, /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1636 object_init, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1637 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
|
1638 PyType_GenericNew, /* tp_new */ |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
1639 _PyObject_Del, /* tp_free */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1640 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1641 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1642 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1643 /* 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
|
1644 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1645 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1646 add_methods(PyTypeObject *type, PyMethodDef *meth) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1647 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1648 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1649 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1650 for (; meth->ml_name != NULL; meth++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1651 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1652 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
|
1653 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1654 descr = PyDescr_NewMethod(type, meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1655 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1656 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1657 if (PyDict_SetItemString(dict,meth->ml_name,descr) < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1658 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1659 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1660 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1661 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1662 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1663 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1664 static int |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
1665 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
|
1666 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1667 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1668 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1669 for (; memb->name != NULL; memb++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1670 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1671 if (PyDict_GetItemString(dict, memb->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1672 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1673 descr = PyDescr_NewMember(type, memb); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1674 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1675 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1676 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
|
1677 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1678 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1679 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1680 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1681 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1682 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1683 static int |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
1684 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
|
1685 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1686 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1687 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1688 for (; gsp->name != NULL; gsp++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1689 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1690 if (PyDict_GetItemString(dict, gsp->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1691 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1692 descr = PyDescr_NewGetSet(type, gsp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1693 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1694 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1695 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1696 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
|
1697 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1698 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1699 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1700 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1701 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1702 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1703 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1704 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
|
1705 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1706 int oldsize, newsize; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1707 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1708 /* 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
|
1709 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
|
1710 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
|
1711 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
|
1712 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
|
1713 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1714 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
|
1715 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
|
1716 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
|
1717 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1718 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
|
1719 (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
|
1720 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
|
1721 (!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
|
1722 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
|
1723 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
|
1724 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
|
1725 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
|
1726 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1727 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1728 /* Wow */ |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1729 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1730 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
|
1731 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
|
1732 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
|
1733 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1734 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1735 /* 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
|
1736 oldsize = base->tp_basicsize; |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1737 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
|
1738 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
|
1739 (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
|
1740 (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
|
1741 (!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
|
1742 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
|
1743 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
|
1744 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
|
1745 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
|
1746 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
|
1747 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1748 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
|
1749 /* 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
|
1750 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
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 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
|
1760 (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
|
1761 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
|
1762 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
|
1763 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1764 } |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1765 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
|
1766 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1767 /* 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
|
1768 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1769 #undef COPYVAL |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1770 #define COPYVAL(SLOT) \ |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1771 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
|
1772 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1773 COPYVAL(tp_itemsize); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1774 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
|
1775 COPYVAL(tp_weaklistoffset); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1776 } |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1777 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
|
1778 COPYVAL(tp_dictoffset); |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
1779 } |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1780 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1781 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1782 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1783 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
|
1784 { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1785 PyTypeObject *basebase; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1786 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1787 #undef SLOTDEFINED |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1788 #undef COPYSLOT |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1789 #undef COPYNUM |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1790 #undef COPYSEQ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1791 #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
|
1792 #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
|
1793 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1794 #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
|
1795 (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
|
1796 (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
|
1797 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1798 #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
|
1799 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
|
1800 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1801 #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
|
1802 #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
|
1803 #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
|
1804 #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
|
1805 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1806 /* 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
|
1807 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
|
1808 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1809 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
|
1810 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
|
1811 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
|
1812 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1813 COPYNUM(nb_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1814 COPYNUM(nb_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1815 COPYNUM(nb_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1816 COPYNUM(nb_divide); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1817 COPYNUM(nb_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1818 COPYNUM(nb_divmod); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1819 COPYNUM(nb_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1820 COPYNUM(nb_negative); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1821 COPYNUM(nb_positive); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1822 COPYNUM(nb_absolute); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1823 COPYNUM(nb_nonzero); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1824 COPYNUM(nb_invert); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1825 COPYNUM(nb_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1826 COPYNUM(nb_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1827 COPYNUM(nb_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1828 COPYNUM(nb_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1829 COPYNUM(nb_or); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1830 COPYNUM(nb_coerce); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1831 COPYNUM(nb_int); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1832 COPYNUM(nb_long); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1833 COPYNUM(nb_float); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1834 COPYNUM(nb_oct); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1835 COPYNUM(nb_hex); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1836 COPYNUM(nb_inplace_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1837 COPYNUM(nb_inplace_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1838 COPYNUM(nb_inplace_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1839 COPYNUM(nb_inplace_divide); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1840 COPYNUM(nb_inplace_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1841 COPYNUM(nb_inplace_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1842 COPYNUM(nb_inplace_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1843 COPYNUM(nb_inplace_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1844 COPYNUM(nb_inplace_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1845 COPYNUM(nb_inplace_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1846 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
|
1847 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
|
1848 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
|
1849 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
|
1850 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
|
1851 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
|
1852 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1853 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1854 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1855 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
|
1856 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
|
1857 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
|
1858 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1859 COPYSEQ(sq_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1860 COPYSEQ(sq_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1861 COPYSEQ(sq_repeat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1862 COPYSEQ(sq_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1863 COPYSEQ(sq_slice); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1864 COPYSEQ(sq_ass_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1865 COPYSEQ(sq_ass_slice); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1866 COPYSEQ(sq_contains); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1867 COPYSEQ(sq_inplace_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1868 COPYSEQ(sq_inplace_repeat); |
|
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 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1871 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
|
1872 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
|
1873 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
|
1874 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1875 COPYMAP(mp_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1876 COPYMAP(mp_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1877 COPYMAP(mp_ass_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1878 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1879 |
|
20384
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1880 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
|
1881 basebase = base->tp_base; |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1882 if (basebase->tp_as_buffer == NULL) |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1883 basebase = NULL; |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1884 COPYBUF(bf_getreadbuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1885 COPYBUF(bf_getwritebuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1886 COPYBUF(bf_getsegcount); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1887 COPYBUF(bf_getcharbuffer); |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1888 } |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
1889 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1890 basebase = base->tp_base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1891 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1892 COPYSLOT(tp_dealloc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1893 COPYSLOT(tp_print); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1894 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
|
1895 type->tp_getattr = base->tp_getattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1896 type->tp_getattro = base->tp_getattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1897 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1898 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
|
1899 type->tp_setattr = base->tp_setattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1900 type->tp_setattro = base->tp_setattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1901 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1902 /* tp_compare see tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1903 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
|
1904 /* tp_hash see tp_richcompare */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1905 COPYSLOT(tp_call); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1906 COPYSLOT(tp_str); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1907 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
|
1908 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
|
1909 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
|
1910 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
|
1911 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1912 type->tp_compare = base->tp_compare; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1913 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
|
1914 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
|
1915 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1916 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1917 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1918 COPYSLOT(tp_compare); |
|
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 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
|
1921 COPYSLOT(tp_iter); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1922 COPYSLOT(tp_iternext); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1923 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1924 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
|
1925 COPYSLOT(tp_descr_get); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1926 COPYSLOT(tp_descr_set); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1927 COPYSLOT(tp_dictoffset); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1928 COPYSLOT(tp_init); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1929 COPYSLOT(tp_alloc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1930 COPYSLOT(tp_free); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1931 } |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1932 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1933 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
1934 staticforward int add_operators(PyTypeObject *); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
1935 staticforward int add_subclass(PyTypeObject *base, PyTypeObject *type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1936 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1937 int |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1938 PyType_Ready(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1939 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
1940 PyObject *dict, *bases; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1941 PyTypeObject *base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1942 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1943 |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
1944 if (type->tp_flags & Py_TPFLAGS_READY) { |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
1945 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
|
1946 return 0; |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
1947 } |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
1948 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
|
1949 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
1950 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
|
1951 |
|
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
|
1952 /* 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
|
1953 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
|
1954 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
|
1955 if (type->ob_type == NULL) |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
1956 type->ob_type = &PyType_Type; |
|
be5ca0b25bfd
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
Guido van Rossum <guido@python.org>
parents:
21404
diff
changeset
|
1957 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1958 /* Initialize tp_base (defaults to BaseObject unless that's us) */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1959 base = type->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1960 if (base == NULL && type != &PyBaseObject_Type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1961 base = type->tp_base = &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1962 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1963 /* Initialize tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1964 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1965 if (bases == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1966 if (base == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1967 bases = PyTuple_New(0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1968 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1969 bases = Py_BuildValue("(O)", base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1970 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
|
1971 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1972 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1973 } |
|
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 /* Initialize the base class */ |
|
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
|
1976 if (base && base->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1977 if (PyType_Ready(base) < 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
|
1978 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1979 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1980 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1981 /* 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
|
1982 dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1983 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1984 dict = PyDict_New(); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1985 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
|
1986 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
|
1987 type->tp_dict = dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1988 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1989 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
1990 /* 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
|
1991 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
|
1992 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1993 if (type->tp_methods != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1994 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
|
1995 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1996 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1997 if (type->tp_members != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1998 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
|
1999 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2000 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2001 if (type->tp_getset != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2002 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
|
2003 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2004 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2005 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2006 /* Calculate method resolution order */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2007 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
|
2008 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2009 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2010 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2011 /* 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
|
2012 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
|
2013 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
|
2014 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2015 /* Initialize tp_dict properly */ |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2016 bases = type->tp_mro; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2017 assert(bases != NULL); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2018 assert(PyTuple_Check(bases)); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2019 n = PyTuple_GET_SIZE(bases); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2020 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
|
2021 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
|
2022 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
|
2023 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
|
2024 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2025 |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2026 /* 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
|
2027 the tp_doc slot. |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2028 */ |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2029 if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2030 if (type->tp_doc != NULL) { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2031 PyObject *doc = PyString_FromString(type->tp_doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2032 PyDict_SetItemString(type->tp_dict, "__doc__", doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2033 Py_DECREF(doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2034 } else { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2035 PyDict_SetItemString(type->tp_dict, "__doc__", Py_None); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2036 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2037 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
2038 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2039 /* 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
|
2040 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
|
2041 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
|
2042 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
|
2043 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
|
2044 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
|
2045 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
|
2046 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
|
2047 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
|
2048 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2049 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2050 /* 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
|
2051 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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 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
|
2057 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
|
2058 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2059 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
2060 /* 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
|
2061 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
|
2062 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
|
2063 (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
|
2064 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
|
2065 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2066 error: |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
2067 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
|
2068 return -1; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2069 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2070 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2071 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
|
2072 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
|
2073 { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2074 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
|
2075 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
|
2076 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2077 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
|
2078 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
|
2079 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
|
2080 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
|
2081 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
|
2082 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2083 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
|
2084 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
|
2085 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
|
2086 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
|
2087 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
|
2088 assert(PyWeakref_CheckRef(ref)); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2089 if (PyWeakref_GET_OBJECT(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
|
2090 return PyList_SetItem(list, i, new); |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2091 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2092 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
|
2093 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
|
2094 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
|
2095 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2096 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2097 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2098 /* 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
|
2099 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2100 /* 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
|
2101 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
|
2102 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
|
2103 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
|
2104 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
|
2105 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2106 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2107 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
|
2108 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2109 inquiry func = (inquiry)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2110 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2111 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2112 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2113 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2114 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2115 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2116 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2117 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2118 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2119 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2120 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2121 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
|
2122 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2123 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2124 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2125 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2126 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2127 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2128 return (*func)(self, other); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2129 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2130 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2131 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
|
2132 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
|
2133 { |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2134 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
|
2135 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
|
2136 |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2137 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
|
2138 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
|
2139 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
|
2140 !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
|
2141 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
|
2142 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
|
2143 } |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2144 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
|
2145 } |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2146 |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
2147 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2148 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
|
2149 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2150 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2151 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2152 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2153 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2154 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
|
2155 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
|
2156 !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
|
2157 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
|
2158 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
|
2159 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2160 return (*func)(other, self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2161 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2162 |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2163 static PyObject * |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2164 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
|
2165 { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2166 coercion func = (coercion)wrapped; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2167 PyObject *other, *res; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2168 int ok; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2169 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2170 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
|
2171 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2172 ok = func(&self, &other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2173 if (ok < 0) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2174 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2175 if (ok > 0) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2176 Py_INCREF(Py_NotImplemented); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2177 return Py_NotImplemented; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2178 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2179 res = PyTuple_New(2); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2180 if (res == NULL) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2181 Py_DECREF(self); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2182 Py_DECREF(other); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2183 return NULL; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2184 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2185 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
|
2186 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
|
2187 return res; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2188 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2189 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2190 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2191 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
|
2192 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2193 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2194 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2195 PyObject *third = Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2196 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2197 /* 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
|
2198 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2199 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
|
2200 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2201 return (*func)(self, other, third); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2202 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2203 |
|
20168
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
2204 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
|
2205 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
|
2206 { |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
2207 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
|
2208 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
|
2209 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
|
2210 |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
2211 /* 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
|
2212 |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
2213 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
|
2214 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
|
2215 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
|
2216 } |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
2217 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2218 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2219 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
|
2220 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2221 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2222 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2223 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2224 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2225 return (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2226 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2227 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2228 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2229 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
|
2230 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2231 intargfunc func = (intargfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2232 int i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2233 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2234 if (!PyArg_ParseTuple(args, "i", &i)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2235 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2236 return (*func)(self, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2237 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2238 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2239 static int |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2240 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
|
2241 { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2242 int i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2243 |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2244 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
|
2245 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
|
2246 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2247 if (i < 0) { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2248 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
|
2249 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
|
2250 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
|
2251 if (n < 0) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2252 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2253 i += n; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2254 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2255 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2256 return i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2257 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2258 |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2259 static PyObject * |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2260 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
|
2261 { |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2262 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
|
2263 PyObject *arg; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2264 int i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2265 |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2266 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
|
2267 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
|
2268 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
|
2269 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
|
2270 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2271 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
|
2272 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2273 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
|
2274 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
|
2275 return NULL; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2276 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2277 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2278 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2279 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
|
2280 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2281 intintargfunc func = (intintargfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2282 int i, j; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2283 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2284 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
|
2285 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2286 return (*func)(self, i, j); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2287 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2288 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2289 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2290 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
|
2291 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2292 intobjargproc func = (intobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2293 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
|
2294 PyObject *arg, *value; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2295 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2296 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
|
2297 return NULL; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2298 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
|
2299 if (i == -1 && PyErr_Occurred()) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2300 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2301 res = (*func)(self, i, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2302 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2303 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2304 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2305 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2306 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2307 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2308 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2309 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
|
2310 { |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2311 intobjargproc func = (intobjargproc)wrapped; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2312 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
|
2313 PyObject *arg; |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2314 |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2315 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
|
2316 return NULL; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
2317 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
|
2318 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
|
2319 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2320 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
|
2321 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
|
2322 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2323 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2324 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2325 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2326 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2327 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2328 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
|
2329 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2330 intintobjargproc func = (intintobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2331 int i, j, res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2332 PyObject *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2333 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2334 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
|
2335 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2336 res = (*func)(self, i, j, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2337 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2338 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2339 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2340 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2341 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2342 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2343 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
|
2344 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
|
2345 { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2346 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
|
2347 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
|
2348 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2349 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
|
2350 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
|
2351 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
|
2352 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
|
2353 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
|
2354 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
|
2355 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
|
2356 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2357 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2358 /* 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
|
2359 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2360 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
|
2361 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2362 objobjproc func = (objobjproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2363 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2364 PyObject *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2365 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2366 if (!PyArg_ParseTuple(args, "O", &value)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2367 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2368 res = (*func)(self, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2369 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2370 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2371 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2372 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2373 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2374 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2375 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
|
2376 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2377 objobjargproc func = (objobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2378 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2379 PyObject *key, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2380 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2381 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
|
2382 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2383 res = (*func)(self, key, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2384 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2385 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2386 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2387 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2388 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2389 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2390 static PyObject * |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2391 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
|
2392 { |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2393 objobjargproc func = (objobjargproc)wrapped; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2394 int res; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2395 PyObject *key; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2396 |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2397 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
|
2398 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2399 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
|
2400 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
|
2401 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2402 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2403 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2404 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
2405 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2406 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2407 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
|
2408 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2409 cmpfunc func = (cmpfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2410 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2411 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2412 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2413 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2414 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
|
2415 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
|
2416 !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
|
2417 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
|
2418 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
|
2419 "%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
|
2420 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
|
2421 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
|
2422 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
|
2423 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
|
2424 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2425 res = (*func)(self, other); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2426 if (PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2427 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2428 return PyInt_FromLong((long)res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2429 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2430 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2431 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2432 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
|
2433 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2434 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2435 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2436 PyObject *name, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2437 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2438 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
|
2439 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2440 res = (*func)(self, name, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2441 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2442 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2443 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2444 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2445 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2446 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2447 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2448 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
|
2449 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2450 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2451 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2452 PyObject *name; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2453 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2454 if (!PyArg_ParseTuple(args, "O", &name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2455 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2456 res = (*func)(self, name, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2457 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2458 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2459 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2460 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2461 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2462 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2463 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2464 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
|
2465 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2466 hashfunc func = (hashfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2467 long res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2468 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2469 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2470 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2471 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2472 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2473 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2474 return PyInt_FromLong(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2475 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2476 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2477 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
|
2478 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
|
2479 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2480 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2481 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
2482 return (*func)(self, args, kwds); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2483 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2484 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2485 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2486 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
|
2487 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2488 richcmpfunc func = (richcmpfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2489 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2490 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2491 if (!PyArg_ParseTuple(args, "O", &other)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2492 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2493 return (*func)(self, other, op); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2494 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2495 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2496 #undef RICHCMP_WRAPPER |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2497 #define RICHCMP_WRAPPER(NAME, OP) \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2498 static PyObject * \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2499 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
|
2500 { \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2501 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
|
2502 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2503 |
|
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
|
2504 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
|
2505 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
|
2506 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
|
2507 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
|
2508 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
|
2509 RICHCMP_WRAPPER(ge, Py_GE) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2510 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2511 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2512 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
|
2513 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2514 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2515 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2516 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2517 if (!PyArg_ParseTuple(args, "")) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2518 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2519 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2520 if (res == NULL && !PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2521 PyErr_SetNone(PyExc_StopIteration); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2522 return res; |
|
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 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2525 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2526 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
|
2527 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2528 descrgetfunc func = (descrgetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2529 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2530 PyObject *type = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2531 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2532 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
|
2533 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2534 return (*func)(self, obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2535 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2536 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2537 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
|
2538 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
|
2539 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2540 descrsetfunc func = (descrsetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2541 PyObject *obj, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2542 int ret; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2543 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2544 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
|
2545 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2546 ret = (*func)(self, obj, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2547 if (ret < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2548 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2549 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2550 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2551 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2552 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2553 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
|
2554 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
|
2555 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2556 initproc func = (initproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2557 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
2558 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
|
2559 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2560 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2561 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2562 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2563 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2564 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
|
2565 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
|
2566 { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2567 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
|
2568 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
|
2569 |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
2570 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
|
2571 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
|
2572 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
|
2573 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
|
2574 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
|
2575 "%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
|
2576 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
|
2577 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
|
2578 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
2579 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
|
2580 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
|
2581 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
|
2582 "%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
|
2583 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2584 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
|
2585 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
|
2586 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
2587 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
|
2588 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
|
2589 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
|
2590 "%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
|
2591 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2592 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2593 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2594 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
|
2595 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
|
2596 } |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2597 |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2598 /* 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
|
2599 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
|
2600 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
|
2601 staticbase = subtype; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2602 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
|
2603 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
|
2604 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
|
2605 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
|
2606 "%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
|
2607 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2608 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2609 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
|
2610 return NULL; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2611 } |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
2612 |
|
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
|
2613 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
|
2614 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
|
2615 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
|
2616 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
|
2617 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
|
2618 return res; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2619 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2620 |
|
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
|
2621 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
|
2622 {"__new__", (PyCFunction)tp_new_wrapper, METH_KEYWORDS, |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
2623 "T.__new__(S, ...) -> 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
|
2624 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2625 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2626 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2627 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
|
2628 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
|
2629 { |
| 19036 | 2630 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
|
2631 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2632 if (PyDict_GetItemString(type->tp_dict, "__new__") != NULL) |
| 19036 | 2633 return 0; |
| 2634 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
|
2635 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
|
2636 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
|
2637 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
|
2638 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
2639 |
| 19036 | 2640 /* Slot wrappers that call the corresponding __foo__ slot. See comments |
| 2641 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
|
2642 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2643 #define SLOT0(FUNCNAME, OPSTR) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2644 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2645 FUNCNAME(PyObject *self) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2646 { \ |
|
19540
e141b392b61d
Fix a typo in SLOT0 macro for the declaration of cache_str.
Guido van Rossum <guido@python.org>
parents:
19538
diff
changeset
|
2647 static PyObject *cache_str; \ |
| 19911 | 2648 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
|
2649 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2650 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2651 #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
|
2652 static PyObject * \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2653 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
|
2654 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2655 static PyObject *cache_str; \ |
| 19911 | 2656 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
|
2657 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2658 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2659 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2660 #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
|
2661 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2662 FUNCNAME(PyObject *self, PyObject *other) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2663 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2664 static PyObject *cache_str, *rcache_str; \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2665 int do_other = self->ob_type != other->ob_type && \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2666 other->ob_type->tp_as_number != NULL && \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2667 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
|
2668 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
|
2669 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
|
2670 PyObject *r; \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2671 if (do_other && \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2672 PyType_IsSubtype(other->ob_type, self->ob_type)) { \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2673 r = call_maybe( \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2674 other, ROPSTR, &rcache_str, "(O)", self); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2675 if (r != Py_NotImplemented) \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2676 return r; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2677 Py_DECREF(r); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2678 do_other = 0; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2679 } \ |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
2680 r = call_maybe( \ |
| 19911 | 2681 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
|
2682 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
|
2683 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
|
2684 return r; \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2685 Py_DECREF(r); \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2686 } \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2687 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
|
2688 return call_maybe( \ |
| 19911 | 2689 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
|
2690 } \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2691 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
|
2692 return Py_NotImplemented; \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2693 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2694 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2695 #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
|
2696 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
|
2697 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2698 #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
|
2699 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2700 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
|
2701 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2702 static PyObject *cache_str; \ |
| 19911 | 2703 return call_method(self, OPSTR, &cache_str, \ |
| 2704 "(" ARGCODES ")", arg1, arg2); \ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2705 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2706 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2707 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2708 slot_sq_length(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2709 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2710 static PyObject *len_str; |
| 19911 | 2711 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
|
2712 int len; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2713 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2714 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2715 return -1; |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
2716 len = (int)PyInt_AsLong(res); |
|
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
2717 Py_DECREF(res); |
|
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
2718 return len; |
|
18933
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 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2721 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
|
2722 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
|
2723 |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2724 /* 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
|
2725 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
|
2726 static PyObject * |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2727 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
|
2728 { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2729 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
|
2730 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
|
2731 descrgetfunc f; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2732 |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2733 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
|
2734 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
|
2735 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
|
2736 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2737 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2738 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
|
2739 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
|
2740 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
|
2741 Py_INCREF(func); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2742 else |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2743 func = f(func, self, (PyObject *)(self->ob_type)); |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2744 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
|
2745 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
|
2746 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
|
2747 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
|
2748 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
|
2749 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
|
2750 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
|
2751 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
|
2752 return retval; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2753 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2754 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2755 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2756 else { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2757 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
|
2758 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2759 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
|
2760 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
|
2761 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
|
2762 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2763 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
2764 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2765 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
|
2766 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2767 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2768 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
|
2769 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2770 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
|
2771 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
|
2772 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2773 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
|
2774 res = call_method(self, "__delitem__", &delitem_str, |
| 19911 | 2775 "(i)", index); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2776 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2777 res = call_method(self, "__setitem__", &setitem_str, |
| 19911 | 2778 "(iO)", index, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2779 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2780 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2781 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2782 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2783 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2784 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2785 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2786 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
|
2787 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2788 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
|
2789 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
|
2790 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2791 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
|
2792 res = call_method(self, "__delslice__", &delslice_str, |
| 19911 | 2793 "(ii)", i, j); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2794 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2795 res = call_method(self, "__setslice__", &setslice_str, |
| 19911 | 2796 "(iiO)", i, j, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2797 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2798 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2799 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2800 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2801 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2802 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2803 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2804 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
|
2805 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2806 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
|
2807 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
|
2808 |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2809 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
|
2810 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2811 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2812 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
|
2813 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2814 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2815 else { |
| 19911 | 2816 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
|
2817 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2818 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2819 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2820 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2821 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2822 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
|
2823 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2824 else if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2825 return -1; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2826 else { |
|
19808
0584c9132525
Generalize operator.indexOf (PySequence_Index) to work with any
Tim Peters <tim.peters@gmail.com>
parents:
19803
diff
changeset
|
2827 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
|
2828 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
|
2829 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2830 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2831 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2832 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
|
2833 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
|
2834 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2835 #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
|
2836 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2837 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
|
2838 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2839 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2840 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
|
2841 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2842 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
|
2843 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
|
2844 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2845 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
|
2846 res = call_method(self, "__delitem__", &delitem_str, |
| 19911 | 2847 "(O)", key); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2848 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2849 res = call_method(self, "__setitem__", &setitem_str, |
| 19911 | 2850 "(OO)", key, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2851 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2852 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2853 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2854 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2855 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2856 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2857 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
|
2858 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
|
2859 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
|
2860 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
|
2861 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
|
2862 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
|
2863 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2864 staticforward PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2865 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2866 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
|
2867 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
|
2868 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2869 static PyObject * |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2870 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
|
2871 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2872 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
|
2873 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2874 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
|
2875 return slot_nb_power_binary(self, other); |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2876 /* Three-arg power doesn't use __rpow__ */ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
2877 return call_method(self, "__pow__", &pow_str, |
| 19911 | 2878 "(OO)", other, modulus); |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2879 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2880 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2881 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
|
2882 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
|
2883 SLOT0(slot_nb_absolute, "__abs__") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2884 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2885 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2886 slot_nb_nonzero(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2887 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2888 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
|
2889 static PyObject *nonzero_str, *len_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
|
2890 |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2891 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
|
2892 if (func == NULL) { |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2893 if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2894 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2895 func = lookup_maybe(self, "__len__", &len_str); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2896 if (func == NULL) { |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2897 if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2898 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2899 else |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2900 return 1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2901 } |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2902 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2903 res = PyObject_CallObject(func, NULL); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2904 Py_DECREF(func); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2905 if (res == NULL) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2906 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2907 return PyObject_IsTrue(res); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2908 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2909 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2910 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
|
2911 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
|
2912 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
|
2913 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
|
2914 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
|
2915 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
|
2916 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2917 static int |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2918 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
|
2919 { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2920 static PyObject *coerce_str; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2921 PyObject *self = *a, *other = *b; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2922 |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2923 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
|
2924 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
|
2925 PyObject *r; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2926 r = call_maybe( |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2927 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
|
2928 if (r == NULL) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2929 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2930 if (r == Py_NotImplemented) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2931 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2932 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2933 else { |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2934 if (!PyTuple_Check(r) || PyTuple_GET_SIZE(r) != 2) { |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2935 PyErr_SetString(PyExc_TypeError, |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2936 "__coerce__ didn't return a 2-tuple"); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2937 Py_DECREF(r); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2938 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2939 } |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2940 *a = PyTuple_GET_ITEM(r, 0); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2941 Py_INCREF(*a); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2942 *b = PyTuple_GET_ITEM(r, 1); |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2943 Py_INCREF(*b); |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2944 Py_DECREF(r); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
2945 return 0; |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2946 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2947 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2948 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
|
2949 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
|
2950 PyObject *r; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2951 r = call_maybe( |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2952 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
|
2953 if (r == NULL) |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2954 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2955 if (r == Py_NotImplemented) { |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2956 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2957 return 1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2958 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2959 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
|
2960 PyErr_SetString(PyExc_TypeError, |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2961 "__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
|
2962 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2963 return -1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2964 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2965 *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
|
2966 Py_INCREF(*a); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2967 *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
|
2968 Py_INCREF(*b); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2969 Py_DECREF(r); |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2970 return 0; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2971 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2972 return 1; |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2973 } |
|
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
2974 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2975 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
|
2976 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
|
2977 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
|
2978 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
|
2979 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
|
2980 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
|
2981 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
|
2982 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
|
2983 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
|
2984 SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2985 SLOT2(slot_nb_inplace_power, "__ipow__", PyObject *, PyObject *, "OO") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2986 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
|
2987 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
|
2988 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
|
2989 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
|
2990 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
|
2991 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
|
2992 "__floordiv__", "__rfloordiv__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2993 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
|
2994 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
|
2995 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
|
2996 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2997 static int |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2998 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
|
2999 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3000 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
|
3001 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
|
3002 int c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3003 |
|
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
|
3004 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
|
3005 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3006 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3007 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3008 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3009 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
|
3010 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3011 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3012 else { |
| 19911 | 3013 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
|
3014 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3015 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3016 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
|
3017 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3018 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3019 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
|
3020 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3021 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
|
3022 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3023 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
|
3024 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3025 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3026 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3027 return 2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3028 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3029 |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3030 /* 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
|
3031 int |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3032 _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
|
3033 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3034 int c; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3035 |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3036 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
|
3037 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
|
3038 if (c <= 1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3039 return c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3040 } |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19964
diff
changeset
|
3041 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
|
3042 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
|
3043 if (c < -1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3044 return -2; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3045 if (c <= 1) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3046 return -c; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3047 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3048 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
|
3049 (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
|
3050 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3051 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3052 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3053 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
|
3054 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3055 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
|
3056 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
|
3057 |
|
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
|
3058 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
|
3059 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3060 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
|
3061 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3062 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3063 } |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
3064 PyErr_Clear(); |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
3065 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
|
3066 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
|
3067 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3068 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3069 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3070 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
|
3071 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3072 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
|
3073 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
|
3074 |
|
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
|
3075 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
|
3076 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3077 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
|
3078 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3079 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3080 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3081 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3082 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3083 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
|
3084 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3085 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3086 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3087 static long |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3088 slot_tp_hash(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3089 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3090 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
|
3091 static PyObject *hash_str, *eq_str, *cmp_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
|
3092 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3093 long h; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3094 |
|
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
|
3095 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
|
3096 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3097 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3098 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
|
3099 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3100 if (res == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3101 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3102 h = PyInt_AsLong(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3103 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3104 else { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3105 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
|
3106 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
|
3107 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3108 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
|
3109 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
|
3110 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3111 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3112 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3113 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
|
3114 return -1; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3115 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3116 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3117 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
|
3118 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3119 if (h == -1 && !PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3120 h = -2; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3121 return h; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3122 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3123 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3124 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3125 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
|
3126 { |
|
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
|
3127 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
|
3128 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
|
3129 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3130 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3131 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3132 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3133 res = PyObject_Call(meth, args, kwds); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3134 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3135 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3136 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3137 |
|
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
|
3138 /* 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
|
3139 |
|
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
|
3140 - 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
|
3141 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
|
3142 |
|
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
|
3143 - 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
|
3144 |
|
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
|
3145 The code in update_slot() and fixup_slot_dispatchers() always installs |
|
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
|
3146 slot_tp_getattr_hook(); this detects the absence of __getattr__ and then |
|
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
|
3147 installs the simpler slot if necessary. */ |
|
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
|
3148 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3149 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3150 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
|
3151 { |
|
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
|
3152 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
|
3153 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
|
3154 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3155 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3156 |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3157 static PyObject * |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3158 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
|
3159 { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3160 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
|
3161 PyObject *getattr, *getattribute, *res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3162 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
|
3163 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
|
3164 |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3165 if (getattr_str == NULL) { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3166 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
|
3167 if (getattr_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3168 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3169 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3170 if (getattribute_str == NULL) { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3171 getattribute_str = |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3172 PyString_InternFromString("__getattribute__"); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3173 if (getattribute_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3174 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3175 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3176 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
|
3177 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
|
3178 /* 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
|
3179 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
|
3180 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
|
3181 } |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3182 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
|
3183 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
|
3184 (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
|
3185 ((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
|
3186 (void *)PyObject_GenericGetAttr)) |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3187 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
|
3188 else |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3189 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
|
3190 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
|
3191 PyErr_Clear(); |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3192 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
|
3193 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3194 return res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3195 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
3196 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3197 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3198 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
|
3199 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3200 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
|
3201 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
|
3202 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3203 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
|
3204 res = call_method(self, "__delattr__", &delattr_str, |
| 19911 | 3205 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3206 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3207 res = call_method(self, "__setattr__", &setattr_str, |
| 19911 | 3208 "(OO)", name, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3209 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3210 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3211 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3212 return 0; |
|
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 /* 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
|
3216 static char *name_op[] = { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3217 "__lt__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3218 "__le__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3219 "__eq__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3220 "__ne__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3221 "__gt__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3222 "__ge__", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3223 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3224 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3225 static PyObject * |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3226 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
|
3227 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3228 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
|
3229 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
|
3230 |
|
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
|
3231 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
|
3232 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3233 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3234 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
|
3235 return Py_NotImplemented; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3236 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3237 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
|
3238 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3239 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3240 else { |
| 19911 | 3241 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
|
3242 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3243 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3244 Py_DECREF(func); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3245 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3246 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3247 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3248 /* 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
|
3249 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
|
3250 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3251 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3252 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
|
3253 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3254 PyObject *res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3255 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3256 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
|
3257 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
|
3258 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
|
3259 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3260 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3261 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3262 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
|
3263 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
|
3264 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
|
3265 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3266 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3267 Py_DECREF(res); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3268 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3269 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
|
3270 return Py_NotImplemented; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3271 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3272 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3273 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3274 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
|
3275 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3276 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
|
3277 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
|
3278 |
|
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
|
3279 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
|
3280 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3281 res = PyObject_CallObject(func, NULL); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3282 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3283 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3284 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3285 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
|
3286 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
|
3287 if (func == NULL) { |
|
20183
c6b6189a8397
SF bug [#466173] unpack TypeError unclear
Tim Peters <tim.peters@gmail.com>
parents:
20168
diff
changeset
|
3288 PyErr_SetString(PyExc_TypeError, "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
|
3289 return NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3290 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3291 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3292 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
|
3293 } |
|
18933
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 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3296 slot_tp_iternext(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3297 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3298 static PyObject *next_str; |
| 19911 | 3299 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
|
3300 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3301 |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
3302 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
|
3303 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
|
3304 { |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
3305 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
|
3306 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
|
3307 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
|
3308 |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
3309 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
|
3310 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
|
3311 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
|
3312 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
|
3313 } |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
3314 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
|
3315 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
|
3316 /* 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
|
3317 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
|
3318 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
|
3319 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
|
3320 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
|
3321 } |
|
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
|
3322 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
|
3323 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
|
3324 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
|
3325 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
|
3326 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
|
3327 } |
|
18933
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 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3330 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
|
3331 { |
|
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
|
3332 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
|
3333 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
|
3334 |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
3335 if (value == NULL) |
|
21142
842b280421ba
Fix for SF bug #485678.
Guido van Rossum <guido@python.org>
parents:
20978
diff
changeset
|
3336 res = call_method(self, "__delete__", &del_str, |
| 19911 | 3337 "(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
|
3338 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
3339 res = call_method(self, "__set__", &set_str, |
| 19911 | 3340 "(OO)", target, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3341 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3342 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3343 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3344 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3345 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3346 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3347 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3348 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
|
3349 { |
|
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
|
3350 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
|
3351 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
|
3352 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3353 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3354 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3355 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3356 res = PyObject_Call(meth, args, kwds); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3357 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3358 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3359 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3360 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3361 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3362 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3363 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3364 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3365 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
|
3366 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3367 PyObject *func = PyObject_GetAttrString((PyObject *)type, "__new__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3368 PyObject *newargs, *x; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3369 int i, n; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3370 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3371 if (func == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3372 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3373 assert(PyTuple_Check(args)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3374 n = PyTuple_GET_SIZE(args); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3375 newargs = PyTuple_New(n+1); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3376 if (newargs == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3377 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3378 Py_INCREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3379 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
|
3380 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3381 x = PyTuple_GET_ITEM(args, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3382 Py_INCREF(x); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3383 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
|
3384 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3385 x = PyObject_Call(func, newargs, kwds); |
|
20195
3408d929bb94
slot_tp_new(): newargs was leaking.
Guido van Rossum <guido@python.org>
parents:
20190
diff
changeset
|
3386 Py_DECREF(newargs); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3387 Py_DECREF(func); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3388 return x; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3389 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3390 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3391 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3392 /* 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
|
3393 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
|
3394 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
|
3395 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
|
3396 __ne__ etc. all map to tp_richcompare) and one name may map to multiple |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3397 slots (e.g. __str__ affects tp_str as well as tp_repr). */ |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3398 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3399 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
|
3400 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3401 #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
|
3402 #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
|
3403 #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
|
3404 #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
|
3405 #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
|
3406 #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
|
3407 #undef UNSLOT |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3408 #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
|
3409 #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
|
3410 #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
|
3411 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3412 #define TPSLOT(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
|
3413 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, DOC} |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3414 #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
|
3415 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3416 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
|
3417 #define ETSLOT(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
|
3418 {NAME, offsetof(etype, SLOT), (void *)(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
|
3419 #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
|
3420 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
|
3421 #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
|
3422 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
|
3423 #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
|
3424 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
|
3425 #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
|
3426 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
|
3427 "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
|
3428 #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
|
3429 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
|
3430 "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
|
3431 #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
|
3432 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
|
3433 "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
|
3434 #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
|
3435 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
|
3436 "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
|
3437 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3438 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
|
3439 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
|
3440 "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
|
3441 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
|
3442 "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
|
3443 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
|
3444 "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
|
3445 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
|
3446 "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
|
3447 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
|
3448 "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
|
3449 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
|
3450 "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
|
3451 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
|
3452 "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
|
3453 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
|
3454 "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
|
3455 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
|
3456 wrap_intintobjargproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3457 "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
|
3458 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
|
3459 "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
|
3460 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
|
3461 "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
|
3462 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
|
3463 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
|
3464 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
|
3465 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
|
3466 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3467 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
|
3468 "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
|
3469 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
|
3470 wrap_binaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3471 "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
|
3472 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
|
3473 wrap_objobjargproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3474 "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
|
3475 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
|
3476 wrap_delitem, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3477 "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
|
3478 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3479 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
|
3480 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3481 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
|
3482 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3483 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
|
3484 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3485 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
|
3486 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3487 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
|
3488 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3489 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
|
3490 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3491 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
|
3492 "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3493 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
|
3494 "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3495 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
|
3496 "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3497 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
|
3498 "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3499 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
|
3500 "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
|
3501 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
|
3502 "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
|
3503 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
|
3504 "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
|
3505 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
|
3506 "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
|
3507 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
|
3508 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
|
3509 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
|
3510 "abs(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3511 UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_unaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3512 "x != 0"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3513 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
|
3514 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
|
3515 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
|
3516 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
|
3517 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
|
3518 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
|
3519 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
|
3520 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
|
3521 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
|
3522 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
|
3523 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
|
3524 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
|
3525 "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
|
3526 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
|
3527 "int(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3528 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
|
3529 "long(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3530 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
|
3531 "float(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3532 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
|
3533 "oct(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3534 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
|
3535 "hex(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3536 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
|
3537 wrap_binaryfunc, "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3538 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
|
3539 wrap_binaryfunc, "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3540 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
|
3541 wrap_binaryfunc, "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3542 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
|
3543 wrap_binaryfunc, "/"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3544 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
|
3545 wrap_binaryfunc, "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3546 IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3547 wrap_ternaryfunc, "**"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3548 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
|
3549 wrap_binaryfunc, "<<"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3550 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
|
3551 wrap_binaryfunc, ">>"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3552 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
|
3553 wrap_binaryfunc, "&"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3554 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
|
3555 wrap_binaryfunc, "^"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3556 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
|
3557 wrap_binaryfunc, "|"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3558 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
|
3559 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
|
3560 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
|
3561 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
|
3562 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
|
3563 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
|
3564 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
|
3565 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
|
3566 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3567 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
|
3568 "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
|
3569 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
|
3570 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
|
3571 "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
|
3572 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
|
3573 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
|
3574 "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
|
3575 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
|
3576 "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
|
3577 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
|
3578 "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
|
3579 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
|
3580 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
|
3581 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
|
3582 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
|
3583 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
|
3584 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
|
3585 "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
|
3586 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
|
3587 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
|
3588 "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
|
3589 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
|
3590 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
|
3591 "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
|
3592 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
|
3593 "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
|
3594 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
|
3595 "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
|
3596 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
|
3597 "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
|
3598 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
|
3599 "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
|
3600 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
|
3601 "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
|
3602 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
|
3603 "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
|
3604 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
|
3605 "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
|
3606 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
|
3607 "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
|
3608 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
|
3609 "descr.__set__(obj, value)"), |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3610 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
|
3611 "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
|
3612 "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
|
3613 PyWrapperFlag_KEYWORDS), |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
3614 TPSLOT("__new__", tp_new, slot_tp_new, 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
|
3615 {NULL} |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3616 }; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3617 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3618 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
|
3619 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
|
3620 { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3621 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
|
3622 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3623 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
|
3624 assert(offset < offsetof(etype, as_buffer)); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3625 if (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
|
3626 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
|
3627 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
|
3628 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3629 else if (offset >= offsetof(etype, as_sequence)) { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3630 ptr = (void *)type->tp_as_sequence; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3631 offset -= offsetof(etype, as_sequence); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3632 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3633 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
|
3634 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
|
3635 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
|
3636 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3637 else { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3638 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
|
3639 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3640 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
|
3641 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
|
3642 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
|
3643 } |
| 19036 | 3644 |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3645 staticforward int recurse_down_subclasses(PyTypeObject *type, |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3646 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
|
3647 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3648 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
|
3649 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
|
3650 { |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3651 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
|
3652 |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3653 for (pp = pp0; *pp; pp++) { |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3654 slotdef *p = *pp; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3655 PyObject *descr; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3656 PyWrapperDescrObject *d; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3657 void *generic = NULL, *specific = NULL; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3658 int use_generic = 0; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3659 int 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
|
3660 void **ptr = slotptr(type, offset); |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3661 if (ptr == NULL) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3662 continue; |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3663 do { |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3664 descr = _PyType_Lookup(type, p->name_strobj); |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3665 if (descr == NULL) |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3666 continue; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3667 generic = p->function; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3668 if (descr->ob_type == &PyWrapperDescr_Type) { |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3669 d = (PyWrapperDescrObject *)descr; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3670 if (d->d_base->wrapper == p->wrapper && |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3671 PyType_IsSubtype(type, d->d_type)) { |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3672 if (specific == NULL || |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3673 specific == d->d_wrapped) |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3674 specific = d->d_wrapped; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3675 else |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3676 use_generic = 1; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3677 } |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3678 } |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3679 else |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3680 use_generic = 1; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3681 } while ((++p)->offset == offset); |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3682 if (specific && !use_generic) |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3683 *ptr = specific; |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3684 else |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3685 *ptr = generic; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3686 } |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3687 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
|
3688 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3689 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3690 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
|
3691 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
|
3692 { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3693 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
|
3694 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
|
3695 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
|
3696 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3697 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
|
3698 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
|
3699 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
|
3700 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
|
3701 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
|
3702 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
|
3703 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
|
3704 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
|
3705 subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3706 if (subclass == NULL) |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3707 continue; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3708 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
|
3709 /* 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
|
3710 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
|
3711 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
|
3712 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
|
3713 continue; |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3714 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
|
3715 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
|
3716 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3717 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
|
3718 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3719 |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3720 static int |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3721 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
|
3722 { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3723 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
|
3724 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
|
3725 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
|
3726 return c; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3727 else |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3728 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
|
3729 } |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3730 |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3731 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
|
3732 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
|
3733 { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3734 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
|
3735 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
|
3736 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3737 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
|
3738 return; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3739 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
|
3740 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
|
3741 if (!p->name_strobj) |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3742 Py_FatalError("XXX ouch"); |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3743 } |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3744 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
|
3745 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
|
3746 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
|
3747 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3748 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3749 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
|
3750 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
|
3751 { |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3752 slotdef *ptrs[10]; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3753 slotdef *p; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3754 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
|
3755 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
|
3756 |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3757 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
|
3758 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
|
3759 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
|
3760 /* 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
|
3761 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
|
3762 *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
|
3763 } |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3764 *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
|
3765 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
|
3766 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
|
3767 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
|
3768 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
|
3769 --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
|
3770 *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
|
3771 } |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
3772 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
|
3773 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
3774 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3775 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
|
3776 fixup_slot_dispatchers(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3777 { |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3778 slotdef *p; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3779 PyObject *mro, *descr; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3780 PyWrapperDescrObject *d; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3781 int i, n, offset; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3782 void **ptr; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3783 void *generic, *specific; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3784 int use_generic; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3785 |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3786 init_slotdefs(); |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3787 mro = type->tp_mro; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3788 assert(PyTuple_Check(mro)); |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3789 n = PyTuple_GET_SIZE(mro); |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3790 for (p = slotdefs; p->name; ) { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3791 offset = p->offset; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3792 ptr = slotptr(type, offset); |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3793 if (!ptr) { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3794 do { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3795 ++p; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3796 } while (p->offset == offset); |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3797 continue; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3798 } |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3799 generic = specific = NULL; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3800 use_generic = 0; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3801 do { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3802 descr = NULL; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3803 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
|
3804 PyObject *b = 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
|
3805 PyObject *dict = NULL; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3806 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
|
3807 dict = ((PyTypeObject *)b)->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
|
3808 else if (PyClass_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
|
3809 dict = ((PyClassObject *)b)->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
|
3810 if (dict != NULL) { |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3811 descr = PyDict_GetItem( |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3812 dict, p->name_strobj); |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3813 if (descr != NULL) |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3814 break; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3815 } |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3816 } |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3817 if (descr == NULL) |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3818 continue; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3819 generic = p->function; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3820 if (descr->ob_type == &PyWrapperDescr_Type) { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3821 d = (PyWrapperDescrObject *)descr; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3822 if (d->d_base->wrapper == p->wrapper && |
|
20489
e09fb4848765
slot_sq_item(): ensure that self is an instance of the wrapper's
Guido van Rossum <guido@python.org>
parents:
20457
diff
changeset
|
3823 PyType_IsSubtype(type, d->d_type)) |
|
e09fb4848765
slot_sq_item(): ensure that self is an instance of the wrapper's
Guido van Rossum <guido@python.org>
parents:
20457
diff
changeset
|
3824 { |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3825 if (specific == NULL || |
|
20489
e09fb4848765
slot_sq_item(): ensure that self is an instance of the wrapper's
Guido van Rossum <guido@python.org>
parents:
20457
diff
changeset
|
3826 specific == d->d_wrapped) |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3827 specific = d->d_wrapped; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3828 else |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3829 use_generic = 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
|
3830 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3831 } |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3832 else |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3833 use_generic = 1; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3834 } while ((++p)->offset == offset); |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3835 if (specific && !use_generic) |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3836 *ptr = specific; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3837 else |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
3838 *ptr = generic; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
3839 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3840 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3841 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3842 /* 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
|
3843 dictionary with method descriptors for function slots. For each |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3844 function slot (like tp_repr) that's defined in the type, one or |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3845 more corresponding descriptors are added in the type's tp_dict |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3846 dictionary under the appropriate name (like __repr__). Some |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3847 function slots cause more than one descriptor to be added (for |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3848 example, the nb_add slot adds both __add__ and __radd__ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3849 descriptors) and some function slots compete for the same |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3850 descriptor (for example both sq_item and mp_subscript generate a |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3851 __getitem__ descriptor). This only adds new descriptors and |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3852 doesn't overwrite entries in tp_dict that were previously |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3853 defined. The descriptors contain a reference to the C function |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3854 they must call, so that it's safe if they are copied into a |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3855 subtype's __dict__ and the subtype has a different C function in |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3856 its slot -- calling the method defined by the descriptor will call |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3857 the C function that was used to create it, rather than the C |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3858 function present in the slot when it is called. (This is important |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3859 because a subtype may have a C function in the slot that calls the |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3860 method from the dictionary, and we want to avoid infinite recursion |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3861 here.) */ |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3862 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3863 static int |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3864 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
|
3865 { |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3866 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
|
3867 slotdef *p; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3868 PyObject *descr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3869 void **ptr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3870 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3871 init_slotdefs(); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3872 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
|
3873 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
|
3874 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3875 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
|
3876 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
|
3877 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3878 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
|
3879 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3880 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
|
3881 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
|
3882 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3883 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
|
3884 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3885 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
|
3886 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3887 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
|
3888 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
|
3889 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3890 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3891 return 0; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3892 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
3893 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3894 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3895 /* Cooperative 'super' */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3896 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3897 typedef struct { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3898 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
|
3899 PyTypeObject *type; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3900 PyObject *obj; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3901 } superobject; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3902 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
3903 static PyMemberDef super_members[] = { |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
3904 {"__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
|
3905 "the class invoking super()"}, |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
3906 {"__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
|
3907 "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
|
3908 {0} |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3909 }; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3910 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3911 static void |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3912 super_dealloc(PyObject *self) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3913 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3914 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3915 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
3916 _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
|
3917 Py_XDECREF(su->obj); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3918 Py_XDECREF(su->type); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3919 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
|
3920 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3921 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3922 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
|
3923 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
|
3924 { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3925 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
|
3926 |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3927 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
|
3928 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
|
3929 "<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
|
3930 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
|
3931 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
|
3932 else |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3933 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
|
3934 "<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
|
3935 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
|
3936 } |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3937 |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3938 static PyObject * |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3939 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
|
3940 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3941 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3942 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3943 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
|
3944 PyObject *mro, *res, *tmp, *dict; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3945 descrgetfunc f; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3946 int i, n; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3947 |
|
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
|
3948 mro = su->obj->ob_type->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
|
3949 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
|
3950 n = 0; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3951 else { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3952 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
|
3953 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
|
3954 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3955 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
|
3956 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
|
3957 break; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3958 } |
|
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
|
3959 if (i >= n && PyType_Check(su->obj)) { |
|
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
|
3960 mro = ((PyTypeObject *)(su->obj))->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
|
3961 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
|
3962 n = 0; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3963 else { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
3964 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
|
3965 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
|
3966 } |
|
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
|
3967 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
|
3968 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
|
3969 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
|
3970 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
|
3971 } |
|
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
|
3972 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3973 i++; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3974 res = NULL; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3975 for (; i < n; i++) { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3976 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
|
3977 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
|
3978 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
|
3979 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
|
3980 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
|
3981 else |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3982 continue; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
3983 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
|
3984 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
|
3985 Py_INCREF(res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3986 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
|
3987 if (f != NULL) { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3988 tmp = f(res, su->obj, res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3989 Py_DECREF(res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3990 res = tmp; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3991 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3992 return res; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3993 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3994 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3995 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3996 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
|
3997 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
3998 |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
3999 static int |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4000 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
|
4001 { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4002 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
|
4003 !(PyType_Check(obj) && |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4004 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
|
4005 PyErr_SetString(PyExc_TypeError, |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4006 "super(type, obj): " |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4007 "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
|
4008 return -1; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4009 } |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4010 else |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4011 return 0; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4012 } |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4013 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4014 static PyObject * |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4015 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
|
4016 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4017 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4018 superobject *new; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4019 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4020 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
|
4021 /* 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
|
4022 Py_INCREF(self); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4023 return self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4024 } |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4025 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
|
4026 /* 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
|
4027 call its type */ |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4028 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
|
4029 "OO", su->type, obj); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4030 else { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4031 /* Inline the common case */ |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4032 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
|
4033 return NULL; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4034 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
|
4035 NULL, NULL); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4036 if (new == NULL) |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4037 return NULL; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4038 Py_INCREF(su->type); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4039 Py_INCREF(obj); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4040 new->type = su->type; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4041 new->obj = obj; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4042 return (PyObject *)new; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4043 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4044 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4045 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4046 static int |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4047 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
|
4048 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4049 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
|
4050 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
|
4051 PyObject *obj = NULL; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4052 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4053 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
|
4054 return -1; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4055 if (obj == Py_None) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4056 obj = NULL; |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
4057 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
|
4058 return -1; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4059 Py_INCREF(type); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4060 Py_XINCREF(obj); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4061 su->type = type; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4062 su->obj = obj; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4063 return 0; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4064 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4065 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4066 static char super_doc[] = |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4067 "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
|
4068 "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
|
4069 "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
|
4070 "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
|
4071 "class C(B):\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4072 " def meth(self, arg):\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4073 " super(C, self).meth(arg)"; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4074 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4075 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
|
4076 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
|
4077 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4078 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
|
4079 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
|
4080 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4081 #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
|
4082 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
|
4083 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
|
4084 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
|
4085 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
|
4086 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4087 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4088 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
|
4089 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
|
4090 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4091 #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
|
4092 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4093 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
|
4094 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4095 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4096 PyTypeObject PySuper_Type = { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4097 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
|
4098 0, /* ob_size */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4099 "super", /* tp_name */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4100 sizeof(superobject), /* tp_basicsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4101 0, /* tp_itemsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4102 /* methods */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4103 super_dealloc, /* tp_dealloc */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4104 0, /* tp_print */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4105 0, /* tp_getattr */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4106 0, /* tp_setattr */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4107 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
|
4108 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
|
4109 0, /* tp_as_number */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4110 0, /* tp_as_sequence */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4111 0, /* tp_as_mapping */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4112 0, /* tp_hash */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4113 0, /* tp_call */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4114 0, /* tp_str */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4115 super_getattro, /* tp_getattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4116 0, /* tp_setattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4117 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
|
4118 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
|
4119 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
|
4120 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
|
4121 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
|
4122 0, /* tp_clear */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4123 0, /* tp_richcompare */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4124 0, /* tp_weaklistoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4125 0, /* tp_iter */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4126 0, /* tp_iternext */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4127 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
|
4128 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
|
4129 0, /* tp_getset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4130 0, /* tp_base */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4131 0, /* tp_dict */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4132 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
|
4133 0, /* tp_descr_set */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4134 0, /* tp_dictoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4135 super_init, /* tp_init */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4136 PyType_GenericAlloc, /* tp_alloc */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
4137 PyType_GenericNew, /* tp_new */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
4138 _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
|
4139 }; |
