Mercurial > cpython-lru_cache-weakref
annotate Objects/typeobject.c @ 60008:0dfd62076ded
Blocked revisions 79402,79406 via svnmerge
........
r79402 | benjamin.peterson | 2010-03-24 20:03:51 -0500 (Wed, 24 Mar 2010) | 1 line
set bsddb eol style
........
r79406 | benjamin.peterson | 2010-03-24 20:05:57 -0500 (Wed, 24 Mar 2010) | 1 line
fix eol properties on capsule files
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Thu, 25 Mar 2010 01:11:10 +0000 |
| parents | f49d24b4456e |
| children | cab14be0ada1 |
| rev | line source |
|---|---|
| 6 | 1 /* Type object implementation */ |
| 2 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
3 #include "Python.h" |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
4 #include "frameobject.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 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
7 #include <ctype.h> |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
8 |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
9 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
10 /* Support type attribute cache */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
11 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
12 /* The cache can keep references to the names alive for longer than |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
13 they normally would. This is why the maximum size is limited to |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
14 MCACHE_MAX_ATTR_SIZE, since it might be a problem if very large |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
15 strings are used as attribute names. */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
16 #define MCACHE_MAX_ATTR_SIZE 100 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
17 #define MCACHE_SIZE_EXP 10 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
18 #define MCACHE_HASH(version, name_hash) \ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
19 (((unsigned int)(version) * (unsigned int)(name_hash)) \ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
20 >> (8*sizeof(unsigned int) - MCACHE_SIZE_EXP)) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
21 #define MCACHE_HASH_METHOD(type, name) \ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
22 MCACHE_HASH((type)->tp_version_tag, \ |
|
47260
49906d432b47
#2963: fix method cache types.
Georg Brandl <georg@python.org>
parents:
46867
diff
changeset
|
23 ((PyUnicodeObject *)(name))->hash) |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
24 #define MCACHE_CACHEABLE_NAME(name) \ |
|
47260
49906d432b47
#2963: fix method cache types.
Georg Brandl <georg@python.org>
parents:
46867
diff
changeset
|
25 PyUnicode_CheckExact(name) && \ |
|
49906d432b47
#2963: fix method cache types.
Georg Brandl <georg@python.org>
parents:
46867
diff
changeset
|
26 PyUnicode_GET_SIZE(name) <= MCACHE_MAX_ATTR_SIZE |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
27 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
28 struct method_cache_entry { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
29 unsigned int version; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
30 PyObject *name; /* reference to exactly a str or None */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
31 PyObject *value; /* borrowed */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
32 }; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
33 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
34 static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP]; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
35 static unsigned int next_version_tag = 0; |
|
45026
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
36 |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
37 unsigned int |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
38 PyType_ClearCache(void) |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
39 { |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
40 Py_ssize_t i; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
41 unsigned int cur_version_tag = next_version_tag - 1; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
42 |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
43 for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
44 method_cache[i].version = 0; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
45 Py_CLEAR(method_cache[i].name); |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
46 method_cache[i].value = NULL; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
47 } |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
48 next_version_tag = 0; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
49 /* mark all version tags as invalid */ |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
50 PyType_Modified(&PyBaseObject_Type); |
|
45026
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
51 return cur_version_tag; |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45017
diff
changeset
|
52 } |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
53 |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
54 void |
|
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
55 PyType_Modified(PyTypeObject *type) |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
56 { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
57 /* Invalidate any cached data for the specified type and all |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
58 subclasses. This function is called after the base |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
59 classes, mro, or attributes of the type are altered. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
60 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
61 Invariants: |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
62 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
63 - Py_TPFLAGS_VALID_VERSION_TAG is never set if |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
64 Py_TPFLAGS_HAVE_VERSION_TAG is not set (e.g. on type |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
65 objects coming from non-recompiled extension modules) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
66 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
67 - before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type, |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
68 it must first be set on all super types. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
69 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
70 This function clears the Py_TPFLAGS_VALID_VERSION_TAG of a |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
71 type (so it must first clear it on all subclasses). The |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
72 tp_version_tag value is meaningless unless this flag is set. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
73 We don't assign new version tags eagerly, but only as |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
74 needed. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
75 */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
76 PyObject *raw, *ref; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
77 Py_ssize_t i, n; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
78 |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44654
diff
changeset
|
79 if (!PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
80 return; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
81 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
82 raw = type->tp_subclasses; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
83 if (raw != NULL) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
84 n = PyList_GET_SIZE(raw); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
85 for (i = 0; i < n; i++) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
86 ref = PyList_GET_ITEM(raw, i); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
87 ref = PyWeakref_GET_OBJECT(ref); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
88 if (ref != Py_None) { |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
89 PyType_Modified((PyTypeObject *)ref); |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
90 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
91 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
92 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
93 type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
94 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
95 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
96 static void |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
97 type_mro_modified(PyTypeObject *type, PyObject *bases) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
98 /* |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
99 Check that all base classes or elements of the mro of type are |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
100 able to be cached. This function is called after the base |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
101 classes or mro of the type are altered. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
102 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
103 Unset HAVE_VERSION_TAG and VALID_VERSION_TAG if the type |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
104 inherits from an old-style class, either directly or if it |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
105 appears in the MRO of a new-style class. No support either for |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
106 custom MROs that include types that are not officially super |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
107 types. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
108 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
109 Called from mro_internal, which will subsequently be called on |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
110 each subclass when their mro is recursively updated. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
111 */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
112 Py_ssize_t i, n; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
113 int clear = 0; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
114 |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44654
diff
changeset
|
115 if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
116 return; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
117 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
118 n = PyTuple_GET_SIZE(bases); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
119 for (i = 0; i < n; i++) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
120 PyObject *b = PyTuple_GET_ITEM(bases, i); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
121 PyTypeObject *cls; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
122 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
123 if (!PyType_Check(b) ) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
124 clear = 1; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
125 break; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
126 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
127 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
128 cls = (PyTypeObject *)b; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
129 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
130 if (!PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) || |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
131 !PyType_IsSubtype(type, cls)) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
132 clear = 1; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
133 break; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
134 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
135 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
136 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
137 if (clear) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
138 type->tp_flags &= ~(Py_TPFLAGS_HAVE_VERSION_TAG| |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
139 Py_TPFLAGS_VALID_VERSION_TAG); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
140 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
141 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
142 static int |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
143 assign_version_tag(PyTypeObject *type) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
144 { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
145 /* Ensure that the tp_version_tag is valid and set |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
146 Py_TPFLAGS_VALID_VERSION_TAG. To respect the invariant, this |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
147 must first be done on all super classes. Return 0 if this |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
148 cannot be done, 1 if Py_TPFLAGS_VALID_VERSION_TAG. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
149 */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
150 Py_ssize_t i, n; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
151 PyObject *bases; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
152 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
153 if (PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
154 return 1; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
155 if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
156 return 0; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
157 if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
158 return 0; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
159 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
160 type->tp_version_tag = next_version_tag++; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
161 /* for stress-testing: next_version_tag &= 0xFF; */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
162 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
163 if (type->tp_version_tag == 0) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
164 /* wrap-around or just starting Python - clear the whole |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
165 cache by filling names with references to Py_None. |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
166 Values are also set to NULL for added protection, as they |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
167 are borrowed reference */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
168 for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
169 method_cache[i].value = NULL; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
170 Py_XDECREF(method_cache[i].name); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
171 method_cache[i].name = Py_None; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
172 Py_INCREF(Py_None); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
173 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
174 /* mark all version tags as invalid */ |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
175 PyType_Modified(&PyBaseObject_Type); |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
176 return 1; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
177 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
178 bases = type->tp_bases; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
179 n = PyTuple_GET_SIZE(bases); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
180 for (i = 0; i < n; i++) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
181 PyObject *b = PyTuple_GET_ITEM(bases, i); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
182 assert(PyType_Check(b)); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
183 if (!assign_version_tag((PyTypeObject *)b)) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
184 return 0; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
185 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
186 type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
187 return 1; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
188 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
189 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
190 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
191 static PyMemberDef type_members[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
192 {"__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
|
193 {"__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
|
194 {"__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
|
195 {"__weakrefoffset__", T_LONG, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
196 offsetof(PyTypeObject, tp_weaklistoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
197 {"__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
|
198 {"__dictoffset__", T_LONG, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
199 offsetof(PyTypeObject, tp_dictoffset), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
200 {"__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
|
201 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
202 }; |
| 6 | 203 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
204 static PyObject * |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
205 type_name(PyTypeObject *type, void *context) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
206 { |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35742
diff
changeset
|
207 const char *s; |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
208 |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
209 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
210 PyHeapTypeObject* et = (PyHeapTypeObject*)type; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
211 |
|
36631
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
212 Py_INCREF(et->ht_name); |
|
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
213 return et->ht_name; |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
214 } |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
215 else { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
216 s = strrchr(type->tp_name, '.'); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
217 if (s == NULL) |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
218 s = type->tp_name; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
219 else |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
220 s++; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
221 return PyUnicode_FromString(s); |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
222 } |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
223 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
224 |
| 26421 | 225 static int |
| 226 type_set_name(PyTypeObject *type, PyObject *value, void *context) | |
| 227 { | |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
228 PyHeapTypeObject* et; |
|
42862
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
229 char *tp_name; |
|
43755
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
230 PyObject *tmp; |
| 26421 | 231 |
| 232 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
| 233 PyErr_Format(PyExc_TypeError, | |
| 234 "can't set %s.__name__", type->tp_name); | |
| 235 return -1; | |
| 236 } | |
| 237 if (!value) { | |
| 238 PyErr_Format(PyExc_TypeError, | |
| 239 "can't delete %s.__name__", type->tp_name); | |
| 240 return -1; | |
| 241 } | |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
242 if (!PyUnicode_Check(value)) { |
| 26421 | 243 PyErr_Format(PyExc_TypeError, |
| 244 "can only assign string to %s.__name__, not '%s'", | |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
245 type->tp_name, Py_TYPE(value)->tp_name); |
| 26421 | 246 return -1; |
| 247 } | |
|
43755
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
248 |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
249 /* Check absence of null characters */ |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
250 tmp = PyUnicode_FromStringAndSize("\0", 1); |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
251 if (tmp == NULL) |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
252 return -1; |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
253 if (PyUnicode_Contains(value, tmp) != 0) { |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
254 Py_DECREF(tmp); |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
255 PyErr_Format(PyExc_ValueError, |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
256 "__name__ must not contain null bytes"); |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
257 return -1; |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
258 } |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
259 Py_DECREF(tmp); |
|
704e6711e50d
Fixes for issue 1752184, ensuring type objects are always created
Guido van Rossum <guido@python.org>
parents:
43292
diff
changeset
|
260 |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48475
diff
changeset
|
261 tp_name = _PyUnicode_AsString(value); |
|
42862
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
262 if (tp_name == NULL) |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
263 return -1; |
| 26421 | 264 |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
265 et = (PyHeapTypeObject*)type; |
| 26421 | 266 |
| 267 Py_INCREF(value); | |
| 268 | |
|
36631
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
269 Py_DECREF(et->ht_name); |
|
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
270 et->ht_name = value; |
| 26421 | 271 |
|
42862
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
272 type->tp_name = tp_name; |
| 26421 | 273 |
| 274 return 0; | |
| 275 } | |
| 276 | |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
277 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
278 type_module(PyTypeObject *type, void *context) |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
279 { |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
280 PyObject *mod; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
281 char *s; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
282 |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
283 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
284 mod = PyDict_GetItemString(type->tp_dict, "__module__"); |
|
32323
c1fbbc3eed39
Fix for bug #966623 - classes created with type() in an exec(, {}) don't
Anthony Baxter <anthonybaxter@gmail.com>
parents:
31813
diff
changeset
|
285 if (!mod) { |
|
c1fbbc3eed39
Fix for bug #966623 - classes created with type() in an exec(, {}) don't
Anthony Baxter <anthonybaxter@gmail.com>
parents:
31813
diff
changeset
|
286 PyErr_Format(PyExc_AttributeError, "__module__"); |
|
c1fbbc3eed39
Fix for bug #966623 - classes created with type() in an exec(, {}) don't
Anthony Baxter <anthonybaxter@gmail.com>
parents:
31813
diff
changeset
|
287 return 0; |
|
c1fbbc3eed39
Fix for bug #966623 - classes created with type() in an exec(, {}) don't
Anthony Baxter <anthonybaxter@gmail.com>
parents:
31813
diff
changeset
|
288 } |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
289 Py_XINCREF(mod); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
290 return mod; |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
291 } |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
292 else { |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
293 s = strrchr(type->tp_name, '.'); |
|
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
294 if (s != NULL) |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
295 return PyUnicode_FromStringAndSize( |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
296 type->tp_name, (Py_ssize_t)(s - type->tp_name)); |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43866
diff
changeset
|
297 return PyUnicode_FromString("builtins"); |
|
26448
bddc41315336
Nudge getting __module__ and __name__ for new-style classes so that
Michael W. Hudson <mwh@python.net>
parents:
26446
diff
changeset
|
298 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
299 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
300 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
301 static int |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
302 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
|
303 { |
| 26421 | 304 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
|
305 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
306 "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
|
307 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
308 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
309 if (!value) { |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
310 PyErr_Format(PyExc_TypeError, |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
311 "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
|
312 return -1; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
313 } |
| 26421 | 314 |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
315 PyType_Modified(type); |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
316 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
317 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
|
318 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
319 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
320 static PyObject * |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
321 type_abstractmethods(PyTypeObject *type, void *context) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
322 { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
323 PyObject *mod = PyDict_GetItemString(type->tp_dict, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
324 "__abstractmethods__"); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
325 if (!mod) { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
326 PyErr_Format(PyExc_AttributeError, "__abstractmethods__"); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
327 return NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
328 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
329 Py_XINCREF(mod); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
330 return mod; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
331 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
332 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
333 static int |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
334 type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
335 { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
336 /* __abstractmethods__ should only be set once on a type, in |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
337 abc.ABCMeta.__new__, so this function doesn't do anything |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
338 special to update subclasses. |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
339 */ |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
340 int res = PyDict_SetItemString(type->tp_dict, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
341 "__abstractmethods__", value); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
342 if (res == 0) { |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
343 PyType_Modified(type); |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
344 if (value && PyObject_IsTrue(value)) { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
345 type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
346 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
347 else { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
348 type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
349 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
350 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
351 return res; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
352 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
353 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
354 static PyObject * |
| 26421 | 355 type_get_bases(PyTypeObject *type, void *context) |
| 356 { | |
| 357 Py_INCREF(type->tp_bases); | |
| 358 return type->tp_bases; | |
| 359 } | |
| 360 | |
| 361 static PyTypeObject *best_base(PyObject *); | |
| 362 static int mro_internal(PyTypeObject *); | |
| 363 static int compatible_for_assignment(PyTypeObject *, PyTypeObject *, char *); | |
| 364 static int add_subclass(PyTypeObject*, PyTypeObject*); | |
| 365 static void remove_subclass(PyTypeObject *, PyTypeObject *); | |
| 366 static void update_all_slots(PyTypeObject *); | |
| 367 | |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
368 typedef int (*update_callback)(PyTypeObject *, void *); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
369 static int update_subclasses(PyTypeObject *type, PyObject *name, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
370 update_callback callback, void *data); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
371 static int recurse_down_subclasses(PyTypeObject *type, PyObject *name, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
372 update_callback callback, void *data); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
373 |
| 26421 | 374 static int |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
375 mro_subclasses(PyTypeObject *type, PyObject* temp) |
| 26421 | 376 { |
| 377 PyTypeObject *subclass; | |
| 378 PyObject *ref, *subclasses, *old_mro; | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
379 Py_ssize_t i, n; |
| 26421 | 380 |
| 381 subclasses = type->tp_subclasses; | |
| 382 if (subclasses == NULL) | |
| 383 return 0; | |
| 384 assert(PyList_Check(subclasses)); | |
| 385 n = PyList_GET_SIZE(subclasses); | |
| 386 for (i = 0; i < n; i++) { | |
| 387 ref = PyList_GET_ITEM(subclasses, i); | |
| 388 assert(PyWeakref_CheckRef(ref)); | |
| 389 subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref); | |
| 390 assert(subclass != NULL); | |
| 391 if ((PyObject *)subclass == Py_None) | |
| 392 continue; | |
| 393 assert(PyType_Check(subclass)); | |
| 394 old_mro = subclass->tp_mro; | |
| 395 if (mro_internal(subclass) < 0) { | |
| 396 subclass->tp_mro = old_mro; | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
397 return -1; |
| 26421 | 398 } |
| 399 else { | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
400 PyObject* tuple; |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
401 tuple = PyTuple_Pack(2, subclass, old_mro); |
|
28625
07d8e0eab3af
Fix three (!) object leaks in the code for assignment to __bases__.
Guido van Rossum <guido@python.org>
parents:
28621
diff
changeset
|
402 Py_DECREF(old_mro); |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
403 if (!tuple) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
404 return -1; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
405 if (PyList_Append(temp, tuple) < 0) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
406 return -1; |
|
28625
07d8e0eab3af
Fix three (!) object leaks in the code for assignment to __bases__.
Guido van Rossum <guido@python.org>
parents:
28621
diff
changeset
|
407 Py_DECREF(tuple); |
| 26421 | 408 } |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
409 if (mro_subclasses(subclass, temp) < 0) |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
410 return -1; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
411 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
412 return 0; |
| 26421 | 413 } |
| 414 | |
| 415 static int | |
| 416 type_set_bases(PyTypeObject *type, PyObject *value, void *context) | |
| 417 { | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
418 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
419 int r = 0; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
420 PyObject *ob, *temp; |
| 26421 | 421 PyTypeObject *new_base, *old_base; |
| 422 PyObject *old_bases, *old_mro; | |
| 423 | |
| 424 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
| 425 PyErr_Format(PyExc_TypeError, | |
| 426 "can't set %s.__bases__", type->tp_name); | |
| 427 return -1; | |
| 428 } | |
| 429 if (!value) { | |
| 430 PyErr_Format(PyExc_TypeError, | |
| 431 "can't delete %s.__bases__", type->tp_name); | |
| 432 return -1; | |
| 433 } | |
| 434 if (!PyTuple_Check(value)) { | |
| 435 PyErr_Format(PyExc_TypeError, | |
| 436 "can only assign tuple to %s.__bases__, not %s", | |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
437 type->tp_name, Py_TYPE(value)->tp_name); |
| 26421 | 438 return -1; |
| 439 } | |
|
26645
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
440 if (PyTuple_GET_SIZE(value) == 0) { |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
441 PyErr_Format(PyExc_TypeError, |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
442 "can only assign non-empty tuple to %s.__bases__, not ()", |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
443 type->tp_name); |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
444 return -1; |
|
d176cbfd3765
Tighten the tests for assignment to __bases__: disallow empty tuple.
Guido van Rossum <guido@python.org>
parents:
26583
diff
changeset
|
445 } |
| 26421 | 446 for (i = 0; i < PyTuple_GET_SIZE(value); i++) { |
| 447 ob = PyTuple_GET_ITEM(value, i); | |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
448 if (!PyType_Check(ob)) { |
| 26421 | 449 PyErr_Format( |
| 450 PyExc_TypeError, | |
| 451 "%s.__bases__ must be tuple of old- or new-style classes, not '%s'", | |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
452 type->tp_name, Py_TYPE(ob)->tp_name); |
| 26421 | 453 return -1; |
| 454 } | |
|
26440
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
455 if (PyType_Check(ob)) { |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
456 if (PyType_IsSubtype((PyTypeObject*)ob, type)) { |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
457 PyErr_SetString(PyExc_TypeError, |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
458 "a __bases__ item causes an inheritance cycle"); |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
459 return -1; |
|
aa0e19b6e1e7
I had the inheritance cycle stuff backwards. Oops!
Michael W. Hudson <mwh@python.net>
parents:
26425
diff
changeset
|
460 } |
| 26421 | 461 } |
| 462 } | |
| 463 | |
| 464 new_base = best_base(value); | |
| 465 | |
| 466 if (!new_base) { | |
| 467 return -1; | |
| 468 } | |
| 469 | |
| 470 if (!compatible_for_assignment(type->tp_base, new_base, "__bases__")) | |
| 471 return -1; | |
| 472 | |
| 473 Py_INCREF(new_base); | |
| 474 Py_INCREF(value); | |
| 475 | |
| 476 old_bases = type->tp_bases; | |
| 477 old_base = type->tp_base; | |
| 478 old_mro = type->tp_mro; | |
| 479 | |
| 480 type->tp_bases = value; | |
| 481 type->tp_base = new_base; | |
| 482 | |
| 483 if (mro_internal(type) < 0) { | |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
484 goto bail; |
| 26421 | 485 } |
| 486 | |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
487 temp = PyList_New(0); |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
488 if (!temp) |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
489 goto bail; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
490 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
491 r = mro_subclasses(type, temp); |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
492 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
493 if (r < 0) { |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
494 for (i = 0; i < PyList_Size(temp); i++) { |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
495 PyTypeObject* cls; |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
496 PyObject* mro; |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
497 PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), |
|
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
498 "", 2, 2, &cls, &mro); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
499 Py_INCREF(mro); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
500 ob = cls->tp_mro; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
501 cls->tp_mro = mro; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
502 Py_DECREF(ob); |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
503 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
504 Py_DECREF(temp); |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
505 goto bail; |
|
26445
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
506 } |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
507 |
|
7421367274b4
Readjustments to the way we cope with exceptions from subclasses'
Michael W. Hudson <mwh@python.net>
parents:
26440
diff
changeset
|
508 Py_DECREF(temp); |
| 26421 | 509 |
| 510 /* any base that was in __bases__ but now isn't, we | |
| 26660 | 511 need to remove |type| from its tp_subclasses. |
| 26421 | 512 conversely, any class now in __bases__ that wasn't |
| 26660 | 513 needs to have |type| added to its subclasses. */ |
| 26421 | 514 |
| 515 /* for now, sod that: just remove from all old_bases, | |
| 516 add to all new_bases */ | |
| 517 | |
| 518 for (i = PyTuple_GET_SIZE(old_bases) - 1; i >= 0; i--) { | |
| 519 ob = PyTuple_GET_ITEM(old_bases, i); | |
| 520 if (PyType_Check(ob)) { | |
| 521 remove_subclass( | |
| 522 (PyTypeObject*)ob, type); | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 for (i = PyTuple_GET_SIZE(value) - 1; i >= 0; i--) { | |
| 527 ob = PyTuple_GET_ITEM(value, i); | |
| 528 if (PyType_Check(ob)) { | |
| 529 if (add_subclass((PyTypeObject*)ob, type) < 0) | |
| 530 r = -1; | |
| 531 } | |
| 532 } | |
| 533 | |
| 534 update_all_slots(type); | |
| 535 | |
| 536 Py_DECREF(old_bases); | |
| 537 Py_DECREF(old_base); | |
| 538 Py_DECREF(old_mro); | |
| 539 | |
| 540 return r; | |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
541 |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
542 bail: |
|
30084
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
543 Py_DECREF(type->tp_bases); |
|
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
544 Py_DECREF(type->tp_base); |
|
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
545 if (type->tp_mro != old_mro) { |
|
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
546 Py_DECREF(type->tp_mro); |
|
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
547 } |
|
d05d0ed465d8
Repair refcounting on error return from type_set_bases.
Michael W. Hudson <mwh@python.net>
parents:
29900
diff
changeset
|
548 |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
549 type->tp_bases = old_bases; |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
550 type->tp_base = old_base; |
|
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
551 type->tp_mro = old_mro; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
552 |
|
26446
7777dceb66ee
I don't know why staring at the email to python-checkins made me
Michael W. Hudson <mwh@python.net>
parents:
26445
diff
changeset
|
553 return -1; |
| 26421 | 554 } |
| 555 | |
| 556 static PyObject * | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
557 type_dict(PyTypeObject *type, void *context) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
558 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
559 if (type->tp_dict == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
560 Py_INCREF(Py_None); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
561 return Py_None; |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
562 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
563 return PyDictProxy_New(type->tp_dict); |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
564 } |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
565 |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
566 static PyObject * |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
567 type_get_doc(PyTypeObject *type, void *context) |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
568 { |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
569 PyObject *result; |
| 23118 | 570 if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) |
| 42822 | 571 return PyUnicode_FromString(type->tp_doc); |
| 23118 | 572 result = PyDict_GetItemString(type->tp_dict, "__doc__"); |
| 573 if (result == NULL) { | |
| 574 result = Py_None; | |
| 575 Py_INCREF(result); | |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
576 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
577 else if (Py_TYPE(result)->tp_descr_get) { |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
578 result = Py_TYPE(result)->tp_descr_get(result, NULL, |
|
23127
70650ae1a2cf
type_get_doc(): Squash compiler wng about incompatible ptr types.
Tim Peters <tim.peters@gmail.com>
parents:
23118
diff
changeset
|
579 (PyObject *)type); |
| 23118 | 580 } |
| 581 else { | |
| 582 Py_INCREF(result); | |
| 583 } | |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
584 return result; |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
585 } |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
586 |
|
48875
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
587 static PyObject * |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
588 type___instancecheck__(PyObject *type, PyObject *inst) |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
589 { |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
590 switch (_PyObject_RealIsInstance(inst, type)) { |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
591 case -1: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
592 return NULL; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
593 case 0: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
594 Py_RETURN_FALSE; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
595 default: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
596 Py_RETURN_TRUE; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
597 } |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
598 } |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
599 |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
600 |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
601 static PyObject * |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
602 type___subclasscheck__(PyObject *type, PyObject *inst) |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
603 { |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
604 switch (_PyObject_RealIsSubclass(inst, type)) { |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
605 case -1: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
606 return NULL; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
607 case 0: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
608 Py_RETURN_FALSE; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
609 default: |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
610 Py_RETURN_TRUE; |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
611 } |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
612 } |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
613 |
|
d6e86a96f9b3
Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
Antoine Pitrou <solipsis@pitrou.net>
parents:
48660
diff
changeset
|
614 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
615 static PyGetSetDef type_getsets[] = { |
| 26421 | 616 {"__name__", (getter)type_name, (setter)type_set_name, NULL}, |
| 617 {"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL}, | |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
618 {"__module__", (getter)type_module, (setter)type_set_module, NULL}, |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
619 {"__abstractmethods__", (getter)type_abstractmethods, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
620 (setter)type_set_abstractmethods, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
621 {"__dict__", (getter)type_dict, NULL, NULL}, |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
622 {"__doc__", (getter)type_get_doc, NULL, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
623 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
624 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
625 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
626 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
627 type_repr(PyTypeObject *type) |
| 6 | 628 { |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
629 PyObject *mod, *name, *rtn; |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
630 |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
631 mod = type_module(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
632 if (mod == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
633 PyErr_Clear(); |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
634 else if (!PyUnicode_Check(mod)) { |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
635 Py_DECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
636 mod = NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
637 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
638 name = type_name(type, NULL); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
639 if (name == NULL) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
640 return NULL; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
641 |
|
46336
56e49952d1a4
Bug #2565: The repr() of type objects now calls them 'class',
Martin v. Löwis <martin@v.loewis.de>
parents:
45549
diff
changeset
|
642 if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins")) |
|
56e49952d1a4
Bug #2565: The repr() of type objects now calls them 'class',
Martin v. Löwis <martin@v.loewis.de>
parents:
45549
diff
changeset
|
643 rtn = PyUnicode_FromFormat("<class '%U.%U'>", mod, name); |
|
20076
d9250d5b79a7
Change repr() of a new-style class to say <class 'ClassName'> rather
Guido van Rossum <guido@python.org>
parents:
20075
diff
changeset
|
644 else |
|
46336
56e49952d1a4
Bug #2565: The repr() of type objects now calls them 'class',
Martin v. Löwis <martin@v.loewis.de>
parents:
45549
diff
changeset
|
645 rtn = PyUnicode_FromFormat("<class '%s'>", 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
|
646 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
647 Py_XDECREF(mod); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
648 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
|
649 return rtn; |
| 6 | 650 } |
| 651 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
652 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
653 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
|
654 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
655 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
656 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
657 if (type->tp_new == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
658 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
659 "cannot create '%.100s' instances", |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
660 type->tp_name); |
|
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 |
|
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
|
664 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
|
665 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
|
666 /* 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
|
667 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
|
668 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
|
669 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
|
670 (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
|
671 (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
|
672 return obj; |
|
22859
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
673 /* If the returned object is not an instance of type, |
|
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
674 it won't be initialized. */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
675 if (!PyType_IsSubtype(Py_TYPE(obj), type)) |
|
22859
bbf05af3c191
- Changed new-style class instantiation so that when C's __new__
Guido van Rossum <guido@python.org>
parents:
22854
diff
changeset
|
676 return obj; |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
677 type = Py_TYPE(obj); |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
678 if (type->tp_init != NULL && |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
679 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
|
680 Py_DECREF(obj); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
681 obj = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
682 } |
|
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 return obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
685 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
686 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
687 PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
688 PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) |
|
18933
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 PyObject *obj; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
691 const size_t size = _PyObject_VAR_SIZE(type, nitems+1); |
|
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
692 /* note that we need to add one, for the sentinel */ |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
693 |
|
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
694 if (PyType_IS_GC(type)) |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
695 obj = _PyObject_GC_Malloc(size); |
|
20293
b285decf0421
Repaired the debug Windows deaths in test_descr, by allocating enough
Tim Peters <tim.peters@gmail.com>
parents:
20277
diff
changeset
|
696 else |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
697 obj = (PyObject *)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
|
698 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
699 if (obj == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
700 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
|
701 |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
702 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
|
703 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
704 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
|
705 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
|
706 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
707 if (type->tp_itemsize == 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
708 PyObject_INIT(obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
709 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
710 (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
|
711 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
712 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
|
713 _PyObject_GC_TRACK(obj); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
714 return obj; |
|
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 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
717 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
718 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
|
719 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
720 return type->tp_alloc(type, 0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
721 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
722 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
723 /* 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
|
724 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
725 static int |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
726 traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
727 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
728 Py_ssize_t i, n; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
729 PyMemberDef *mp; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
730 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
731 n = Py_SIZE(type); |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
732 mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
733 for (i = 0; i < n; i++, mp++) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
734 if (mp->type == T_OBJECT_EX) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
735 char *addr = (char *)self + mp->offset; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
736 PyObject *obj = *(PyObject **)addr; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
737 if (obj != NULL) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
738 int err = visit(obj, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
739 if (err) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
740 return err; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
741 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
742 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
743 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
744 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
745 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
746 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
747 static int |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
748 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
|
749 { |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
750 PyTypeObject *type, *base; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
751 traverseproc basetraverse; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
752 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
753 /* Find the nearest base with a different tp_traverse, |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
754 and traverse slots while we're at it */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
755 type = Py_TYPE(self); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
756 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
757 while ((basetraverse = base->tp_traverse) == subtype_traverse) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
758 if (Py_SIZE(base)) { |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
759 int err = traverse_slots(base, self, visit, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
760 if (err) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
761 return err; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
762 } |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
763 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
|
764 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
|
765 } |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
766 |
|
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
767 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
|
768 PyObject **dictptr = _PyObject_GetDictPtr(self); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
769 if (dictptr && *dictptr) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
770 Py_VISIT(*dictptr); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
771 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
772 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
773 if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
774 /* For a heaptype, the instances count as references |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
775 to the type. Traverse the type so the collector |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
776 can find cycles involving this link. */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
777 Py_VISIT(type); |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
778 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
779 if (basetraverse) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
780 return basetraverse(self, visit, arg); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
781 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
782 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
783 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
784 static void |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
785 clear_slots(PyTypeObject *type, PyObject *self) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
786 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
787 Py_ssize_t i, n; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
788 PyMemberDef *mp; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
789 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
790 n = Py_SIZE(type); |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
791 mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
792 for (i = 0; i < n; i++, mp++) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
793 if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
794 char *addr = (char *)self + mp->offset; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
795 PyObject *obj = *(PyObject **)addr; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
796 if (obj != NULL) { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
797 *(PyObject **)addr = NULL; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
798 Py_DECREF(obj); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
799 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
800 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
801 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
802 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
803 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
804 static int |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
805 subtype_clear(PyObject *self) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
806 { |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
807 PyTypeObject *type, *base; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
808 inquiry baseclear; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
809 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
810 /* Find the nearest base with a different tp_clear |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
811 and clear slots while we're at it */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
812 type = Py_TYPE(self); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
813 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
814 while ((baseclear = base->tp_clear) == subtype_clear) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
815 if (Py_SIZE(base)) |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
816 clear_slots(base, self); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
817 base = base->tp_base; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
818 assert(base); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
819 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
820 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
821 /* There's no need to clear the instance dict (if any); |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
822 the collector will call its tp_clear handler. */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
823 |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
824 if (baseclear) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
825 return baseclear(self); |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
826 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
|
827 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
828 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
829 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
830 subtype_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
831 { |
|
21246
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
832 PyTypeObject *type, *base; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
833 destructor basedealloc; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
834 |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
835 /* Extract the type; we expect it to be a heap type */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
836 type = Py_TYPE(self); |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
837 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
838 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
839 /* Test whether the type has GC exactly once */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
840 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
841 if (!PyType_IS_GC(type)) { |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
842 /* It's really rare to find a dynamic type that doesn't have |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
843 GC; it can only happen when deriving from 'object' and not |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
844 adding any slots or instance variables. This allows |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
845 certain simplifications: there's no need to call |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
846 clear_slots(), or DECREF the dict, or clear weakrefs. */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
847 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
848 /* Maybe call finalizer; exit early if resurrected */ |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
849 if (type->tp_del) { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
850 type->tp_del(self); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
851 if (self->ob_refcnt > 0) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
852 return; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
853 } |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
854 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
855 /* Find the nearest base with a different tp_dealloc */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
856 base = type; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
857 while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
858 assert(Py_SIZE(base) == 0); |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
859 base = base->tp_base; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
860 assert(base); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
861 } |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
862 |
|
53374
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
863 /* Extract the type again; tp_del may have changed it */ |
|
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
864 type = Py_TYPE(self); |
|
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
865 |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
866 /* Call the base tp_dealloc() */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
867 assert(basedealloc); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
868 basedealloc(self); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
869 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
870 /* Can't reference self beyond this point */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
871 Py_DECREF(type); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
872 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
873 /* Done */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
874 return; |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
875 } |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
876 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
877 /* We get here only if the type has GC */ |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
878 |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
879 /* UnTrack and re-Track around the trashcan macro, alas */ |
| 27717 | 880 /* See explanation at end of function for full disclosure */ |
|
24653
1ab27c1770df
Fix a subtle bug in the trashcan code I added yesterday to
Guido van Rossum <guido@python.org>
parents:
24614
diff
changeset
|
881 PyObject_GC_UnTrack(self); |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
882 ++_PyTrash_delete_nesting; |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
883 Py_TRASHCAN_SAFE_BEGIN(self); |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
884 --_PyTrash_delete_nesting; |
|
30915
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
885 /* DO NOT restore GC tracking at this point. weakref callbacks |
|
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
886 * (if any, and whether directly here or indirectly in something we |
|
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
887 * call) may trigger GC, and if self is tracked at that point, it |
|
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
888 * will look like trash to GC and GC will try to delete self again. |
|
30907
3d9b36d6ab89
SF bug 840829: weakref callbacks and gc corrupt memory.
Tim Peters <tim.peters@gmail.com>
parents:
30722
diff
changeset
|
889 */ |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
890 |
|
29442
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
891 /* Find the nearest base with a different tp_dealloc */ |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
892 base = type; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
893 while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
894 base = base->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
895 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
|
896 } |
|
cb921d483e00
The previous checkin to clear __slots__ variables did a little bit of
Guido van Rossum <guido@python.org>
parents:
21242
diff
changeset
|
897 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
898 /* If we added a weaklist, we clear it. Do this *before* calling |
|
29442
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
899 the finalizer (__del__), clearing slots, or clearing the instance |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
900 dict. */ |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
901 |
|
29308
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
902 if (type->tp_weaklistoffset && !base->tp_weaklistoffset) |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
903 PyObject_ClearWeakRefs(self); |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
904 |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
905 /* Maybe call finalizer; exit early if resurrected */ |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
906 if (type->tp_del) { |
|
30915
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
907 _PyObject_GC_TRACK(self); |
|
29308
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
908 type->tp_del(self); |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
909 if (self->ob_refcnt > 0) |
|
30915
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
910 goto endlabel; /* resurrected */ |
|
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
911 else |
|
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
912 _PyObject_GC_UNTRACK(self); |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
913 /* New weakrefs could be created during the finalizer call. |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
914 If this occurs, clear them out without calling their |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
915 finalizers since they might rely on part of the object |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
916 being finalized that has already been destroyed. */ |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
917 if (type->tp_weaklistoffset && !base->tp_weaklistoffset) { |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
918 /* Modeled after GET_WEAKREFS_LISTPTR() */ |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
919 PyWeakReference **list = (PyWeakReference **) \ |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
920 PyObject_GET_WEAKREFS_LISTPTR(self); |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
921 while (*list) |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
922 _PyWeakref_ClearRef(*list); |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
923 } |
|
29308
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
924 } |
|
ad1e67ac567b
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
Guido van Rossum <guido@python.org>
parents:
29201
diff
changeset
|
925 |
|
29442
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
926 /* Clear slots up to the nearest base with a different tp_dealloc */ |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
927 base = type; |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
928 while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
929 if (Py_SIZE(base)) |
|
29442
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
930 clear_slots(base, self); |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
931 base = base->tp_base; |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
932 assert(base); |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
933 } |
|
6fecc99afa69
- SF patch 751998 fixes an unwanted side effect of the previous fix
Guido van Rossum <guido@python.org>
parents:
29408
diff
changeset
|
934 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
935 /* 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 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
|
942 *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
|
943 } |
|
18933
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 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
946 |
|
53374
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
947 /* Extract the type again; tp_del may have changed it */ |
|
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
948 type = Py_TYPE(self); |
|
2e37190f8ea7
Merged revisions 71860 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52258
diff
changeset
|
949 |
|
30917
12c22d6b1ec0
subtype_dealloc(): Simplified overly contorted retracking logic. With
Tim Peters <tim.peters@gmail.com>
parents:
30915
diff
changeset
|
950 /* Call the base tp_dealloc(); first retrack self if |
|
12c22d6b1ec0
subtype_dealloc(): Simplified overly contorted retracking logic. With
Tim Peters <tim.peters@gmail.com>
parents:
30915
diff
changeset
|
951 * basedealloc knows about gc. |
|
12c22d6b1ec0
subtype_dealloc(): Simplified overly contorted retracking logic. With
Tim Peters <tim.peters@gmail.com>
parents:
30915
diff
changeset
|
952 */ |
|
12c22d6b1ec0
subtype_dealloc(): Simplified overly contorted retracking logic. With
Tim Peters <tim.peters@gmail.com>
parents:
30915
diff
changeset
|
953 if (PyType_IS_GC(base)) |
|
12c22d6b1ec0
subtype_dealloc(): Simplified overly contorted retracking logic. With
Tim Peters <tim.peters@gmail.com>
parents:
30915
diff
changeset
|
954 _PyObject_GC_TRACK(self); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
955 assert(basedealloc); |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
956 basedealloc(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
957 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
958 /* Can't reference self beyond this point */ |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
959 Py_DECREF(type); |
|
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
960 |
|
24653
1ab27c1770df
Fix a subtle bug in the trashcan code I added yesterday to
Guido van Rossum <guido@python.org>
parents:
24614
diff
changeset
|
961 endlabel: |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
962 ++_PyTrash_delete_nesting; |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
963 Py_TRASHCAN_SAFE_END(self); |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
964 --_PyTrash_delete_nesting; |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
965 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
966 /* Explanation of the weirdness around the trashcan macros: |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
967 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
968 Q. What do the trashcan macros do? |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
969 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
970 A. Read the comment titled "Trashcan mechanism" in object.h. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
971 For one, this explains why there must be a call to GC-untrack |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
972 before the trashcan begin macro. Without understanding the |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
973 trashcan code, the answers to the following questions don't make |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
974 sense. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
975 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
976 Q. Why do we GC-untrack before the trashcan and then immediately |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
977 GC-track again afterward? |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
978 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
979 A. In the case that the base class is GC-aware, the base class |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
980 probably GC-untracks the object. If it does that using the |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
981 UNTRACK macro, this will crash when the object is already |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
982 untracked. Because we don't know what the base class does, the |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
983 only safe thing is to make sure the object is tracked when we |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
984 call the base class dealloc. But... The trashcan begin macro |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
985 requires that the object is *untracked* before it is called. So |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
986 the dance becomes: |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
987 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
988 GC untrack |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
989 trashcan begin |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
990 GC track |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
991 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
992 Q. Why did the last question say "immediately GC-track again"? |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
993 It's nowhere near immediately. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
994 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
995 A. Because the code *used* to re-track immediately. Bad Idea. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
996 self has a refcount of 0, and if gc ever gets its hands on it |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
997 (which can happen if any weakref callback gets invoked), it |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
998 looks like trash to gc too, and gc also tries to delete self |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
999 then. But we're already deleting self. Double dealloction is |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1000 a subtle disaster. |
|
30915
8081643c373f
subtype_dealloc(): A more complete fix for critical bug 840829 +
Tim Peters <tim.peters@gmail.com>
parents:
30907
diff
changeset
|
1001 |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1002 Q. Why the bizarre (net-zero) manipulation of |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1003 _PyTrash_delete_nesting around the trashcan macros? |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1004 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1005 A. Some base classes (e.g. list) also use the trashcan mechanism. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1006 The following scenario used to be possible: |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1007 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1008 - suppose the trashcan level is one below the trashcan limit |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1009 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1010 - subtype_dealloc() is called |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1011 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1012 - the trashcan limit is not yet reached, so the trashcan level |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1013 is incremented and the code between trashcan begin and end is |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1014 executed |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1015 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1016 - this destroys much of the object's contents, including its |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1017 slots and __dict__ |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1018 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1019 - basedealloc() is called; this is really list_dealloc(), or |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1020 some other type which also uses the trashcan macros |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1021 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1022 - the trashcan limit is now reached, so the object is put on the |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1023 trashcan's to-be-deleted-later list |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1024 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1025 - basedealloc() returns |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1026 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1027 - subtype_dealloc() decrefs the object's type |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1028 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1029 - subtype_dealloc() returns |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1030 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1031 - later, the trashcan code starts deleting the objects from its |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1032 to-be-deleted-later list |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1033 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1034 - subtype_dealloc() is called *AGAIN* for the same object |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1035 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1036 - at the very least (if the destroyed slots and __dict__ don't |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1037 cause problems) the object's type gets decref'ed a second |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1038 time, which is *BAD*!!! |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1039 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1040 The remedy is to make sure that if the code between trashcan |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1041 begin and end in subtype_dealloc() is called, the code between |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1042 trashcan begin and end in basedealloc() will also be called. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1043 This is done by decrementing the level after passing into the |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1044 trashcan block, and incrementing it just before leaving the |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1045 block. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1046 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1047 But now it's possible that a chain of objects consisting solely |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1048 of objects whose deallocator is subtype_dealloc() will defeat |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1049 the trashcan mechanism completely: the decremented level means |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1050 that the effective level never reaches the limit. Therefore, we |
|
27707
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1051 *increment* the level *before* entering the trashcan block, and |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1052 matchingly decrement it after leaving. This means the trashcan |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1053 code will trigger a little early, but that's no big deal. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1054 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1055 Q. Are there any live examples of code in need of all this |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1056 complexity? |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1057 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1058 A. Yes. See SF bug 668433 for code that crashed (when Python was |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1059 compiled in debug mode) before the trashcan level manipulations |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1060 were added. For more discussion, see SF patches 581742, 575073 |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1061 and bug 574207. |
|
e0fa52067dbe
Fix for SF #668433. I'm not explaining it here; ample comments are in
Guido van Rossum <guido@python.org>
parents:
27132
diff
changeset
|
1062 */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1063 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1064 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1065 static PyTypeObject *solid_base(PyTypeObject *type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1066 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1067 /* type test with subclassing support */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1068 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1069 int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1070 PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) |
|
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 PyObject *mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1073 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1074 mro = a->tp_mro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1075 if (mro != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1076 /* Deal with multiple inheritance without recursion |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1077 by walking the MRO tuple */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1078 Py_ssize_t i, n; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1079 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1080 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1081 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1082 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
|
1083 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1084 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1085 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1086 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1087 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1088 /* 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
|
1089 do { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1090 if (a == b) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1091 return 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1092 a = a->tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1093 } while (a != NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1094 return b == &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1095 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1096 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1097 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1098 /* 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
|
1099 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
|
1100 (so we can't use PyObject_GetAttr) but still binding |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1101 it to the instance. The arguments are the object, |
|
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
|
1102 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
|
1103 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
|
1104 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1105 Two variants: |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1106 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1107 - 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
|
1108 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
|
1109 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1110 - lookup_method() always raises an exception upon errors. |
|
53905
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1111 |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1112 - _PyObject_LookupSpecial() exported for the benefit of other places. |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1113 */ |
|
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
|
1114 |
|
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
|
1115 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1116 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
|
1117 { |
|
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
|
1118 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
|
1119 |
|
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
|
1120 if (*attrobj == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
1121 *attrobj = PyUnicode_InternFromString(attrstr); |
|
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
|
1122 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
|
1123 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
|
1124 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1125 res = _PyType_Lookup(Py_TYPE(self), *attrobj); |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1126 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
|
1127 descrgetfunc f; |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1128 if ((f = Py_TYPE(res)->tp_descr_get) == 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
|
1129 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
|
1130 else |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1131 res = f(res, self, (PyObject *)(Py_TYPE(self))); |
|
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
|
1132 } |
|
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
|
1133 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
|
1134 } |
|
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
|
1135 |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1136 static PyObject * |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1137 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
|
1138 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 return res; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1143 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1144 |
|
53905
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1145 PyObject * |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1146 _PyObject_LookupSpecial(PyObject *self, char *attrstr, PyObject **attrobj) |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1147 { |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1148 return lookup_maybe(self, attrstr, attrobj); |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1149 } |
|
2993f049e2c9
Merged revisions 72461 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53374
diff
changeset
|
1150 |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1151 /* A variation of PyObject_CallMethod that uses lookup_method() |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1152 instead of PyObject_GetAttrString(). This uses the same convention |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1153 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
|
1154 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
1155 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
|
1156 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
|
1157 { |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1158 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
|
1159 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
|
1160 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
|
1161 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
1162 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
|
1163 if (func == NULL) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1164 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1165 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
|
1166 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
|
1167 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1168 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1169 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1170 if (format && *format) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1171 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
|
1172 else |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1173 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
|
1174 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1175 va_end(va); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1176 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1177 if (args == NULL) |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1178 return NULL; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1179 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1180 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
|
1181 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
|
1182 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1183 Py_DECREF(args); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1184 Py_DECREF(func); |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1185 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1186 return retval; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1187 } |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1188 |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1189 /* 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
|
1190 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20586
diff
changeset
|
1191 static PyObject * |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1192 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
|
1193 { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1194 va_list va; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1195 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
|
1196 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
|
1197 |
|
20225
aa18c0ecc4fb
call_method(), call_maybe(): fix a performance bug: the argument
Guido van Rossum <guido@python.org>
parents:
20220
diff
changeset
|
1198 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
|
1199 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
|
1200 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
|
1201 if (!PyErr_Occurred()) { |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1202 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
|
1203 return Py_NotImplemented; |
|
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
1204 } |
| 19911 | 1205 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
|
1206 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1207 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1208 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
|
1209 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
|
1210 else |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1211 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
|
1212 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1213 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
|
1214 |
| 19911 | 1215 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
|
1216 return NULL; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1217 |
| 19911 | 1218 assert(PyTuple_Check(args)); |
| 1219 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
|
1220 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1221 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
|
1222 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
|
1223 |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1224 return retval; |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1225 } |
|
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
1226 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1227 /* |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1228 Method resolution order algorithm C3 described in |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1229 "A Monotonic Superclass Linearization for Dylan", |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1230 by Kim Barrett, Bob Cassel, Paul Haahr, |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1231 David A. Moon, Keith Playford, and P. Tucker Withington. |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1232 (OOPSLA 1996) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1233 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1234 Some notes about the rules implied by C3: |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1235 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1236 No duplicate bases. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1237 It isn't legal to repeat a class in a list of base classes. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1238 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1239 The next three properties are the 3 constraints in "C3". |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1240 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1241 Local precendece order. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1242 If A precedes B in C's MRO, then A will precede B in the MRO of all |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1243 subclasses of C. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1244 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1245 Monotonicity. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1246 The MRO of a class must be an extension without reordering of the |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1247 MRO of each of its superclasses. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1248 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1249 Extended Precedence Graph (EPG). |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1250 Linearization is consistent if there is a path in the EPG from |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1251 each class to all its successors in the linearization. See |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1252 the paper for definition of EPG. |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1253 */ |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1254 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1255 static int |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1256 tail_contains(PyObject *list, int whence, PyObject *o) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1257 Py_ssize_t j, size; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1258 size = PyList_GET_SIZE(list); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1259 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1260 for (j = whence+1; j < size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1261 if (PyList_GET_ITEM(list, j) == o) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1262 return 1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1263 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1264 return 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1265 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1266 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1267 static PyObject * |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1268 class_name(PyObject *cls) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1269 { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1270 PyObject *name = PyObject_GetAttrString(cls, "__name__"); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1271 if (name == NULL) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1272 PyErr_Clear(); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1273 Py_XDECREF(name); |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43755
diff
changeset
|
1274 name = PyObject_Repr(cls); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1275 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1276 if (name == NULL) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1277 return NULL; |
|
42019
f5b65731bd6c
Expect unicode in class_name.
Martin v. Löwis <martin@v.loewis.de>
parents:
42013
diff
changeset
|
1278 if (!PyUnicode_Check(name)) { |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1279 Py_DECREF(name); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1280 return NULL; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1281 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1282 return name; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1283 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1284 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1285 static int |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1286 check_duplicates(PyObject *list) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1287 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1288 Py_ssize_t i, j, n; |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1289 /* Let's use a quadratic time algorithm, |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1290 assuming that the bases lists is short. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1291 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1292 n = PyList_GET_SIZE(list); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1293 for (i = 0; i < n; i++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1294 PyObject *o = PyList_GET_ITEM(list, i); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1295 for (j = i + 1; j < n; j++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1296 if (PyList_GET_ITEM(list, j) == o) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1297 o = class_name(o); |
|
59538
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1298 if (o != NULL) { |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1299 PyErr_Format(PyExc_TypeError, |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1300 "duplicate base class %U", |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1301 o); |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1302 Py_DECREF(o); |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1303 } else { |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1304 PyErr_SetString(PyExc_TypeError, |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1305 "duplicate base class"); |
|
f49d24b4456e
Issue #6697: use %U format instead of _PyUnicode_AsString(), because
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57273
diff
changeset
|
1306 } |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1307 return -1; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1308 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1309 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1310 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1311 return 0; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1312 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1313 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1314 /* Raise a TypeError for an MRO order disagreement. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1315 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1316 It's hard to produce a good error message. In the absence of better |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1317 insight into error reporting, report the classes that were candidates |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1318 to be put next into the MRO. There is some conflict between the |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1319 order in which they should be put in the MRO, but it's hard to |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1320 diagnose what constraint can't be satisfied. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1321 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1322 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1323 static void |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1324 set_mro_error(PyObject *to_merge, int *remain) |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1325 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1326 Py_ssize_t i, n, off, to_merge_size; |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1327 char buf[1000]; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1328 PyObject *k, *v; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1329 PyObject *set = PyDict_New(); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1330 if (!set) return; |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1331 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1332 to_merge_size = PyList_GET_SIZE(to_merge); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1333 for (i = 0; i < to_merge_size; i++) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1334 PyObject *L = PyList_GET_ITEM(to_merge, i); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1335 if (remain[i] < PyList_GET_SIZE(L)) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1336 PyObject *c = PyList_GET_ITEM(L, remain[i]); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1337 if (PyDict_SetItem(set, c, Py_None) < 0) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1338 Py_DECREF(set); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1339 return; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1340 } |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1341 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1342 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1343 n = PyDict_Size(set); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1344 |
|
28514
9400504cb0b2
SF bug #699934: Obscure error message
Raymond Hettinger <python@rcn.com>
parents:
28403
diff
changeset
|
1345 off = PyOS_snprintf(buf, sizeof(buf), "Cannot create a \ |
|
9400504cb0b2
SF bug #699934: Obscure error message
Raymond Hettinger <python@rcn.com>
parents:
28403
diff
changeset
|
1346 consistent method resolution\norder (MRO) for bases"); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1347 i = 0; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1348 while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) { |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1349 PyObject *name = class_name(k); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1350 off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48475
diff
changeset
|
1351 name ? _PyUnicode_AsString(name) : "?"); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1352 Py_XDECREF(name); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1353 if (--n && (size_t)(off+1) < sizeof(buf)) { |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1354 buf[off++] = ','; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1355 buf[off] = '\0'; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1356 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1357 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1358 PyErr_SetString(PyExc_TypeError, buf); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1359 Py_DECREF(set); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1360 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1361 |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1362 static int |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1363 pmerge(PyObject *acc, PyObject* to_merge) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1364 Py_ssize_t i, j, to_merge_size, empty_cnt; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1365 int *remain; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1366 int ok; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1367 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1368 to_merge_size = PyList_GET_SIZE(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1369 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1370 /* remain stores an index into each sublist of to_merge. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1371 remain[i] is the index of the next base in to_merge[i] |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1372 that is not included in acc. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1373 */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
1374 remain = (int *)PyMem_MALLOC(SIZEOF_INT*to_merge_size); |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1375 if (remain == NULL) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1376 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1377 for (i = 0; i < to_merge_size; i++) |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1378 remain[i] = 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1379 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1380 again: |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1381 empty_cnt = 0; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1382 for (i = 0; i < to_merge_size; i++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1383 PyObject *candidate; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1384 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1385 PyObject *cur_list = PyList_GET_ITEM(to_merge, i); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1386 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1387 if (remain[i] >= PyList_GET_SIZE(cur_list)) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1388 empty_cnt++; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1389 continue; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1390 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1391 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1392 /* Choose next candidate for MRO. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1393 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1394 The input sequences alone can determine the choice. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1395 If not, choose the class which appears in the MRO |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1396 of the earliest direct superclass of the new class. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1397 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1398 |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1399 candidate = PyList_GET_ITEM(cur_list, remain[i]); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1400 for (j = 0; j < to_merge_size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1401 PyObject *j_lst = PyList_GET_ITEM(to_merge, j); |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1402 if (tail_contains(j_lst, remain[j], candidate)) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1403 goto skip; /* continue outer loop */ |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1404 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1405 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1406 ok = PyList_Append(acc, candidate); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1407 if (ok < 0) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1408 PyMem_Free(remain); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1409 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1410 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1411 for (j = 0; j < to_merge_size; j++) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1412 PyObject *j_lst = PyList_GET_ITEM(to_merge, j); |
|
26964
5df7a284eaf4
Fix an out-of-bound index in pmerge() discovered by Zooko (SF bug
Guido van Rossum <guido@python.org>
parents:
26660
diff
changeset
|
1413 if (remain[j] < PyList_GET_SIZE(j_lst) && |
|
5df7a284eaf4
Fix an out-of-bound index in pmerge() discovered by Zooko (SF bug
Guido van Rossum <guido@python.org>
parents:
26660
diff
changeset
|
1414 PyList_GET_ITEM(j_lst, remain[j]) == candidate) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1415 remain[j]++; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1416 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1417 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1418 goto again; |
|
26227
529719a5350e
Repaired illegal syntax most compilers probably let slide (but MSVC
Tim Peters <tim.peters@gmail.com>
parents:
26222
diff
changeset
|
1419 skip: ; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1420 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1421 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1422 if (empty_cnt == to_merge_size) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1423 PyMem_FREE(remain); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1424 return 0; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1425 } |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1426 set_mro_error(to_merge, remain); |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1427 PyMem_FREE(remain); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1428 return -1; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1429 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1430 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1431 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1432 mro_implementation(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1433 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1434 Py_ssize_t i, n; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1435 int ok; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1436 PyObject *bases, *result; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1437 PyObject *to_merge, *bases_aslist; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1438 |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44654
diff
changeset
|
1439 if (type->tp_dict == NULL) { |
|
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44654
diff
changeset
|
1440 if (PyType_Ready(type) < 0) |
|
23903
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1441 return NULL; |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1442 } |
|
066f8938071a
Patch from SF bug 570483 (Tim Northover).
Guido van Rossum <guido@python.org>
parents:
23856
diff
changeset
|
1443 |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1444 /* Find a superclass linearization that honors the constraints |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1445 of the explicit lists of bases and the constraints implied by |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
1446 each base class. |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1447 |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1448 to_merge is a list of lists, where each list is a superclass |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1449 linearization implied by a base class. The last element of |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1450 to_merge is the declared list of bases. |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1451 */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1452 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1453 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1454 n = PyTuple_GET_SIZE(bases); |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1455 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1456 to_merge = PyList_New(n+1); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1457 if (to_merge == NULL) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1458 return NULL; |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1459 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1460 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
|
1461 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
|
1462 PyObject *parentMRO; |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
1463 parentMRO = PySequence_List(((PyTypeObject*)base)->tp_mro); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1464 if (parentMRO == NULL) { |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1465 Py_DECREF(to_merge); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1466 return NULL; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1467 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1468 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1469 PyList_SET_ITEM(to_merge, i, parentMRO); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1470 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1471 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1472 bases_aslist = PySequence_List(bases); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1473 if (bases_aslist == NULL) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1474 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1475 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1476 } |
|
26410
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1477 /* This is just a basic sanity check. */ |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1478 if (check_duplicates(bases_aslist) < 0) { |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1479 Py_DECREF(to_merge); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1480 Py_DECREF(bases_aslist); |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1481 return NULL; |
|
26918e2efd17
A tweaked version of Jeremy's patch #642489, to produce better error
Guido van Rossum <guido@python.org>
parents:
26227
diff
changeset
|
1482 } |
|
26222
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1483 PyList_SET_ITEM(to_merge, n, bases_aslist); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1484 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1485 result = Py_BuildValue("[O]", (PyObject *)type); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1486 if (result == NULL) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1487 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1488 return NULL; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1489 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1490 |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1491 ok = pmerge(result, to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1492 Py_DECREF(to_merge); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1493 if (ok < 0) { |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1494 Py_DECREF(result); |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1495 return NULL; |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1496 } |
|
c95190532c0c
Use the new C3 MRO algorithm, implemented by Samuele Pedroni (SF patch
Guido van Rossum <guido@python.org>
parents:
25853
diff
changeset
|
1497 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1498 return result; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1499 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1500 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1501 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
|
1502 mro_external(PyObject *self) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1503 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1504 PyTypeObject *type = (PyTypeObject *)self; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1505 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1506 return mro_implementation(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1507 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1508 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1509 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1510 mro_internal(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1511 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1512 PyObject *mro, *result, *tuple; |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1513 int checkit = 0; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1514 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1515 if (Py_TYPE(type) == &PyType_Type) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1516 result = mro_implementation(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1517 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1518 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
|
1519 static PyObject *mro_str; |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1520 checkit = 1; |
|
19535
9753608e2d57
Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
Guido van Rossum <guido@python.org>
parents:
19476
diff
changeset
|
1521 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
|
1522 if (mro == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1523 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1524 result = PyObject_CallObject(mro, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1525 Py_DECREF(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1526 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1527 if (result == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1528 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1529 tuple = PySequence_Tuple(result); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1530 Py_DECREF(result); |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1531 if (tuple == NULL) |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1532 return -1; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1533 if (checkit) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1534 Py_ssize_t i, len; |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1535 PyObject *cls; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1536 PyTypeObject *solid; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1537 |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1538 solid = solid_base(type); |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1539 |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1540 len = PyTuple_GET_SIZE(tuple); |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1541 |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1542 for (i = 0; i < len; i++) { |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1543 PyTypeObject *t; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1544 cls = PyTuple_GET_ITEM(tuple, i); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
1545 if (!PyType_Check(cls)) { |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1546 PyErr_Format(PyExc_TypeError, |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1547 "mro() returned a non-class ('%.500s')", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1548 Py_TYPE(cls)->tp_name); |
|
36169
652429c4f2a4
Fix ref/memory leak introduced in rev 41845.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36153
diff
changeset
|
1549 Py_DECREF(tuple); |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1550 return -1; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1551 } |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1552 t = (PyTypeObject*)cls; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1553 if (!PyType_IsSubtype(solid, solid_base(t))) { |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1554 PyErr_Format(PyExc_TypeError, |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1555 "mro() returned base with unsuitable layout ('%.500s')", |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1556 t->tp_name); |
|
36169
652429c4f2a4
Fix ref/memory leak introduced in rev 41845.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36153
diff
changeset
|
1557 Py_DECREF(tuple); |
|
36153
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1558 return -1; |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1559 } |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1560 } |
|
042eb3d1ce3f
SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
Armin Rigo <arigo@tunes.org>
parents:
36150
diff
changeset
|
1561 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1562 type->tp_mro = tuple; |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1563 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1564 type_mro_modified(type, type->tp_mro); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1565 /* corner case: the old-style super class might have been hidden |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1566 from the custom MRO */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1567 type_mro_modified(type, type->tp_bases); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1568 |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
1569 PyType_Modified(type); |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
1570 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1571 return 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 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1574 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1575 /* 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
|
1576 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
|
1577 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1578 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1579 best_base(PyObject *bases) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1580 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1581 Py_ssize_t i, n; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1582 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
|
1583 PyObject *base_proto; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1584 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1585 assert(PyTuple_Check(bases)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1586 n = PyTuple_GET_SIZE(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1587 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
|
1588 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
|
1589 winner = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1590 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
|
1591 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
|
1592 if (!PyType_Check(base_proto)) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1593 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1594 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1595 "bases must be types"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1596 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1597 } |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1598 base_i = (PyTypeObject *)base_proto; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1599 if (base_i->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
1600 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
|
1601 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1602 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1603 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
|
1604 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
|
1605 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
|
1606 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
|
1607 } |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
1608 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
|
1609 ; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1610 else if (PyType_IsSubtype(candidate, winner)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1611 winner = candidate; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1612 base = base_i; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1613 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1614 else { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1615 PyErr_SetString( |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1616 PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1617 "multiple bases have " |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1618 "instance lay-out conflict"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1619 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1620 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1621 } |
| 21404 | 1622 if (base == NULL) |
| 1623 PyErr_SetString(PyExc_TypeError, | |
| 1624 "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
|
1625 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1626 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1627 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1628 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1629 extra_ivars(PyTypeObject *type, PyTypeObject *base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1630 { |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
1631 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
|
1632 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
|
1633 |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1634 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
|
1635 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
|
1636 /* If itemsize is involved, stricter rules */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1637 return t_size != b_size || |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1638 type->tp_itemsize != base->tp_itemsize; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1639 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1640 if (type->tp_weaklistoffset && base->tp_weaklistoffset == 0 && |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1641 type->tp_weaklistoffset + sizeof(PyObject *) == t_size && |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1642 type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1643 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1644 if (type->tp_dictoffset && base->tp_dictoffset == 0 && |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1645 type->tp_dictoffset + sizeof(PyObject *) == t_size && |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1646 type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1647 t_size -= sizeof(PyObject *); |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1648 |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1649 return t_size != b_size; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1650 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1651 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1652 static PyTypeObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1653 solid_base(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1654 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1655 PyTypeObject *base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1656 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1657 if (type->tp_base) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1658 base = solid_base(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1659 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1660 base = &PyBaseObject_Type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1661 if (extra_ivars(type, base)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1662 return type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1663 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1664 return base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1665 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1666 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1667 static void object_dealloc(PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1668 static int object_init(PyObject *, PyObject *, PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1669 static int update_slot(PyTypeObject *, PyObject *); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
1670 static void fixup_slot_dispatchers(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1671 |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1672 /* |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1673 * Helpers for __dict__ descriptor. We don't want to expose the dicts |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1674 * inherited from various builtin types. The builtin base usually provides |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1675 * its own __dict__ descriptor, so we use that when we can. |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1676 */ |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1677 static PyTypeObject * |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1678 get_builtin_base_with_dict(PyTypeObject *type) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1679 { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1680 while (type->tp_base != NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1681 if (type->tp_dictoffset != 0 && |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1682 !(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1683 return type; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1684 type = type->tp_base; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1685 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1686 return NULL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1687 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1688 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1689 static PyObject * |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1690 get_dict_descriptor(PyTypeObject *type) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1691 { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1692 static PyObject *dict_str; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1693 PyObject *descr; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1694 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1695 if (dict_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
1696 dict_str = PyUnicode_InternFromString("__dict__"); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1697 if (dict_str == NULL) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1698 return NULL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1699 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1700 descr = _PyType_Lookup(type, dict_str); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1701 if (descr == NULL || !PyDescr_IsData(descr)) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1702 return NULL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1703 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1704 return descr; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1705 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1706 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1707 static void |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1708 raise_dict_descr_error(PyObject *obj) |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1709 { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1710 PyErr_Format(PyExc_TypeError, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1711 "this __dict__ descriptor does not support " |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1712 "'%.200s' objects", Py_TYPE(obj)->tp_name); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1713 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1714 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1715 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
|
1716 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
|
1717 { |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1718 PyObject **dictptr; |
|
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
|
1719 PyObject *dict; |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1720 PyTypeObject *base; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1721 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1722 base = get_builtin_base_with_dict(Py_TYPE(obj)); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1723 if (base != NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1724 descrgetfunc func; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1725 PyObject *descr = get_dict_descriptor(base); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1726 if (descr == NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1727 raise_dict_descr_error(obj); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1728 return NULL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1729 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1730 func = Py_TYPE(descr)->tp_descr_get; |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1731 if (func == NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1732 raise_dict_descr_error(obj); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1733 return NULL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1734 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1735 return func(descr, obj, (PyObject *)(Py_TYPE(obj))); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1736 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1737 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1738 dictptr = _PyObject_GetDictPtr(obj); |
|
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
|
1739 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
|
1740 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
|
1741 "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
|
1742 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
|
1743 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1744 dict = *dictptr; |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1745 if (dict == NULL) |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1746 *dictptr = dict = PyDict_New(); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1747 Py_XINCREF(dict); |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
1748 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
|
1749 } |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1750 |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1751 static int |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1752 subtype_setdict(PyObject *obj, PyObject *value, void *context) |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1753 { |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1754 PyObject **dictptr; |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1755 PyObject *dict; |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1756 PyTypeObject *base; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1757 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1758 base = get_builtin_base_with_dict(Py_TYPE(obj)); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1759 if (base != NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1760 descrsetfunc func; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1761 PyObject *descr = get_dict_descriptor(base); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1762 if (descr == NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1763 raise_dict_descr_error(obj); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1764 return -1; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1765 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1766 func = Py_TYPE(descr)->tp_descr_set; |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1767 if (func == NULL) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1768 raise_dict_descr_error(obj); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1769 return -1; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1770 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1771 return func(descr, obj, value); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1772 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1773 |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1774 dictptr = _PyObject_GetDictPtr(obj); |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1775 if (dictptr == NULL) { |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1776 PyErr_SetString(PyExc_AttributeError, |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1777 "This object has no __dict__"); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1778 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1779 } |
|
21235
b782490da7f0
At the PythonLabs meeting someone mentioned it would make Jim really
Guido van Rossum <guido@python.org>
parents:
21192
diff
changeset
|
1780 if (value != NULL && !PyDict_Check(value)) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1781 PyErr_Format(PyExc_TypeError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1782 "__dict__ must be set to a dictionary, " |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1783 "not a '%.200s'", Py_TYPE(value)->tp_name); |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1784 return -1; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1785 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1786 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
|
1787 Py_XINCREF(value); |
|
20681
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1788 *dictptr = value; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1789 Py_XDECREF(dict); |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1790 return 0; |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1791 } |
|
a0f1c2d2ac9e
Allow assignment to newinstance.__dict__.
Guido van Rossum <guido@python.org>
parents:
20599
diff
changeset
|
1792 |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1793 static PyObject * |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1794 subtype_getweakref(PyObject *obj, void *context) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1795 { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1796 PyObject **weaklistptr; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1797 PyObject *result; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1798 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1799 if (Py_TYPE(obj)->tp_weaklistoffset == 0) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1800 PyErr_SetString(PyExc_AttributeError, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1801 "This object has no __weakref__"); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1802 return NULL; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1803 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1804 assert(Py_TYPE(obj)->tp_weaklistoffset > 0); |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1805 assert(Py_TYPE(obj)->tp_weaklistoffset + sizeof(PyObject *) <= |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1806 (size_t)(Py_TYPE(obj)->tp_basicsize)); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1807 weaklistptr = (PyObject **) |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1808 ((char *)obj + Py_TYPE(obj)->tp_weaklistoffset); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1809 if (*weaklistptr == NULL) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1810 result = Py_None; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1811 else |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1812 result = *weaklistptr; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1813 Py_INCREF(result); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1814 return result; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1815 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1816 |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1817 /* Three variants on the subtype_getsets list. */ |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1818 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1819 static PyGetSetDef subtype_getsets_full[] = { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1820 {"__dict__", subtype_dict, subtype_setdict, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
1821 PyDoc_STR("dictionary for instance variables (if defined)")}, |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1822 {"__weakref__", subtype_getweakref, NULL, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
1823 PyDoc_STR("list of weak references to the object (if defined)")}, |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1824 {0} |
|
19616
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1825 }; |
|
337b53679c73
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
Guido van Rossum <guido@python.org>
parents:
19595
diff
changeset
|
1826 |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1827 static PyGetSetDef subtype_getsets_dict_only[] = { |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1828 {"__dict__", subtype_dict, subtype_setdict, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1829 PyDoc_STR("dictionary for instance variables (if defined)")}, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1830 {0} |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1831 }; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1832 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1833 static PyGetSetDef subtype_getsets_weakref_only[] = { |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1834 {"__weakref__", subtype_getweakref, NULL, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1835 PyDoc_STR("list of weak references to the object (if defined)")}, |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1836 {0} |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1837 }; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
1838 |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1839 static int |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1840 valid_identifier(PyObject *s) |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1841 { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
1842 if (!PyUnicode_Check(s)) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1843 PyErr_Format(PyExc_TypeError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1844 "__slots__ items must be strings, not '%.200s'", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1845 Py_TYPE(s)->tp_name); |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1846 return 0; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1847 } |
| 43074 | 1848 if (!PyUnicode_IsIdentifier(s)) { |
| 1849 PyErr_SetString(PyExc_TypeError, | |
| 1850 "__slots__ must be identifiers"); | |
| 1851 return 0; | |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1852 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1853 return 1; |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1854 } |
|
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
1855 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1856 /* Forward */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1857 static int |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1858 object_init(PyObject *self, PyObject *args, PyObject *kwds); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1859 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1860 static int |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1861 type_init(PyObject *cls, PyObject *args, PyObject *kwds) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1862 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1863 int res; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1864 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1865 assert(args != NULL && PyTuple_Check(args)); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1866 assert(kwds == NULL || PyDict_Check(kwds)); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1867 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1868 if (kwds != NULL && PyDict_Check(kwds) && PyDict_Size(kwds) != 0) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1869 PyErr_SetString(PyExc_TypeError, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1870 "type.__init__() takes no keyword arguments"); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1871 return -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1872 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1873 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1874 if (args != NULL && PyTuple_Check(args) && |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1875 (PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1876 PyErr_SetString(PyExc_TypeError, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1877 "type.__init__() takes 1 or 3 arguments"); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1878 return -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1879 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1880 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1881 /* Call object.__init__(self) now. */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1882 /* XXX Could call super(type, cls).__init__() but what's the point? */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1883 args = PyTuple_GetSlice(args, 0, 0); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1884 res = object_init(cls, args, NULL); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1885 Py_DECREF(args); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1886 return res; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1887 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
1888 |
|
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
|
1889 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1890 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
|
1891 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1892 PyObject *name, *bases, *dict; |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36631
diff
changeset
|
1893 static char *kwlist[] = {"name", "bases", "dict", 0}; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
1894 PyObject *slots, *tmp, *newslots; |
|
19329
f93c16c10a55
type_new(): only defer to the winning metatype if it's different from
Guido van Rossum <guido@python.org>
parents:
19316
diff
changeset
|
1895 PyTypeObject *type, *base, *tmptype, *winner; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
1896 PyHeapTypeObject *et; |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
1897 PyMemberDef *mp; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1898 Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1899 int j, may_add_dict, may_add_weak; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1900 |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1901 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
|
1902 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
|
1903 |
|
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
|
1904 /* 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
|
1905 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1906 const Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
1907 const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds); |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1908 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1909 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
|
1910 PyObject *x = PyTuple_GET_ITEM(args, 0); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1911 Py_INCREF(Py_TYPE(x)); |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1912 return (PyObject *) Py_TYPE(x); |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1913 } |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1914 |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1915 /* 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
|
1916 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
|
1917 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
|
1918 if (nargs + nkwds != 3) { |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1919 PyErr_SetString(PyExc_TypeError, |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1920 "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
|
1921 return NULL; |
|
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20681
diff
changeset
|
1922 } |
|
18933
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 |
|
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
|
1925 /* Check arguments: (name, bases, dict) */ |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43755
diff
changeset
|
1926 if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1927 &name, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1928 &PyTuple_Type, &bases, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1929 &PyDict_Type, &dict)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1930 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1931 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1932 /* 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
|
1933 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
|
1934 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
|
1935 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
|
1936 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
|
1937 winner = metatype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1938 for (i = 0; i < nbases; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1939 tmp = PyTuple_GET_ITEM(bases, i); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1940 tmptype = Py_TYPE(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
|
1941 if (PyType_IsSubtype(winner, tmptype)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1942 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
|
1943 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
|
1944 winner = tmptype; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1945 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1946 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1947 PyErr_SetString(PyExc_TypeError, |
|
28737
d792544ab111
Improve the message about metatype/metaclass conflicts.
Guido van Rossum <guido@python.org>
parents:
28640
diff
changeset
|
1948 "metaclass conflict: " |
|
d792544ab111
Improve the message about metatype/metaclass conflicts.
Guido van Rossum <guido@python.org>
parents:
28640
diff
changeset
|
1949 "the metaclass of a derived class " |
|
d792544ab111
Improve the message about metatype/metaclass conflicts.
Guido van Rossum <guido@python.org>
parents:
28640
diff
changeset
|
1950 "must be a (non-strict) subclass " |
|
d792544ab111
Improve the message about metatype/metaclass conflicts.
Guido van Rossum <guido@python.org>
parents:
28640
diff
changeset
|
1951 "of the metaclasses of all its bases"); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1952 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1953 } |
|
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
|
1954 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
|
1955 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
|
1956 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
|
1957 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
|
1958 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1959 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1960 /* Adjust for empty tuple bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1961 if (nbases == 0) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
1962 bases = PyTuple_Pack(1, &PyBaseObject_Type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1963 if (bases == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1964 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1965 nbases = 1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1966 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1967 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1968 Py_INCREF(bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1969 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1970 /* 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
|
1971 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1972 /* 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
|
1973 base = best_base(bases); |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
1974 if (base == NULL) { |
|
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
1975 Py_DECREF(bases); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1976 return NULL; |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
1977 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1978 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
|
1979 PyErr_Format(PyExc_TypeError, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1980 "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
|
1981 base->tp_name); |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
1982 Py_DECREF(bases); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1983 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1984 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1985 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1986 /* 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
|
1987 slots = PyDict_GetItemString(dict, "__slots__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
1988 nslots = 0; |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1989 add_dict = 0; |
|
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
1990 add_weak = 0; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1991 may_add_dict = base->tp_dictoffset == 0; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1992 may_add_weak = base->tp_weaklistoffset == 0 && base->tp_itemsize == 0; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1993 if (slots == NULL) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1994 if (may_add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1995 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1996 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1997 if (may_add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1998 add_weak++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
1999 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2000 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2001 else { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2002 /* Have slots */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2003 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2004 /* Make it into a tuple */ |
|
42862
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
2005 if (PyUnicode_Check(slots)) |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
2006 slots = PyTuple_Pack(1, slots); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2007 else |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2008 slots = PySequence_Tuple(slots); |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
2009 if (slots == NULL) { |
|
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
2010 Py_DECREF(bases); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2011 return NULL; |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
2012 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2013 assert(PyTuple_Check(slots)); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2014 |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2015 /* Are slots allowed? */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2016 nslots = PyTuple_GET_SIZE(slots); |
|
29899
434b6cda4fa5
Remove unnecessary check in tests for slots allowed.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29611
diff
changeset
|
2017 if (nslots > 0 && base->tp_itemsize != 0) { |
|
19595
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
2018 PyErr_Format(PyExc_TypeError, |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
2019 "nonempty __slots__ " |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
2020 "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
|
2021 base->tp_name); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2022 bad_slots: |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
2023 Py_DECREF(bases); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2024 Py_DECREF(slots); |
|
19595
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
2025 return NULL; |
|
db36e396f043
Safety measures now that str and tuple are subclassable:
Guido van Rossum <guido@python.org>
parents:
19594
diff
changeset
|
2026 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2027 |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2028 /* Check for valid slot names and two special cases */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2029 for (i = 0; i < nslots; i++) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2030 PyObject *tmp = PyTuple_GET_ITEM(slots, i); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2031 if (!valid_identifier(tmp)) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2032 goto bad_slots; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2033 assert(PyUnicode_Check(tmp)); |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2034 if (PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2035 if (!may_add_dict || add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2036 PyErr_SetString(PyExc_TypeError, |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2037 "__dict__ slot disallowed: " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2038 "we already got one"); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2039 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2040 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2041 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2042 } |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2043 if (PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0) { |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2044 if (!may_add_weak || add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2045 PyErr_SetString(PyExc_TypeError, |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2046 "__weakref__ slot disallowed: " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2047 "either we already got one, " |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2048 "or __itemsize__ != 0"); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2049 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2050 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2051 add_weak++; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2052 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2053 } |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2054 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2055 /* Copy slots into a list, mangle names and sort them. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2056 Sorted names are needed for __class__ assignment. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2057 Convert them back to tuple at the end. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2058 */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2059 newslots = PyList_New(nslots - add_dict - add_weak); |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2060 if (newslots == NULL) |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2061 goto bad_slots; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2062 for (i = j = 0; i < nslots; i++) { |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2063 tmp = PyTuple_GET_ITEM(slots, i); |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2064 if ((add_dict && |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2065 PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) || |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2066 (add_weak && |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2067 PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0)) |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2068 continue; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35637
diff
changeset
|
2069 tmp =_Py_Mangle(name, tmp); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2070 if (!tmp) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2071 goto bad_slots; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2072 PyList_SET_ITEM(newslots, j, tmp); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2073 j++; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2074 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2075 assert(j == nslots - add_dict - add_weak); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2076 nslots = j; |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2077 Py_DECREF(slots); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2078 if (PyList_Sort(newslots) == -1) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2079 Py_DECREF(bases); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2080 Py_DECREF(newslots); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2081 return NULL; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2082 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2083 slots = PyList_AsTuple(newslots); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2084 Py_DECREF(newslots); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2085 if (slots == NULL) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2086 Py_DECREF(bases); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2087 return NULL; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2088 } |
|
23950
f7ce696979e1
SF 569257 -- Name mangle double underscored variable names in __slots__.
Raymond Hettinger <python@rcn.com>
parents:
23903
diff
changeset
|
2089 |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2090 /* Secondary bases may provide weakrefs or dict */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2091 if (nbases > 1 && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2092 ((may_add_dict && !add_dict) || |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2093 (may_add_weak && !add_weak))) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2094 for (i = 0; i < nbases; i++) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2095 tmp = PyTuple_GET_ITEM(bases, i); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2096 if (tmp == (PyObject *)base) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2097 continue; /* Skip primary base */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2098 assert(PyType_Check(tmp)); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2099 tmptype = (PyTypeObject *)tmp; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2100 if (may_add_dict && !add_dict && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2101 tmptype->tp_dictoffset != 0) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2102 add_dict++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2103 if (may_add_weak && !add_weak && |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2104 tmptype->tp_weaklistoffset != 0) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2105 add_weak++; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2106 if (may_add_dict && !add_dict) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2107 continue; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2108 if (may_add_weak && !add_weak) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2109 continue; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2110 /* Nothing more to check */ |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2111 break; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2112 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2113 } |
|
19349
9b5a2c1a02f3
Weak reference support, closing SF bug #451773.
Guido van Rossum <guido@python.org>
parents:
19339
diff
changeset
|
2114 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2115 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2116 /* 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
|
2117 "return NULL" may leak slots! */ |
|
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 /* Allocate the type object */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2120 type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots); |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2121 if (type == NULL) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2122 Py_XDECREF(slots); |
|
30098
d6379620fb08
/* XXX From here until type is allocated, "return NULL" leaks bases! */
Michael W. Hudson <mwh@python.net>
parents:
30084
diff
changeset
|
2123 Py_DECREF(bases); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2124 return NULL; |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2125 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2126 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2127 /* Keep name and slots alive in the extended type object */ |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2128 et = (PyHeapTypeObject *)type; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2129 Py_INCREF(name); |
|
36631
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
2130 et->ht_name = name; |
|
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
2131 et->ht_slots = slots; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2132 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2133 /* Initialize tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2134 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
|
2135 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
|
2136 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
|
2137 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
|
2138 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
2139 /* Initialize essential fields */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2140 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
|
2141 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
|
2142 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
|
2143 type->tp_as_buffer = &et->as_buffer; |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48475
diff
changeset
|
2144 type->tp_name = _PyUnicode_AsString(name); |
|
42862
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
2145 if (!type->tp_name) { |
|
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
2146 Py_DECREF(type); |
|
ed1594a16bdb
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42854
diff
changeset
|
2147 return NULL; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2148 } |
|
18933
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 /* Set tp_base and tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2151 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2152 Py_INCREF(base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2153 type->tp_base = base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2154 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2155 /* 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
|
2156 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
|
2157 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2158 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2159 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2160 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2161 |
|
19300
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2162 /* Set __module__ in the dict */ |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2163 if (PyDict_GetItemString(dict, "__module__") == NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2164 tmp = PyEval_GetGlobals(); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2165 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2166 tmp = PyDict_GetItemString(tmp, "__name__"); |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2167 if (tmp != NULL) { |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2168 if (PyDict_SetItemString(dict, "__module__", |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2169 tmp) < 0) |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2170 return NULL; |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2171 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2172 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2173 } |
|
81440dd326bb
Fix SF bug #442501: calculate __module__ properly.
Guido van Rossum <guido@python.org>
parents:
19297
diff
changeset
|
2174 |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2175 /* Set tp_doc to a copy of dict['__doc__'], if the latter is there |
|
22348
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
2176 and is a string. The __doc__ accessor will first look for tp_doc; |
|
51aa9eb24d81
SF patch 530070: pydoc regression, from Martin and Guido.
Tim Peters <tim.peters@gmail.com>
parents:
22331
diff
changeset
|
2177 if that fails, it will still look into __dict__. |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2178 */ |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2179 { |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2180 PyObject *doc = PyDict_GetItemString(dict, "__doc__"); |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2181 if (doc != NULL && PyUnicode_Check(doc)) { |
|
46644
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2182 Py_ssize_t len; |
|
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2183 char *doc_str; |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2184 char *tp_doc; |
|
46644
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2185 |
|
54555
f48a05214281
Issue #5373: Remove restriction on null bytes in docstrings of classes.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54119
diff
changeset
|
2186 doc_str = _PyUnicode_AsString(doc); |
|
46644
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2187 if (doc_str == NULL) { |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2188 Py_DECREF(type); |
|
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2189 return NULL; |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2190 } |
|
54555
f48a05214281
Issue #5373: Remove restriction on null bytes in docstrings of classes.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54119
diff
changeset
|
2191 /* Silently truncate the docstring if it contains null bytes. */ |
|
f48a05214281
Issue #5373: Remove restriction on null bytes in docstrings of classes.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54119
diff
changeset
|
2192 len = strlen(doc_str); |
|
46644
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2193 tp_doc = (char *)PyObject_MALLOC(len + 1); |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2194 if (tp_doc == NULL) { |
|
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2195 Py_DECREF(type); |
|
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2196 return NULL; |
| 42822 | 2197 } |
|
46644
ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46336
diff
changeset
|
2198 memcpy(tp_doc, doc_str, len + 1); |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
2199 type->tp_doc = tp_doc; |
|
20239
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2200 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2201 } |
|
2745c3dc24af
SF bug [#467331] ClassType.__doc__ always None.
Tim Peters <tim.peters@gmail.com>
parents:
20231
diff
changeset
|
2202 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2203 /* 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
|
2204 make it a static function */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2205 tmp = PyDict_GetItemString(dict, "__new__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2206 if (tmp != NULL && PyFunction_Check(tmp)) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2207 tmp = PyStaticMethod_New(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2208 if (tmp == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2209 Py_DECREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2210 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2211 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2212 PyDict_SetItemString(dict, "__new__", tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2213 Py_DECREF(tmp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2214 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2215 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2216 /* Add descriptors for custom slots from __slots__, or for __dict__ */ |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2217 mp = PyHeapType_GET_MEMBERS(et); |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
2218 slotoffset = base->tp_basicsize; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2219 if (slots != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2220 for (i = 0; i < nslots; i++, mp++) { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48475
diff
changeset
|
2221 mp->name = _PyUnicode_AsString( |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2222 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
|
2223 mp->type = T_OBJECT_EX; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2224 mp->offset = slotoffset; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2225 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2226 /* __dict__ and __weakref__ are already filtered out */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2227 assert(strcmp(mp->name, "__dict__") != 0); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2228 assert(strcmp(mp->name, "__weakref__") != 0); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2229 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2230 slotoffset += sizeof(PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2231 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2232 } |
|
24761
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2233 if (add_dict) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2234 if (base->tp_itemsize) |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2235 type->tp_dictoffset = -(long)sizeof(PyObject *); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2236 else |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2237 type->tp_dictoffset = slotoffset; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2238 slotoffset += sizeof(PyObject *); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2239 } |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2240 if (add_weak) { |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2241 assert(!base->tp_itemsize); |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2242 type->tp_weaklistoffset = slotoffset; |
|
e0431d9c4474
Refactor how __dict__ and __weakref__ interact with __slots__.
Guido van Rossum <guido@python.org>
parents:
24728
diff
changeset
|
2243 slotoffset += sizeof(PyObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2244 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2245 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
|
2246 type->tp_itemsize = base->tp_itemsize; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2247 type->tp_members = PyHeapType_GET_MEMBERS(et); |
|
27132
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2248 |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2249 if (type->tp_weaklistoffset && type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2250 type->tp_getset = subtype_getsets_full; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2251 else if (type->tp_weaklistoffset && !type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2252 type->tp_getset = subtype_getsets_weakref_only; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2253 else if (!type->tp_weaklistoffset && type->tp_dictoffset) |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2254 type->tp_getset = subtype_getsets_dict_only; |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2255 else |
|
22d660494f29
Fix for SF bug #642358: only provide a new with a __dict__ or
Guido van Rossum <guido@python.org>
parents:
27124
diff
changeset
|
2256 type->tp_getset = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2257 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2258 /* Special case some slots */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2259 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
|
2260 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
|
2261 type->tp_getattro = PyObject_GenericGetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2262 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
|
2263 type->tp_setattro = PyObject_GenericSetAttr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2264 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2265 type->tp_dealloc = subtype_dealloc; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2266 |
|
20277
2983b54256c7
Enable GC for new-style instances. This touches lots of files, since
Guido van Rossum <guido@python.org>
parents:
20259
diff
changeset
|
2267 /* 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
|
2268 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
|
2269 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
|
2270 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
|
2271 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2272 /* 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
|
2273 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
|
2274 if (type->tp_flags & Py_TPFLAGS_HAVE_GC) { |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
2275 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
|
2276 type->tp_traverse = subtype_traverse; |
|
23666
2becb5793acd
Address SF bug 519621: slots weren't traversed by GC.
Guido van Rossum <guido@python.org>
parents:
23649
diff
changeset
|
2277 type->tp_clear = subtype_clear; |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2278 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2279 else |
|
22980
9f949027d7ba
Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22871
diff
changeset
|
2280 type->tp_free = PyObject_Del; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2281 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2282 /* Initialize the rest */ |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
2283 if (PyType_Ready(type) < 0) { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2284 Py_DECREF(type); |
|
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 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2287 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
2288 /* 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
|
2289 fixup_slot_dispatchers(type); |
| 19036 | 2290 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2291 return (PyObject *)type; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2292 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2293 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2294 /* 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
|
2295 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
|
2296 PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2297 _PyType_Lookup(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2298 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
2299 Py_ssize_t 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
|
2300 PyObject *mro, *res, *base, *dict; |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2301 unsigned int h; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2302 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2303 if (MCACHE_CACHEABLE_NAME(name) && |
|
45017
4725c84b0422
Merged revisions 60350-60363 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44654
diff
changeset
|
2304 PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) { |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2305 /* fast path */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2306 h = MCACHE_HASH_METHOD(type, name); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2307 if (method_cache[h].version == type->tp_version_tag && |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2308 method_cache[h].name == name) |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2309 return method_cache[h].value; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2310 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2311 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
2312 /* 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
|
2313 mro = type->tp_mro; |
|
23753
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2314 |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2315 /* If mro is NULL, the type is either not yet initialized |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2316 by PyType_Ready(), or already cleared by type_clear(). |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2317 Either way the safest thing to do is to return NULL. */ |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2318 if (mro == NULL) |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2319 return NULL; |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
2320 |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2321 res = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2322 assert(PyTuple_Check(mro)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2323 n = PyTuple_GET_SIZE(mro); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2324 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
|
2325 base = PyTuple_GET_ITEM(mro, i); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
2326 assert(PyType_Check(base)); |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
2327 dict = ((PyTypeObject *)base)->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2328 assert(dict && PyDict_Check(dict)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2329 res = PyDict_GetItem(dict, name); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2330 if (res != NULL) |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2331 break; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2332 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2333 |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2334 if (MCACHE_CACHEABLE_NAME(name) && assign_version_tag(type)) { |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2335 h = MCACHE_HASH_METHOD(type, name); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2336 method_cache[h].version = type->tp_version_tag; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2337 method_cache[h].value = res; /* borrowed */ |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2338 Py_INCREF(name); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2339 Py_DECREF(method_cache[h].name); |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2340 method_cache[h].name = name; |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2341 } |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
2342 return res; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2343 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2344 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2345 /* This is similar to PyObject_GenericGetAttr(), |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2346 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
|
2347 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2348 type_getattro(PyTypeObject *type, PyObject *name) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2349 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2350 PyTypeObject *metatype = Py_TYPE(type); |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2351 PyObject *meta_attribute, *attribute; |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2352 descrgetfunc meta_get; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2353 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2354 /* 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
|
2355 if (type->tp_dict == NULL) { |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
2356 if (PyType_Ready(type) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2357 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2358 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2359 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2360 /* No readable descriptor found yet */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2361 meta_get = NULL; |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
2362 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2363 /* Look for the attribute in the metatype */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2364 meta_attribute = _PyType_Lookup(metatype, name); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2365 |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2366 if (meta_attribute != NULL) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2367 meta_get = Py_TYPE(meta_attribute)->tp_descr_get; |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
2368 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2369 if (meta_get != NULL && PyDescr_IsData(meta_attribute)) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2370 /* Data descriptors implement tp_descr_set to intercept |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2371 * writes. Assume the attribute is not overridden in |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2372 * type's tp_dict (and bases): call the descriptor now. |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2373 */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2374 return meta_get(meta_attribute, (PyObject *)type, |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2375 (PyObject *)metatype); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2376 } |
| 30159 | 2377 Py_INCREF(meta_attribute); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2378 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2379 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2380 /* No data descriptor found on metatype. Look in tp_dict of this |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2381 * type and its bases */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2382 attribute = _PyType_Lookup(type, name); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2383 if (attribute != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2384 /* Implement descriptor functionality, if any */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2385 descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get; |
| 30159 | 2386 |
| 2387 Py_XDECREF(meta_attribute); | |
| 2388 | |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2389 if (local_get != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2390 /* NULL 2nd argument indicates the descriptor was |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2391 * found on the target object itself (or a base) */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2392 return local_get(attribute, (PyObject *)NULL, |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2393 (PyObject *)type); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2394 } |
|
24184
c4dcb80f48ea
object.h special-build macro minefield: renamed all the new lexical
Tim Peters <tim.peters@gmail.com>
parents:
23967
diff
changeset
|
2395 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2396 Py_INCREF(attribute); |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2397 return attribute; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2398 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2399 |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2400 /* No attribute found in local __dict__ (or bases): use the |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2401 * descriptor from the metatype, if any */ |
| 30159 | 2402 if (meta_get != NULL) { |
| 2403 PyObject *res; | |
| 2404 res = meta_get(meta_attribute, (PyObject *)type, | |
| 2405 (PyObject *)metatype); | |
| 2406 Py_DECREF(meta_attribute); | |
| 2407 return res; | |
| 2408 } | |
|
22804
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2409 |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2410 /* If an ordinary attribute was found on the metatype, return it now */ |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2411 if (meta_attribute != NULL) { |
|
77343aa03e2f
Clarifying code rearrangement and comments by David Abrahams. I've
Guido van Rossum <guido@python.org>
parents:
22774
diff
changeset
|
2412 return meta_attribute; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2413 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2414 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2415 /* Give up */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2416 PyErr_Format(PyExc_AttributeError, |
|
42040
96eefc7a67a0
Simplify error formatting and type_repr().
Walter Dörwald <walter@livinglogic.de>
parents:
42037
diff
changeset
|
2417 "type object '%.50s' has no attribute '%U'", |
|
96eefc7a67a0
Simplify error formatting and type_repr().
Walter Dörwald <walter@livinglogic.de>
parents:
42037
diff
changeset
|
2418 type->tp_name, name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2419 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2420 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2421 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2422 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2423 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
|
2424 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2425 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
|
2426 PyErr_Format( |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2427 PyExc_TypeError, |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2428 "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
|
2429 type->tp_name); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2430 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
|
2431 } |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2432 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
|
2433 return -1; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
2434 return update_slot(type, name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2435 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2436 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2437 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2438 type_dealloc(PyTypeObject *type) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2439 { |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2440 PyHeapTypeObject *et; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2441 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2442 /* 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
|
2443 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
|
2444 _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
|
2445 PyObject_ClearWeakRefs((PyObject *)type); |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2446 et = (PyHeapTypeObject *)type; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2447 Py_XDECREF(type->tp_base); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2448 Py_XDECREF(type->tp_dict); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2449 Py_XDECREF(type->tp_bases); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2450 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
|
2451 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
|
2452 Py_XDECREF(type->tp_subclasses); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2453 /* A type's tp_doc is heap allocated, unlike the tp_doc slots |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2454 * of most other objects. It's okay to cast it to char *. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2455 */ |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35742
diff
changeset
|
2456 PyObject_Free((char *)type->tp_doc); |
|
36631
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
2457 Py_XDECREF(et->ht_name); |
|
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
2458 Py_XDECREF(et->ht_slots); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2459 Py_TYPE(type)->tp_free((PyObject *)type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2460 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2461 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2462 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
|
2463 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
|
2464 { |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2465 PyObject *list, *raw, *ref; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
2466 Py_ssize_t i, n; |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2467 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2468 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
|
2469 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
|
2470 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
|
2471 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
|
2472 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
|
2473 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
|
2474 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
|
2475 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
|
2476 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
|
2477 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
|
2478 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
|
2479 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
|
2480 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
|
2481 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
|
2482 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
|
2483 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
|
2484 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2485 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2486 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2487 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
|
2488 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2489 |
|
42420
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2490 static PyObject * |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2491 type_prepare(PyObject *self, PyObject *args, PyObject *kwds) |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2492 { |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2493 return PyDict_New(); |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2494 } |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2495 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2496 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
|
2497 {"mro", (PyCFunction)mro_external, METH_NOARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2498 PyDoc_STR("mro() -> list\nreturn a type's method resolution order")}, |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
2499 {"__subclasses__", (PyCFunction)type_subclasses, METH_NOARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
2500 PyDoc_STR("__subclasses__() -> list of immediate subclasses")}, |
|
42420
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2501 {"__prepare__", (PyCFunction)type_prepare, |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2502 METH_VARARGS | METH_KEYWORDS | METH_CLASS, |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2503 PyDoc_STR("__prepare__() -> dict\n" |
|
02c27177df79
Add a default __prepare__() method to 'type', so it can be called
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2504 "used to create the namespace for the class statement")}, |
|
54119
f9f997c1fd81
Merged revisions 72690 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53905
diff
changeset
|
2505 {"__instancecheck__", type___instancecheck__, METH_O, |
|
f9f997c1fd81
Merged revisions 72690 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53905
diff
changeset
|
2506 PyDoc_STR("__instancecheck__() -> check if an object is an instance")}, |
|
f9f997c1fd81
Merged revisions 72690 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53905
diff
changeset
|
2507 {"__subclasscheck__", type___subclasscheck__, METH_O, |
|
f9f997c1fd81
Merged revisions 72690 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53905
diff
changeset
|
2508 PyDoc_STR("__subclasschck__ -> check if an class is a subclass")}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2509 {0} |
|
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 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
2512 PyDoc_STRVAR(type_doc, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2513 "type(object) -> the object's type\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
2514 "type(name, bases, dict) -> a new type"); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2515 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2516 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
|
2517 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
|
2518 { |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2519 /* Because of type_is_gc(), the collector only calls this |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2520 for heaptypes. */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2521 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
|
2522 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2523 Py_VISIT(type->tp_dict); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2524 Py_VISIT(type->tp_cache); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2525 Py_VISIT(type->tp_mro); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2526 Py_VISIT(type->tp_bases); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2527 Py_VISIT(type->tp_base); |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2528 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2529 /* There's no need to visit type->tp_subclasses or |
|
36631
49d9c120357a
Bug #1086854: Rename PyHeapType members adding ht_ prefix.
Georg Brandl <georg@python.org>
parents:
36519
diff
changeset
|
2530 ((PyHeapTypeObject *)type)->ht_slots, because they can't be involved |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2531 in cycles; tp_subclasses is a list of weak references, |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2532 and slots is a tuple of strings. */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2533 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2534 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
|
2535 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2536 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2537 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
|
2538 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
|
2539 { |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2540 /* Because of type_is_gc(), the collector only calls this |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2541 for heaptypes. */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2542 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
|
2543 |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2544 /* The only field we need to clear is tp_mro, which is part of a |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2545 hard cycle (its first element is the class itself) that won't |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2546 be broken otherwise (it's a tuple and tuples don't have a |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2547 tp_clear handler). None of the other fields need to be |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2548 cleared, and here's why: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2549 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2550 tp_dict: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2551 It is a dict, so the collector will call its tp_clear. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2552 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2553 tp_cache: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2554 Not used; if it were, it would be a dict. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2555 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2556 tp_bases, tp_base: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2557 If these are involved in a cycle, there must be at least |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2558 one other, mutable object in the cycle, e.g. a base |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2559 class's dict; the cycle will be broken that way. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2560 |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2561 tp_subclasses: |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2562 A list of weak references can't be part of a cycle; and |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2563 lists have their own tp_clear. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2564 |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2565 slots (in PyHeapTypeObject): |
|
23755
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2566 A tuple of strings can't be part of a cycle. |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2567 */ |
|
0279040ae03c
In the recent python-dev thread "Bizarre new test failure", we
Guido van Rossum <guido@python.org>
parents:
23753
diff
changeset
|
2568 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2569 Py_CLEAR(type->tp_mro); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2570 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2571 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
|
2572 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2573 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2574 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
|
2575 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
|
2576 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2577 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
|
2578 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2579 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2580 PyTypeObject PyType_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42203
diff
changeset
|
2581 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2582 "type", /* tp_name */ |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
2583 sizeof(PyHeapTypeObject), /* tp_basicsize */ |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
2584 sizeof(PyMemberDef), /* tp_itemsize */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2585 (destructor)type_dealloc, /* tp_dealloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2586 0, /* tp_print */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2587 0, /* tp_getattr */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2588 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51251
diff
changeset
|
2589 0, /* tp_reserved */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2590 (reprfunc)type_repr, /* tp_repr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2591 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2592 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2593 0, /* tp_as_mapping */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2594 0, /* tp_hash */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2595 (ternaryfunc)type_call, /* tp_call */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2596 0, /* tp_str */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2597 (getattrofunc)type_getattro, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2598 (setattrofunc)type_setattro, /* tp_setattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2599 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
|
2600 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
40909
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
2601 Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS, /* tp_flags */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2602 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
|
2603 (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
|
2604 (inquiry)type_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2605 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
|
2606 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
|
2607 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2608 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2609 type_methods, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2610 type_members, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2611 type_getsets, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2612 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2613 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2614 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2615 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2616 offsetof(PyTypeObject, tp_dict), /* tp_dictoffset */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2617 type_init, /* tp_init */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2618 0, /* tp_alloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2619 type_new, /* tp_new */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2620 PyObject_GC_Del, /* tp_free */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
2621 (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
|
2622 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2623 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2624 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2625 /* 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
|
2626 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2627 /* You may wonder why object.__new__() only complains about arguments |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2628 when object.__init__() is not overridden, and vice versa. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2629 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2630 Consider the use cases: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2631 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2632 1. When neither is overridden, we want to hear complaints about |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2633 excess (i.e., any) arguments, since their presence could |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2634 indicate there's a bug. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2635 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2636 2. When defining an Immutable type, we are likely to override only |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2637 __new__(), since __init__() is called too late to initialize an |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2638 Immutable object. Since __new__() defines the signature for the |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2639 type, it would be a pain to have to override __init__() just to |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2640 stop it from complaining about excess arguments. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2641 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2642 3. When defining a Mutable type, we are likely to override only |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2643 __init__(). So here the converse reasoning applies: we don't |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2644 want to have to override __new__() just to stop it from |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2645 complaining. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2646 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2647 4. When __init__() is overridden, and the subclass __init__() calls |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2648 object.__init__(), the latter should complain about excess |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2649 arguments; ditto for __new__(). |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2650 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2651 Use cases 2 and 3 make it unattractive to unconditionally check for |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2652 excess arguments. The best solution that addresses all four use |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2653 cases is as follows: __init__() complains about excess arguments |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2654 unless __new__() is overridden and __init__() is not overridden |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2655 (IOW, if __init__() is overridden or __new__() is not overridden); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2656 symmetrically, __new__() complains about excess arguments unless |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2657 __init__() is overridden and __new__() is not overridden |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2658 (IOW, if __new__() is overridden or __init__() is not overridden). |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2659 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2660 However, for backwards compatibility, this breaks too much code. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2661 Therefore, in 2.6, we'll *warn* about excess arguments when both |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2662 methods are overridden; for all other cases we'll use the above |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2663 rules. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2664 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2665 */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2666 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2667 /* Forward */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2668 static PyObject * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2669 object_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2670 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2671 static int |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2672 excess_args(PyObject *args, PyObject *kwds) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2673 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2674 return PyTuple_GET_SIZE(args) || |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2675 (kwds && PyDict_Check(kwds) && PyDict_Size(kwds)); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2676 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2677 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2678 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2679 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
|
2680 { |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2681 int err = 0; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2682 if (excess_args(args, kwds)) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2683 PyTypeObject *type = Py_TYPE(self); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2684 if (type->tp_init != object_init && |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2685 type->tp_new != object_new) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2686 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2687 err = PyErr_WarnEx(PyExc_DeprecationWarning, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2688 "object.__init__() takes no parameters", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2689 1); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2690 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2691 else if (type->tp_init != object_init || |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2692 type->tp_new == object_new) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2693 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2694 PyErr_SetString(PyExc_TypeError, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2695 "object.__init__() takes no parameters"); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2696 err = -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2697 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2698 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2699 return err; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2700 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2701 |
|
27866
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2702 static PyObject * |
|
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2703 object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2704 { |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2705 int err = 0; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2706 if (excess_args(args, kwds)) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2707 if (type->tp_new != object_new && |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2708 type->tp_init != object_init) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2709 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2710 err = PyErr_WarnEx(PyExc_DeprecationWarning, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2711 "object.__new__() takes no parameters", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2712 1); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2713 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2714 else if (type->tp_new != object_new || |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2715 type->tp_init == object_init) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2716 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2717 PyErr_SetString(PyExc_TypeError, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2718 "object.__new__() takes no parameters"); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2719 err = -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2720 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2721 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2722 if (err < 0) |
|
27866
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2723 return NULL; |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2724 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2725 if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2726 static PyObject *comma = NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2727 PyObject *abstract_methods = NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2728 PyObject *builtins; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2729 PyObject *sorted; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2730 PyObject *sorted_methods = NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2731 PyObject *joined = NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2732 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2733 /* Compute ", ".join(sorted(type.__abstractmethods__)) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2734 into joined. */ |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2735 abstract_methods = type_abstractmethods(type, NULL); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2736 if (abstract_methods == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2737 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2738 builtins = PyEval_GetBuiltins(); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2739 if (builtins == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2740 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2741 sorted = PyDict_GetItemString(builtins, "sorted"); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2742 if (sorted == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2743 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2744 sorted_methods = PyObject_CallFunctionObjArgs(sorted, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2745 abstract_methods, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2746 NULL); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2747 if (sorted_methods == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2748 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2749 if (comma == NULL) { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2750 comma = PyUnicode_InternFromString(", "); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2751 if (comma == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2752 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2753 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2754 joined = PyObject_CallMethod(comma, "join", |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2755 "O", sorted_methods); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2756 if (joined == NULL) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2757 goto error; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2758 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2759 PyErr_Format(PyExc_TypeError, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2760 "Can't instantiate abstract class %s " |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2761 "with abstract methods %U", |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2762 type->tp_name, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2763 joined); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2764 error: |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2765 Py_XDECREF(joined); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2766 Py_XDECREF(sorted_methods); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2767 Py_XDECREF(abstract_methods); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2768 return NULL; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
2769 } |
|
27866
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2770 return type->tp_alloc(type, 0); |
|
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2771 } |
|
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
2772 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2773 static void |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2774 object_dealloc(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2775 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2776 Py_TYPE(self)->tp_free(self); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2777 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2778 |
|
19194
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2779 static PyObject * |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
diff
changeset
|
2780 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
|
2781 { |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2782 PyTypeObject *type; |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
2783 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
|
2784 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2785 type = Py_TYPE(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
|
2786 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
|
2787 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
|
2788 PyErr_Clear(); |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
2789 else if (!PyUnicode_Check(mod)) { |
|
19316
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2790 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
|
2791 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
|
2792 } |
|
f7dc21cb1661
Fix object_repr() to include the module (using the same rules as
Guido van Rossum <guido@python.org>
parents:
19301
diff
changeset
|
2793 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
|
2794 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
|
2795 return NULL; |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43866
diff
changeset
|
2796 if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins")) |
|
42036
160b7318a3ca
__module__ is a unicode string now:
Walter Dörwald <walter@livinglogic.de>
parents:
42019
diff
changeset
|
2797 rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, 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
|
2798 else |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
2799 rtn = PyUnicode_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
|
2800 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
|
2801 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
|
2802 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
|
2803 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
|
2804 } |
|
7e9f5c59e9f2
Make dynamic types work as intended. Or at least more so.
Guido van Rossum <guido@python.org>
parents:
19192
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 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2807 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
|
2808 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2809 unaryfunc f; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2810 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2811 f = Py_TYPE(self)->tp_repr; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2812 if (f == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2813 f = object_repr; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2814 return f(self); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2815 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
2816 |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2817 static PyObject * |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2818 object_richcompare(PyObject *self, PyObject *other, int op) |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2819 { |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2820 PyObject *res; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2821 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2822 switch (op) { |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2823 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2824 case Py_EQ: |
|
44513
8bf6a9a3a632
Issue #1393: object_richcompare() returns NotImplemented instead of
Guido van Rossum <guido@python.org>
parents:
44407
diff
changeset
|
2825 /* Return NotImplemented instead of False, so if two |
|
8bf6a9a3a632
Issue #1393: object_richcompare() returns NotImplemented instead of
Guido van Rossum <guido@python.org>
parents:
44407
diff
changeset
|
2826 objects are compared, both get a chance at the |
|
8bf6a9a3a632
Issue #1393: object_richcompare() returns NotImplemented instead of
Guido van Rossum <guido@python.org>
parents:
44407
diff
changeset
|
2827 comparison. See issue #1393. */ |
|
8bf6a9a3a632
Issue #1393: object_richcompare() returns NotImplemented instead of
Guido van Rossum <guido@python.org>
parents:
44407
diff
changeset
|
2828 res = (self == other) ? Py_True : Py_NotImplemented; |
|
41324
519e72d630d2
Fix refcounting bug reported by Amaury Forgeot d'Arc.
Guido van Rossum <guido@python.org>
parents:
41311
diff
changeset
|
2829 Py_INCREF(res); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2830 break; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2831 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2832 case Py_NE: |
|
41311
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2833 /* By default, != returns the opposite of ==, |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2834 unless the latter returns NotImplemented. */ |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2835 res = PyObject_RichCompare(self, other, Py_EQ); |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2836 if (res != NULL && res != Py_NotImplemented) { |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2837 int ok = PyObject_IsTrue(res); |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2838 Py_DECREF(res); |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2839 if (ok < 0) |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2840 res = NULL; |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2841 else { |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2842 if (ok) |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2843 res = Py_False; |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2844 else |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2845 res = Py_True; |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2846 Py_INCREF(res); |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2847 } |
|
834da52eb2a4
By default, != returns the opposite of ==, unless the latter returns
Guido van Rossum <guido@python.org>
parents:
40909
diff
changeset
|
2848 } |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2849 break; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2850 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2851 default: |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2852 res = Py_NotImplemented; |
|
41324
519e72d630d2
Fix refcounting bug reported by Amaury Forgeot d'Arc.
Guido van Rossum <guido@python.org>
parents:
41311
diff
changeset
|
2853 Py_INCREF(res); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2854 break; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2855 } |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2856 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2857 return res; |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2858 } |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2859 |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
2860 static PyObject * |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2861 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
|
2862 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2863 Py_INCREF(Py_TYPE(self)); |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2864 return (PyObject *)(Py_TYPE(self)); |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2865 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2866 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2867 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2868 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
|
2869 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2870 return a == b || |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2871 (a != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2872 b != NULL && |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2873 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
|
2874 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
|
2875 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
|
2876 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
|
2877 ((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
|
2878 (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
|
2879 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2880 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2881 static int |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2882 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
|
2883 { |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2884 PyTypeObject *base = a->tp_base; |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36510
diff
changeset
|
2885 Py_ssize_t size; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2886 PyObject *slots_a, *slots_b; |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2887 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2888 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
|
2889 return 0; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2890 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
|
2891 return 1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2892 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
|
2893 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
|
2894 size += sizeof(PyObject *); |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2895 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
|
2896 size += sizeof(PyObject *); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2897 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2898 /* Check slots compliance */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2899 slots_a = ((PyHeapTypeObject *)a)->ht_slots; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2900 slots_b = ((PyHeapTypeObject *)b)->ht_slots; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2901 if (slots_a && slots_b) { |
|
51245
9ca34c18e1bd
Issue #1717: remove the cmp builtin function, the C-API functions
Mark Dickinson <dickinsm@gmail.com>
parents:
50884
diff
changeset
|
2902 if (PyObject_RichCompareBool(slots_a, slots_b, Py_EQ) != 1) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2903 return 0; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2904 size += sizeof(PyObject *) * PyTuple_GET_SIZE(slots_a); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2905 } |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2906 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
|
2907 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2908 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2909 static int |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2910 compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, char* attr) |
| 26421 | 2911 { |
| 2912 PyTypeObject *newbase, *oldbase; | |
| 2913 | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2914 if (newto->tp_dealloc != oldto->tp_dealloc || |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2915 newto->tp_free != oldto->tp_free) |
| 26421 | 2916 { |
| 2917 PyErr_Format(PyExc_TypeError, | |
| 2918 "%s assignment: " | |
| 2919 "'%s' deallocator differs from '%s'", | |
| 2920 attr, | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2921 newto->tp_name, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2922 oldto->tp_name); |
| 26421 | 2923 return 0; |
| 2924 } | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2925 newbase = newto; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2926 oldbase = oldto; |
| 26421 | 2927 while (equiv_structs(newbase, newbase->tp_base)) |
| 2928 newbase = newbase->tp_base; | |
| 2929 while (equiv_structs(oldbase, oldbase->tp_base)) | |
| 2930 oldbase = oldbase->tp_base; | |
| 2931 if (newbase != oldbase && | |
| 2932 (newbase->tp_base != oldbase->tp_base || | |
| 2933 !same_slots_added(newbase, oldbase))) { | |
| 2934 PyErr_Format(PyExc_TypeError, | |
| 2935 "%s assignment: " | |
| 2936 "'%s' object layout differs from '%s'", | |
| 2937 attr, | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2938 newto->tp_name, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2939 oldto->tp_name); |
| 26421 | 2940 return 0; |
| 2941 } | |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
2942 |
| 26421 | 2943 return 1; |
| 2944 } | |
| 2945 | |
| 2946 static int | |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2947 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
|
2948 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2949 PyTypeObject *oldto = Py_TYPE(self); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2950 PyTypeObject *newto; |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2951 |
|
23037
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2952 if (value == NULL) { |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2953 PyErr_SetString(PyExc_TypeError, |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2954 "can't delete __class__ attribute"); |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2955 return -1; |
|
89db9e3f35a7
SF bug #541883 (Vincent Fiack).
Guido van Rossum <guido@python.org>
parents:
22980
diff
changeset
|
2956 } |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2957 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
|
2958 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
|
2959 "__class__ must be set to new-style class, not '%s' object", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2960 Py_TYPE(value)->tp_name); |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2961 return -1; |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2962 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2963 newto = (PyTypeObject *)value; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2964 if (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) || |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2965 !(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)) |
|
24728
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2966 { |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2967 PyErr_Format(PyExc_TypeError, |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2968 "__class__ assignment: only for heap types"); |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2969 return -1; |
|
3b8a707b41c4
Disallow class assignment completely unless both old and new are heap
Guido van Rossum <guido@python.org>
parents:
24685
diff
changeset
|
2970 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2971 if (compatible_for_assignment(newto, oldto, "__class__")) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2972 Py_INCREF(newto); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
2973 Py_TYPE(self) = newto; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
2974 Py_DECREF(oldto); |
| 26421 | 2975 return 0; |
| 2976 } | |
| 2977 else { | |
|
23541
f6ded6efabcf
Add a safeguard against setting the class to something with a
Guido van Rossum <guido@python.org>
parents:
23127
diff
changeset
|
2978 return -1; |
|
f6ded6efabcf
Add a safeguard against setting the class to something with a
Guido van Rossum <guido@python.org>
parents:
23127
diff
changeset
|
2979 } |
|
20075
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2980 } |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2981 |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
2982 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
|
2983 {"__class__", object_get_class, object_set_class, |
|
24785
4de9ac0e4173
Allow docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24762
diff
changeset
|
2984 PyDoc_STR("the object's class")}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2985 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2986 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
2987 |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2988 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2989 /* Stuff to implement __reduce_ex__ for pickle protocols >= 2. |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
2990 We fall back to helpers in copyreg for: |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2991 - pickle protocols < 2 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2992 - calculating the list of slot names (done only once per class) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2993 - the __newobj__ function (which is used as a token but never called) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2994 */ |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
2995 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
2996 static PyObject * |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
2997 import_copyreg(void) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
2998 { |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
2999 static PyObject *copyreg_str; |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3000 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3001 if (!copyreg_str) { |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3002 copyreg_str = PyUnicode_InternFromString("copyreg"); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3003 if (copyreg_str == NULL) |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3004 return NULL; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3005 } |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3006 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3007 return PyImport_Import(copyreg_str); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3008 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3009 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3010 static PyObject * |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3011 slotnames(PyObject *cls) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3012 { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3013 PyObject *clsdict; |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3014 PyObject *copyreg; |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3015 PyObject *slotnames; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3016 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3017 if (!PyType_Check(cls)) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3018 Py_INCREF(Py_None); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3019 return Py_None; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3020 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3021 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3022 clsdict = ((PyTypeObject *)cls)->tp_dict; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3023 slotnames = PyDict_GetItemString(clsdict, "__slotnames__"); |
| 35637 | 3024 if (slotnames != NULL && PyList_Check(slotnames)) { |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3025 Py_INCREF(slotnames); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3026 return slotnames; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3027 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3028 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3029 copyreg = import_copyreg(); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3030 if (copyreg == NULL) |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3031 return NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3032 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3033 slotnames = PyObject_CallMethod(copyreg, "_slotnames", "O", cls); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3034 Py_DECREF(copyreg); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3035 if (slotnames != NULL && |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3036 slotnames != Py_None && |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3037 !PyList_Check(slotnames)) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3038 { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3039 PyErr_SetString(PyExc_TypeError, |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3040 "copyreg._slotnames didn't return a list or None"); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3041 Py_DECREF(slotnames); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3042 slotnames = NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3043 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3044 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3045 return slotnames; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3046 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3047 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3048 static PyObject * |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3049 reduce_2(PyObject *obj) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3050 { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3051 PyObject *cls, *getnewargs; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3052 PyObject *args = NULL, *args2 = NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3053 PyObject *getstate = NULL, *state = NULL, *names = NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3054 PyObject *slots = NULL, *listitems = NULL, *dictitems = NULL; |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3055 PyObject *copyreg = NULL, *newobj = NULL, *res = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3056 Py_ssize_t i, n; |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3057 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3058 cls = PyObject_GetAttrString(obj, "__class__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3059 if (cls == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3060 return NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3061 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3062 getnewargs = PyObject_GetAttrString(obj, "__getnewargs__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3063 if (getnewargs != NULL) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3064 args = PyObject_CallObject(getnewargs, NULL); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3065 Py_DECREF(getnewargs); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3066 if (args != NULL && !PyTuple_Check(args)) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
3067 PyErr_Format(PyExc_TypeError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
3068 "__getnewargs__ should return a tuple, " |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
3069 "not '%.200s'", Py_TYPE(args)->tp_name); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3070 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3071 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3072 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3073 else { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3074 PyErr_Clear(); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3075 args = PyTuple_New(0); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3076 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3077 if (args == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3078 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3079 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3080 getstate = PyObject_GetAttrString(obj, "__getstate__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3081 if (getstate != NULL) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3082 state = PyObject_CallObject(getstate, NULL); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3083 Py_DECREF(getstate); |
|
29382
585e303a9491
Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents:
29308
diff
changeset
|
3084 if (state == NULL) |
|
585e303a9491
Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents:
29308
diff
changeset
|
3085 goto end; |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3086 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3087 else { |
|
31477
ba9aaddeb956
Fixed a bug in object.__reduce_ex__ (reduce_2) when using protocol
Jim Fulton <jim@zope.com>
parents:
31176
diff
changeset
|
3088 PyErr_Clear(); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3089 state = PyObject_GetAttrString(obj, "__dict__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3090 if (state == NULL) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3091 PyErr_Clear(); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3092 state = Py_None; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3093 Py_INCREF(state); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3094 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3095 names = slotnames(cls); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3096 if (names == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3097 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3098 if (names != Py_None) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3099 assert(PyList_Check(names)); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3100 slots = PyDict_New(); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3101 if (slots == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3102 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3103 n = 0; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3104 /* Can't pre-compute the list size; the list |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3105 is stored on the class so accessible to other |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3106 threads, which may be run by DECREF */ |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3107 for (i = 0; i < PyList_GET_SIZE(names); i++) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3108 PyObject *name, *value; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3109 name = PyList_GET_ITEM(names, i); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3110 value = PyObject_GetAttr(obj, name); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3111 if (value == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3112 PyErr_Clear(); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3113 else { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3114 int err = PyDict_SetItem(slots, name, |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3115 value); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3116 Py_DECREF(value); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3117 if (err) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3118 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3119 n++; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3120 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3121 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3122 if (n) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3123 state = Py_BuildValue("(NO)", state, slots); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3124 if (state == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3125 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3126 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3127 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3128 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3129 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3130 if (!PyList_Check(obj)) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3131 listitems = Py_None; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3132 Py_INCREF(listitems); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3133 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3134 else { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3135 listitems = PyObject_GetIter(obj); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3136 if (listitems == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3137 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3138 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3139 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3140 if (!PyDict_Check(obj)) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3141 dictitems = Py_None; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3142 Py_INCREF(dictitems); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3143 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3144 else { |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
3145 PyObject *items = PyObject_CallMethod(obj, "items", ""); |
|
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
3146 if (items == NULL) |
|
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
3147 goto end; |
|
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
3148 dictitems = PyObject_GetIter(items); |
|
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
3149 Py_DECREF(items); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3150 if (dictitems == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3151 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3152 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3153 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3154 copyreg = import_copyreg(); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3155 if (copyreg == NULL) |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3156 goto end; |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3157 newobj = PyObject_GetAttrString(copyreg, "__newobj__"); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3158 if (newobj == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3159 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3160 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3161 n = PyTuple_GET_SIZE(args); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3162 args2 = PyTuple_New(n+1); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3163 if (args2 == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3164 goto end; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3165 PyTuple_SET_ITEM(args2, 0, cls); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3166 cls = NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3167 for (i = 0; i < n; i++) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3168 PyObject *v = PyTuple_GET_ITEM(args, i); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3169 Py_INCREF(v); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3170 PyTuple_SET_ITEM(args2, i+1, v); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3171 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3172 |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
3173 res = PyTuple_Pack(5, newobj, args2, state, listitems, dictitems); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3174 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3175 end: |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3176 Py_XDECREF(cls); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3177 Py_XDECREF(args); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3178 Py_XDECREF(args2); |
| 28566 | 3179 Py_XDECREF(slots); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3180 Py_XDECREF(state); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3181 Py_XDECREF(names); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3182 Py_XDECREF(listitems); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3183 Py_XDECREF(dictitems); |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3184 Py_XDECREF(copyreg); |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3185 Py_XDECREF(newobj); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3186 return res; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3187 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3188 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3189 /* |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3190 * There were two problems when object.__reduce__ and object.__reduce_ex__ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3191 * were implemented in the same function: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3192 * - trying to pickle an object with a custom __reduce__ method that |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3193 * fell back to object.__reduce__ in certain circumstances led to |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3194 * infinite recursion at Python level and eventual RuntimeError. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3195 * - Pickling objects that lied about their type by overwriting the |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3196 * __class__ descriptor could lead to infinite recursion at C level |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3197 * and eventual segfault. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3198 * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3199 * Because of backwards compatibility, the two methods still have to |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3200 * behave in the same way, even if this is not required by the pickle |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3201 * protocol. This common functionality was moved to the _common_reduce |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3202 * function. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3203 */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3204 static PyObject * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3205 _common_reduce(PyObject *self, int proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3206 { |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3207 PyObject *copyreg, *res; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3208 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3209 if (proto >= 2) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3210 return reduce_2(self); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3211 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3212 copyreg = import_copyreg(); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3213 if (!copyreg) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3214 return NULL; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3215 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3216 res = PyEval_CallMethod(copyreg, "_reduce_ex", "(Oi)", self, proto); |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46644
diff
changeset
|
3217 Py_DECREF(copyreg); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3218 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3219 return res; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3220 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3221 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3222 static PyObject * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3223 object_reduce(PyObject *self, PyObject *args) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3224 { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3225 int proto = 0; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3226 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3227 if (!PyArg_ParseTuple(args, "|i:__reduce__", &proto)) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3228 return NULL; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3229 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3230 return _common_reduce(self, proto); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3231 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3232 |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3233 static PyObject * |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3234 object_reduce_ex(PyObject *self, PyObject *args) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3235 { |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3236 PyObject *reduce, *res; |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3237 int proto = 0; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3238 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3239 if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto)) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3240 return NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3241 |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3242 reduce = PyObject_GetAttrString(self, "__reduce__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3243 if (reduce == NULL) |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3244 PyErr_Clear(); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3245 else { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3246 PyObject *cls, *clsreduce, *objreduce; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3247 int override; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3248 cls = PyObject_GetAttrString(self, "__class__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3249 if (cls == NULL) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3250 Py_DECREF(reduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3251 return NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3252 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3253 clsreduce = PyObject_GetAttrString(cls, "__reduce__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3254 Py_DECREF(cls); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3255 if (clsreduce == NULL) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3256 Py_DECREF(reduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3257 return NULL; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3258 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3259 objreduce = PyDict_GetItemString(PyBaseObject_Type.tp_dict, |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3260 "__reduce__"); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3261 override = (clsreduce != objreduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3262 Py_DECREF(clsreduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3263 if (override) { |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3264 res = PyObject_CallObject(reduce, NULL); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3265 Py_DECREF(reduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3266 return res; |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3267 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3268 else |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3269 Py_DECREF(reduce); |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3270 } |
|
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3271 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3272 return _common_reduce(self, proto); |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3273 } |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3274 |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3275 static PyObject * |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3276 object_subclasshook(PyObject *cls, PyObject *args) |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3277 { |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3278 Py_INCREF(Py_NotImplemented); |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3279 return Py_NotImplemented; |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3280 } |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3281 |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3282 PyDoc_STRVAR(object_subclasshook_doc, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3283 "Abstract classes can override this to customize issubclass().\n" |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3284 "\n" |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3285 "This is invoked early on by abc.ABCMeta.__subclasscheck__().\n" |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3286 "It should return True, False or NotImplemented. If it returns\n" |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3287 "NotImplemented, the normal algorithm is used. Otherwise, it\n" |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3288 "overrides the normal algorithm (and the outcome is cached).\n"); |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3289 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3290 /* |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3291 from PEP 3101, this code implements: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3292 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3293 class object: |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3294 def __format__(self, format_spec): |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3295 return format(str(self), format_spec) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3296 */ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3297 static PyObject * |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3298 object_format(PyObject *self, PyObject *args) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3299 { |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3300 PyObject *format_spec; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3301 PyObject *self_as_str = NULL; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3302 PyObject *result = NULL; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3303 PyObject *format_meth = NULL; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3304 |
|
44626
60126aa3b816
Simplifed argument parsing in object.__format__, added test case.
Eric Smith <eric@trueblade.com>
parents:
44513
diff
changeset
|
3305 if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3306 return NULL; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3307 |
|
43866
8ed0280c2ab6
Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents:
43777
diff
changeset
|
3308 self_as_str = PyObject_Str(self); |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3309 if (self_as_str != NULL) { |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3310 /* find the format function */ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3311 format_meth = PyObject_GetAttrString(self_as_str, "__format__"); |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3312 if (format_meth != NULL) { |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3313 /* and call it */ |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3314 result = PyObject_CallFunctionObjArgs(format_meth, format_spec, NULL); |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3315 } |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3316 } |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3317 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3318 Py_XDECREF(self_as_str); |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3319 Py_XDECREF(format_meth); |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3320 |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3321 return result; |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3322 } |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3323 |
|
47466
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3324 static PyObject * |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3325 object_sizeof(PyObject *self, PyObject *args) |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3326 { |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3327 Py_ssize_t res, isize; |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3328 |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3329 res = 0; |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3330 isize = self->ob_type->tp_itemsize; |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3331 if (isize > 0) |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3332 res = Py_SIZE(self->ob_type) * isize; |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3333 res += self->ob_type->tp_basicsize; |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3334 |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3335 return PyLong_FromSsize_t(res); |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3336 } |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3337 |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3338 static PyMethodDef object_methods[] = { |
|
27948
db1d4584a5e1
Introducing __reduce_ex__, which is called with a protocol number argument
Guido van Rossum <guido@python.org>
parents:
27943
diff
changeset
|
3339 {"__reduce_ex__", object_reduce_ex, METH_VARARGS, |
|
db1d4584a5e1
Introducing __reduce_ex__, which is called with a protocol number argument
Guido van Rossum <guido@python.org>
parents:
27943
diff
changeset
|
3340 PyDoc_STR("helper for pickle")}, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3341 {"__reduce__", object_reduce, METH_VARARGS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
3342 PyDoc_STR("helper for pickle")}, |
|
45549
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3343 {"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS, |
|
8dd30fe11a4b
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
3344 object_subclasshook_doc}, |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3345 {"__format__", object_format, METH_VARARGS, |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42673
diff
changeset
|
3346 PyDoc_STR("default object formatter")}, |
|
47466
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3347 {"__sizeof__", object_sizeof, METH_NOARGS, |
|
58f4b60773fe
Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3348 PyDoc_STR("__sizeof__() -> size of object in memory, in bytes")}, |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3349 {0} |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3350 }; |
|
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3351 |
|
28016
b849482c70c6
Implementing the salient parts of __reduce_ex__ in C.
Guido van Rossum <guido@python.org>
parents:
27948
diff
changeset
|
3352 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3353 PyTypeObject PyBaseObject_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42203
diff
changeset
|
3354 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3355 "object", /* tp_name */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3356 sizeof(PyObject), /* tp_basicsize */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3357 0, /* tp_itemsize */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3358 object_dealloc, /* tp_dealloc */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3359 0, /* tp_print */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3360 0, /* tp_getattr */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3361 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51251
diff
changeset
|
3362 0, /* tp_reserved */ |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3363 object_repr, /* tp_repr */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3364 0, /* tp_as_number */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3365 0, /* tp_as_sequence */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3366 0, /* tp_as_mapping */ |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
3367 (hashfunc)_Py_HashPointer, /* tp_hash */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3368 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
|
3369 object_str, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3370 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
|
3371 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3372 0, /* tp_as_buffer */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3373 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
3374 PyDoc_STR("The most base type"), /* tp_doc */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3375 0, /* tp_traverse */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3376 0, /* tp_clear */ |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39624
diff
changeset
|
3377 object_richcompare, /* tp_richcompare */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3378 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3379 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3380 0, /* tp_iternext */ |
|
20084
48e93ef3c5b7
- Provisional support for pickling new-style objects. (*)
Guido van Rossum <guido@python.org>
parents:
20076
diff
changeset
|
3381 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
|
3382 0, /* tp_members */ |
|
aae5cf7e5861
Make __class__ assignment possible, when the object structures are the
Guido van Rossum <guido@python.org>
parents:
20063
diff
changeset
|
3383 object_getsets, /* tp_getset */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3384 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3385 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3386 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3387 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3388 0, /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3389 object_init, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3390 PyType_GenericAlloc, /* tp_alloc */ |
|
27866
bbbba0ee61fb
SF patch #685738 by Michael Stone.
Guido van Rossum <guido@python.org>
parents:
27831
diff
changeset
|
3391 object_new, /* tp_new */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3392 PyObject_Del, /* tp_free */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3393 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3394 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3395 |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
3396 /* Add the methods from tp_methods to the __dict__ in a type object */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3397 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3398 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3399 add_methods(PyTypeObject *type, PyMethodDef *meth) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3400 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3401 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3402 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3403 for (; meth->ml_name != NULL; meth++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3404 PyObject *descr; |
|
31172
e4fb6164158c
* Added a new method flag, METH_COEXIST.
Raymond Hettinger <python@rcn.com>
parents:
30917
diff
changeset
|
3405 if (PyDict_GetItemString(dict, meth->ml_name) && |
|
e4fb6164158c
* Added a new method flag, METH_COEXIST.
Raymond Hettinger <python@rcn.com>
parents:
30917
diff
changeset
|
3406 !(meth->ml_flags & METH_COEXIST)) |
|
e4fb6164158c
* Added a new method flag, METH_COEXIST.
Raymond Hettinger <python@rcn.com>
parents:
30917
diff
changeset
|
3407 continue; |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3408 if (meth->ml_flags & METH_CLASS) { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3409 if (meth->ml_flags & METH_STATIC) { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3410 PyErr_SetString(PyExc_ValueError, |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3411 "method cannot be both class and static"); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3412 return -1; |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3413 } |
|
26583
8991f78817c7
SF 548651: Fix the METH_CLASS implementation.
Tim Peters <tim.peters@gmail.com>
parents:
26575
diff
changeset
|
3414 descr = PyDescr_NewClassMethod(type, meth); |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3415 } |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3416 else if (meth->ml_flags & METH_STATIC) { |
|
27814
48dc4a59a50e
Inline create_specialmethod() -- since METH_CLASS is done differently
Guido van Rossum <guido@python.org>
parents:
27811
diff
changeset
|
3417 PyObject *cfunc = PyCFunction_New(meth, NULL); |
|
48dc4a59a50e
Inline create_specialmethod() -- since METH_CLASS is done differently
Guido van Rossum <guido@python.org>
parents:
27811
diff
changeset
|
3418 if (cfunc == NULL) |
|
48dc4a59a50e
Inline create_specialmethod() -- since METH_CLASS is done differently
Guido van Rossum <guido@python.org>
parents:
27811
diff
changeset
|
3419 return -1; |
|
48dc4a59a50e
Inline create_specialmethod() -- since METH_CLASS is done differently
Guido van Rossum <guido@python.org>
parents:
27811
diff
changeset
|
3420 descr = PyStaticMethod_New(cfunc); |
|
48dc4a59a50e
Inline create_specialmethod() -- since METH_CLASS is done differently
Guido van Rossum <guido@python.org>
parents:
27811
diff
changeset
|
3421 Py_DECREF(cfunc); |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3422 } |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3423 else { |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3424 descr = PyDescr_NewMethod(type, meth); |
|
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3425 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3426 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3427 return -1; |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
22348
diff
changeset
|
3428 if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3429 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3430 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3431 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3432 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3433 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3434 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3435 static int |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
3436 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
|
3437 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3438 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3439 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3440 for (; memb->name != NULL; memb++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3441 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3442 if (PyDict_GetItemString(dict, memb->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3443 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3444 descr = PyDescr_NewMember(type, memb); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3445 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3446 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3447 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
|
3448 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3449 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3450 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3451 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3452 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3453 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3454 static int |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
3455 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
|
3456 { |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3457 PyObject *dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3458 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3459 for (; gsp->name != NULL; gsp++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3460 PyObject *descr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3461 if (PyDict_GetItemString(dict, gsp->name)) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3462 continue; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3463 descr = PyDescr_NewGetSet(type, gsp); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3464 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3465 if (descr == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3466 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3467 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
|
3468 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3469 Py_DECREF(descr); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3470 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3471 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3472 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3473 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3474 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3475 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
|
3476 { |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36510
diff
changeset
|
3477 Py_ssize_t oldsize, newsize; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3478 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3479 /* 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
|
3480 oldsize = base->tp_basicsize; |
|
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
3481 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
|
3482 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
|
3483 (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
|
3484 (!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
|
3485 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
|
3486 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
|
3487 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
|
3488 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
|
3489 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
|
3490 } |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3491 { |
|
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
|
3492 /* 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
|
3493 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
|
3494 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
|
3495 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
|
3496 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
|
3497 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
|
3498 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
|
3499 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
|
3500 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
|
3501 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
|
3502 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
|
3503 (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
|
3504 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
|
3505 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
|
3506 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3507 } |
|
19582
13a93a5dcb1d
Use new GC API. Remove usage of BASICSIZE macros.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19551
diff
changeset
|
3508 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
|
3509 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
3510 /* 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
|
3511 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
3512 #undef COPYVAL |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
3513 #define COPYVAL(SLOT) \ |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
3514 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
|
3515 |
|
968d169501f2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
Guido van Rossum <guido@python.org>
parents:
19194
diff
changeset
|
3516 COPYVAL(tp_itemsize); |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3517 COPYVAL(tp_weaklistoffset); |
|
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3518 COPYVAL(tp_dictoffset); |
|
40909
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3519 |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3520 /* Setup fast subclass flags */ |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3521 if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3522 type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS; |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3523 else if (PyType_IsSubtype(base, &PyType_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3524 type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS; |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3525 else if (PyType_IsSubtype(base, &PyLong_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3526 type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47260
diff
changeset
|
3527 else if (PyType_IsSubtype(base, &PyBytes_Type)) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47260
diff
changeset
|
3528 type->tp_flags |= Py_TPFLAGS_BYTES_SUBCLASS; |
|
40909
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3529 else if (PyType_IsSubtype(base, &PyUnicode_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3530 type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS; |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3531 else if (PyType_IsSubtype(base, &PyTuple_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3532 type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS; |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3533 else if (PyType_IsSubtype(base, &PyList_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3534 type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS; |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3535 else if (PyType_IsSubtype(base, &PyDict_Type)) |
|
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40893
diff
changeset
|
3536 type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS; |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3537 } |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3538 |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3539 static char *hash_name_op[] = { |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3540 "__eq__", |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3541 "__hash__", |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3542 NULL |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3543 }; |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3544 |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3545 static int |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3546 overrides_hash(PyTypeObject *type) |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3547 { |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3548 char **p; |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3549 PyObject *dict = type->tp_dict; |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3550 |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3551 assert(dict != NULL); |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3552 for (p = hash_name_op; *p; p++) { |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3553 if (PyDict_GetItemString(dict, *p) != NULL) |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3554 return 1; |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3555 } |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3556 return 0; |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3557 } |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3558 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3559 static void |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3560 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
|
3561 { |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3562 PyTypeObject *basebase; |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3563 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3564 #undef SLOTDEFINED |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3565 #undef COPYSLOT |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3566 #undef COPYNUM |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3567 #undef COPYSEQ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3568 #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
|
3569 #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
|
3570 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3571 #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
|
3572 (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
|
3573 (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
|
3574 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3575 #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
|
3576 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
|
3577 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3578 #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
|
3579 #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
|
3580 #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
|
3581 #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
|
3582 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3583 /* 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
|
3584 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
|
3585 |
|
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3586 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
|
3587 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
|
3588 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
|
3589 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3590 COPYNUM(nb_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3591 COPYNUM(nb_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3592 COPYNUM(nb_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3593 COPYNUM(nb_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3594 COPYNUM(nb_divmod); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3595 COPYNUM(nb_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3596 COPYNUM(nb_negative); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3597 COPYNUM(nb_positive); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3598 COPYNUM(nb_absolute); |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
3599 COPYNUM(nb_bool); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3600 COPYNUM(nb_invert); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3601 COPYNUM(nb_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3602 COPYNUM(nb_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3603 COPYNUM(nb_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3604 COPYNUM(nb_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3605 COPYNUM(nb_or); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3606 COPYNUM(nb_int); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3607 COPYNUM(nb_float); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3608 COPYNUM(nb_inplace_add); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3609 COPYNUM(nb_inplace_subtract); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3610 COPYNUM(nb_inplace_multiply); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3611 COPYNUM(nb_inplace_remainder); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3612 COPYNUM(nb_inplace_power); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3613 COPYNUM(nb_inplace_lshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3614 COPYNUM(nb_inplace_rshift); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3615 COPYNUM(nb_inplace_and); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3616 COPYNUM(nb_inplace_xor); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3617 COPYNUM(nb_inplace_or); |
|
37191
4bfe8afe8f65
Get rid of remnants of integer division
Neal Norwitz <nnorwitz@gmail.com>
parents:
36925
diff
changeset
|
3618 COPYNUM(nb_true_divide); |
|
4bfe8afe8f65
Get rid of remnants of integer division
Neal Norwitz <nnorwitz@gmail.com>
parents:
36925
diff
changeset
|
3619 COPYNUM(nb_floor_divide); |
|
4bfe8afe8f65
Get rid of remnants of integer division
Neal Norwitz <nnorwitz@gmail.com>
parents:
36925
diff
changeset
|
3620 COPYNUM(nb_inplace_true_divide); |
|
4bfe8afe8f65
Get rid of remnants of integer division
Neal Norwitz <nnorwitz@gmail.com>
parents:
36925
diff
changeset
|
3621 COPYNUM(nb_inplace_floor_divide); |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3622 COPYNUM(nb_index); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3623 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3624 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3625 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
|
3626 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
|
3627 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
|
3628 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3629 COPYSEQ(sq_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3630 COPYSEQ(sq_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3631 COPYSEQ(sq_repeat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3632 COPYSEQ(sq_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3633 COPYSEQ(sq_ass_item); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3634 COPYSEQ(sq_contains); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3635 COPYSEQ(sq_inplace_concat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3636 COPYSEQ(sq_inplace_repeat); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3637 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3638 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3639 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
|
3640 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
|
3641 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
|
3642 basebase = NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3643 COPYMAP(mp_length); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3644 COPYMAP(mp_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3645 COPYMAP(mp_ass_subscript); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3646 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3647 |
|
20384
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
3648 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
|
3649 basebase = base->tp_base; |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
3650 if (basebase->tp_as_buffer == NULL) |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
3651 basebase = NULL; |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42477
diff
changeset
|
3652 COPYBUF(bf_getbuffer); |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42477
diff
changeset
|
3653 COPYBUF(bf_releasebuffer); |
|
20384
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
3654 } |
|
2ba4018de2e3
SF bug [#470040] ParseTuple t# vs subclasses.
Tim Peters <tim.peters@gmail.com>
parents:
20382
diff
changeset
|
3655 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3656 basebase = base->tp_base; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3657 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3658 COPYSLOT(tp_dealloc); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3659 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
|
3660 type->tp_getattr = base->tp_getattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3661 type->tp_getattro = base->tp_getattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3662 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3663 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
|
3664 type->tp_setattr = base->tp_setattr; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3665 type->tp_setattro = base->tp_setattro; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3666 } |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51251
diff
changeset
|
3667 /* tp_reserved is ignored */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3668 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
|
3669 /* tp_hash see tp_richcompare */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3670 COPYSLOT(tp_call); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3671 COPYSLOT(tp_str); |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3672 { |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3673 /* Copy comparison-related slots only when |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3674 not overriding them anywhere */ |
|
51247
ba94d7c095e8
Issue #1717, continued: remove PyObject_Compare and Py_CmpToRich declarations
Mark Dickinson <dickinsm@gmail.com>
parents:
51245
diff
changeset
|
3675 if (type->tp_richcompare == NULL && |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3676 type->tp_hash == NULL && |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
3677 !overrides_hash(type)) |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
3678 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3679 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
|
3680 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
|
3681 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3682 } |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3683 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3684 COPYSLOT(tp_iter); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3685 COPYSLOT(tp_iternext); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3686 } |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
3687 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3688 COPYSLOT(tp_descr_get); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3689 COPYSLOT(tp_descr_set); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3690 COPYSLOT(tp_dictoffset); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3691 COPYSLOT(tp_init); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3692 COPYSLOT(tp_alloc); |
|
22848
e589e473f232
Inherit tp_new and tp_is_gc.
Guido van Rossum <guido@python.org>
parents:
22834
diff
changeset
|
3693 COPYSLOT(tp_is_gc); |
|
29201
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3694 if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) == |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3695 (base->tp_flags & Py_TPFLAGS_HAVE_GC)) { |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3696 /* They agree about gc. */ |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3697 COPYSLOT(tp_free); |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3698 } |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3699 else if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) && |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3700 type->tp_free == NULL && |
| 42673 | 3701 base->tp_free == PyObject_Free) { |
|
29201
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3702 /* A bit of magic to plug in the correct default |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3703 * tp_free function when a derived class adds gc, |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3704 * didn't define tp_free, and the base uses the |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3705 * default non-gc tp_free. |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3706 */ |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3707 type->tp_free = PyObject_GC_Del; |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3708 } |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3709 /* else they didn't agree about gc, and there isn't something |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3710 * obvious to be done -- the type is on its own. |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3711 */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3712 } |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3713 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3714 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
3715 static int add_operators(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3716 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3717 int |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19036
diff
changeset
|
3718 PyType_Ready(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3719 { |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3720 PyObject *dict, *bases; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3721 PyTypeObject *base; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3722 Py_ssize_t i, n; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3723 |
|
23756
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
3724 if (type->tp_flags & Py_TPFLAGS_READY) { |
|
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
3725 assert(type->tp_dict != NULL); |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
3726 return 0; |
|
23756
8e5f26796620
Undo the last chunk of the previous patch, putting back a useful
Guido van Rossum <guido@python.org>
parents:
23755
diff
changeset
|
3727 } |
|
19136
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
3728 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
|
3729 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
3730 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
|
3731 |
|
28389
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3732 #ifdef Py_TRACE_REFS |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3733 /* PyType_Ready is the closest thing we have to a choke point |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3734 * for type objects, so is the best place I can think of to try |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3735 * to get type objects into the doubly-linked list of all objects. |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3736 * Still, not all type objects go thru PyType_Ready. |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3737 */ |
|
28396
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28390
diff
changeset
|
3738 _Py_AddToAllObjects((PyObject *)type, 0); |
|
28389
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3739 #endif |
|
4ede57a42c62
Refactored some of the Py_TRACE_REFS code. New private API function
Tim Peters <tim.peters@gmail.com>
parents:
28288
diff
changeset
|
3740 |
|
22871
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
3741 /* Initialize tp_base (defaults to BaseObject unless that's us) */ |
|
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
3742 base = type->tp_base; |
|
33174
f6fa649fc4af
Patch #980082: Missing INCREF in PyType_Ready.
Martin v. Löwis <martin@v.loewis.de>
parents:
32916
diff
changeset
|
3743 if (base == NULL && type != &PyBaseObject_Type) { |
|
22871
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
3744 base = type->tp_base = &PyBaseObject_Type; |
|
33174
f6fa649fc4af
Patch #980082: Missing INCREF in PyType_Ready.
Martin v. Löwis <martin@v.loewis.de>
parents:
32916
diff
changeset
|
3745 Py_INCREF(base); |
|
f6fa649fc4af
Patch #980082: Missing INCREF in PyType_Ready.
Martin v. Löwis <martin@v.loewis.de>
parents:
32916
diff
changeset
|
3746 } |
|
22871
252438bb05d9
- A type can now inherit its metatype from its base type. Previously,
Guido van Rossum <guido@python.org>
parents:
22859
diff
changeset
|
3747 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3748 /* Now the only way base can still be NULL is if type is |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3749 * &PyBaseObject_Type. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3750 */ |
|
36925
7c17e9221f94
Fix three nits found by Coverity, adding null checks and comments.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
3751 |
|
24825
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
3752 /* Initialize the base class */ |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
3753 if (base != NULL && base->tp_dict == NULL) { |
|
24825
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
3754 if (PyType_Ready(base) < 0) |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
3755 goto error; |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
3756 } |
|
c001e5a15369
PyType_Ready(): initialize the base class a bit earlier, so that if we
Guido van Rossum <guido@python.org>
parents:
24795
diff
changeset
|
3757 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3758 /* Initialize ob_type if NULL. This means extensions that want to be |
|
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
|
3759 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
|
3760 initializing the ob_type field of their type objects. */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3761 /* The test for base != NULL is really unnecessary, since base is only |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3762 NULL when type is &PyBaseObject_Type, and we know its ob_type is |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3763 not NULL (it's initialized to &PyType_Type). But coverity doesn't |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3764 know that. */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
3765 if (Py_TYPE(type) == NULL && base != NULL) |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
3766 Py_TYPE(type) = Py_TYPE(base); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3767 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3768 /* Initialize tp_bases */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3769 bases = type->tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3770 if (bases == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3771 if (base == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3772 bases = PyTuple_New(0); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3773 else |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
3774 bases = PyTuple_Pack(1, base); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3775 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
|
3776 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3777 type->tp_bases = bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3778 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3779 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3780 /* 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
|
3781 dict = type->tp_dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3782 if (dict == NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3783 dict = PyDict_New(); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3784 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
|
3785 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
|
3786 type->tp_dict = dict; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3787 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3788 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
3789 /* 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
|
3790 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
|
3791 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3792 if (type->tp_methods != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3793 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
|
3794 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3795 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3796 if (type->tp_members != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3797 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
|
3798 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3799 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3800 if (type->tp_getset != NULL) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3801 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
|
3802 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3803 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3804 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3805 /* Calculate method resolution order */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3806 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
|
3807 goto error; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3808 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3809 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3810 /* 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
|
3811 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
|
3812 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
|
3813 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3814 /* Initialize tp_dict properly */ |
|
20439
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3815 bases = type->tp_mro; |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3816 assert(bases != NULL); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3817 assert(PyTuple_Check(bases)); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3818 n = PyTuple_GET_SIZE(bases); |
|
85571d5f6545
Completely get rid of __dynamic__ and the corresponding
Guido van Rossum <guido@python.org>
parents:
20436
diff
changeset
|
3819 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
|
3820 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
|
3821 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
|
3822 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
|
3823 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3824 |
|
29201
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3825 /* Sanity check for tp_free. */ |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3826 if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) && |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3827 (type->tp_free == NULL || type->tp_free == PyObject_Del)) { |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3828 /* This base class needs to call tp_free, but doesn't have |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3829 * one, or its tp_free is for non-gc'ed objects. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3830 */ |
|
29201
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3831 PyErr_Format(PyExc_TypeError, "type '%.100s' participates in " |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3832 "gc and is a base type but has inappropriate " |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3833 "tp_free slot", |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3834 type->tp_name); |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3835 goto error; |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3836 } |
|
754fd34ad978
PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents:
29173
diff
changeset
|
3837 |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3838 /* 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
|
3839 the tp_doc slot. |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3840 */ |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3841 if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) { |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3842 if (type->tp_doc != NULL) { |
| 42822 | 3843 PyObject *doc = PyUnicode_FromString(type->tp_doc); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
3844 if (doc == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
3845 goto error; |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3846 PyDict_SetItemString(type->tp_dict, "__doc__", doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3847 Py_DECREF(doc); |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3848 } else { |
|
22774
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
3849 PyDict_SetItemString(type->tp_dict, |
|
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
3850 "__doc__", Py_None); |
|
21997
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3851 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3852 } |
|
cb5b4a54ff12
backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents:
21451
diff
changeset
|
3853 |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3854 /* Hack for tp_hash and __hash__. |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3855 If after all that, tp_hash is still NULL, and __hash__ is not in |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
3856 tp_dict, set tp_hash to PyObject_HashNotImplemented and |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
3857 tp_dict['__hash__'] equal to None. |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3858 This signals that __hash__ is not inherited. |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3859 */ |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3860 if (type->tp_hash == NULL) { |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3861 if (PyDict_GetItemString(type->tp_dict, "__hash__") == NULL) { |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3862 if (PyDict_SetItemString(type->tp_dict, "__hash__", Py_None) < 0) |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3863 goto error; |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
3864 type->tp_hash = PyObject_HashNotImplemented; |
|
39623
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3865 } |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3866 } |
|
c6d9fa81f20f
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
3867 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3868 /* 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
|
3869 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
|
3870 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
|
3871 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
|
3872 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
|
3873 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
|
3874 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
|
3875 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
|
3876 type->tp_as_mapping = base->tp_as_mapping; |
|
27821
b804ee5beb49
Fix from SF #681367: inherit tp_as_buffer. This only applies to C
Guido van Rossum <guido@python.org>
parents:
27814
diff
changeset
|
3877 if (type->tp_as_buffer == NULL) |
|
b804ee5beb49
Fix from SF #681367: inherit tp_as_buffer. This only applies to C
Guido van Rossum <guido@python.org>
parents:
27814
diff
changeset
|
3878 type->tp_as_buffer = base->tp_as_buffer; |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3879 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3880 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3881 /* 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
|
3882 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
|
3883 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
|
3884 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
|
3885 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
|
3886 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
|
3887 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
|
3888 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
|
3889 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3890 |
|
51460
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3891 /* Warn for a type that implements tp_compare (now known as |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3892 tp_reserved) but not tp_richcompare. */ |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3893 if (type->tp_reserved && !type->tp_richcompare) { |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3894 int error; |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3895 char msg[240]; |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3896 PyOS_snprintf(msg, sizeof(msg), |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3897 "Type %.100s defines tp_reserved (formerly " |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3898 "tp_compare) but not tp_richcompare. " |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3899 "Comparisons may not behave as intended.", |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3900 type->tp_name); |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3901 error = PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1); |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3902 if (error == -1) |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3903 goto error; |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3904 } |
|
0ed22f1aed04
Issue #1717: add a DeprecationWarning in 3.x on type initialization
Mark Dickinson <dickinsm@gmail.com>
parents:
51270
diff
changeset
|
3905 |
|
19153
64d4ad73a887
- Big changes to fix SF bug #442833 (a nasty multiple inheritance
Guido van Rossum <guido@python.org>
parents:
19136
diff
changeset
|
3906 /* 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
|
3907 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
|
3908 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
|
3909 (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
|
3910 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
|
3911 |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
3912 error: |
|
6463cd9db2fc
Change PyType_Ready() to use the READY and READYING flags. This makes
Guido van Rossum <guido@python.org>
parents:
19109
diff
changeset
|
3913 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
|
3914 return -1; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3915 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3916 |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3917 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
|
3918 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
|
3919 { |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36510
diff
changeset
|
3920 Py_ssize_t i; |
|
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36510
diff
changeset
|
3921 int result; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3922 PyObject *list, *ref, *newobj; |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3923 |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3924 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
|
3925 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
|
3926 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
|
3927 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
|
3928 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
|
3929 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3930 assert(PyList_Check(list)); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3931 newobj = PyWeakref_NewRef((PyObject *)type, NULL); |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3932 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
|
3933 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
|
3934 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
|
3935 assert(PyWeakref_CheckRef(ref)); |
|
25839
243503926c81
Sigh. That wasn't a memory leak, that was Guido committing before
Guido van Rossum <guido@python.org>
parents:
25837
diff
changeset
|
3936 if (PyWeakref_GET_OBJECT(ref) == Py_None) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3937 return PyList_SetItem(list, i, newobj); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3938 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3939 result = PyList_Append(list, newobj); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
3940 Py_DECREF(newobj); |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36510
diff
changeset
|
3941 return result; |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3942 } |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20296
diff
changeset
|
3943 |
| 26421 | 3944 static void |
| 3945 remove_subclass(PyTypeObject *base, PyTypeObject *type) | |
| 3946 { | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3947 Py_ssize_t i; |
| 26421 | 3948 PyObject *list, *ref; |
| 3949 | |
| 3950 list = base->tp_subclasses; | |
| 3951 if (list == NULL) { | |
| 3952 return; | |
| 3953 } | |
| 3954 assert(PyList_Check(list)); | |
| 3955 i = PyList_GET_SIZE(list); | |
| 3956 while (--i >= 0) { | |
| 3957 ref = PyList_GET_ITEM(list, i); | |
| 3958 assert(PyWeakref_CheckRef(ref)); | |
| 3959 if (PyWeakref_GET_OBJECT(ref) == (PyObject*)type) { | |
| 3960 /* this can't fail, right? */ | |
| 3961 PySequence_DelItem(list, i); | |
| 3962 return; | |
| 3963 } | |
| 3964 } | |
| 3965 } | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3966 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3967 static int |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3968 check_num_args(PyObject *ob, int n) |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3969 { |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3970 if (!PyTuple_CheckExact(ob)) { |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3971 PyErr_SetString(PyExc_SystemError, |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3972 "PyArg_UnpackTuple() argument list is not a tuple"); |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3973 return 0; |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3974 } |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3975 if (n == PyTuple_GET_SIZE(ob)) |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3976 return 1; |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3977 PyErr_Format( |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3978 PyExc_TypeError, |
|
36510
0f3894bb2ada
Support %zd in PyErr_Format and PyString_FromFormat.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
3979 "expected %d arguments, got %zd", n, PyTuple_GET_SIZE(ob)); |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3980 return 0; |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3981 } |
|
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3982 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3983 /* 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
|
3984 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3985 /* There's a wrapper *function* for each distinct function typedef used |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
3986 for type object slots (e.g. binaryfunc, ternaryfunc, etc.). There's a |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3987 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
|
3988 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
|
3989 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
|
3990 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3991 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3992 wrap_lenfunc(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
|
3993 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3994 lenfunc func = (lenfunc)wrapped; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
3995 Py_ssize_t res; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3996 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
3997 if (!check_num_args(args, 0)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3998 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
3999 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4000 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4001 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
4002 return PyLong_FromLong((long)res); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4003 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4004 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4005 static PyObject * |
|
30670
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4006 wrap_inquirypred(PyObject *self, PyObject *args, void *wrapped) |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4007 { |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4008 inquiry func = (inquiry)wrapped; |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4009 int res; |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4010 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4011 if (!check_num_args(args, 0)) |
|
30670
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4012 return NULL; |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4013 res = (*func)(self); |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4014 if (res == -1 && PyErr_Occurred()) |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4015 return NULL; |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4016 return PyBool_FromLong((long)res); |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4017 } |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4018 |
|
7f6134f8bd06
SF bug #820397: __nonzero__() returns 1/0
Raymond Hettinger <python@rcn.com>
parents:
30660
diff
changeset
|
4019 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4020 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
|
4021 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4022 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4023 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4024 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4025 if (!check_num_args(args, 1)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4026 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4027 other = PyTuple_GET_ITEM(args, 0); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4028 return (*func)(self, other); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4029 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4030 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4031 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
|
4032 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
|
4033 { |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4034 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
|
4035 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
|
4036 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4037 if (!check_num_args(args, 1)) |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4038 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4039 other = PyTuple_GET_ITEM(args, 0); |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4040 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
|
4041 } |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4042 |
|
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4043 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4044 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
|
4045 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4046 binaryfunc func = (binaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4047 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4048 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4049 if (!check_num_args(args, 1)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4050 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4051 other = PyTuple_GET_ITEM(args, 0); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4052 if (!PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { |
|
20328
26b5f8b94872
It turned out not so difficult to support old-style numbers (those
Guido van Rossum <guido@python.org>
parents:
20320
diff
changeset
|
4053 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
|
4054 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
|
4055 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4056 return (*func)(other, self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4057 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4058 |
|
20140
225f17ec8932
Merge branch changes (coercion, rich comparisons) into trunk.
Guido van Rossum <guido@python.org>
parents:
20095
diff
changeset
|
4059 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4060 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
|
4061 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4062 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4063 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4064 PyObject *third = Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4065 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4066 /* 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
|
4067 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4068 if (!PyArg_UnpackTuple(args, "", 1, 2, &other, &third)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4069 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4070 return (*func)(self, other, third); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4071 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4072 |
|
20168
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
4073 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
|
4074 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
|
4075 { |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
4076 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
|
4077 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
|
4078 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
|
4079 |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
4080 /* 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
|
4081 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4082 if (!PyArg_UnpackTuple(args, "", 1, 2, &other, &third)) |
|
20168
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
4083 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
|
4084 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
|
4085 } |
|
091e9e3ceeaf
Ouch. The wrapper for __rpow__ was the same as for __pow__, resulting
Guido van Rossum <guido@python.org>
parents:
20140
diff
changeset
|
4086 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4087 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4088 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
|
4089 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4090 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4091 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4092 if (!check_num_args(args, 0)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4093 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4094 return (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4095 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4096 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4097 static PyObject * |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
4098 wrap_indexargfunc(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
|
4099 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4100 ssizeargfunc func = (ssizeargfunc)wrapped; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
4101 PyObject* o; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4102 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4103 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
4104 if (!PyArg_UnpackTuple(args, "", 1, 1, &o)) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
4105 return NULL; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
4106 i = PyNumber_AsSsize_t(o, PyExc_OverflowError); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
4107 if (i == -1 && PyErr_Occurred()) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4108 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4109 return (*func)(self, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4110 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4111 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4112 static Py_ssize_t |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4113 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
|
4114 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4115 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4116 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
4117 i = PyNumber_AsSsize_t(arg, PyExc_OverflowError); |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4118 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
|
4119 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4120 if (i < 0) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4121 PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4122 if (sq && sq->sq_length) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4123 Py_ssize_t n = (*sq->sq_length)(self); |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4124 if (n < 0) |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4125 return -1; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4126 i += n; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4127 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4128 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4129 return i; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4130 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4131 |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4132 static PyObject * |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4133 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
|
4134 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4135 ssizeargfunc func = (ssizeargfunc)wrapped; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4136 PyObject *arg; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4137 Py_ssize_t i; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4138 |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4139 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
|
4140 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
|
4141 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
|
4142 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
|
4143 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4144 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
|
4145 } |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4146 check_num_args(args, 1); |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4147 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
|
4148 return NULL; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4149 } |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4150 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4151 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4152 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
|
4153 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4154 ssizeobjargproc func = (ssizeobjargproc)wrapped; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4155 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4156 int res; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4157 PyObject *arg, *value; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4158 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4159 if (!PyArg_UnpackTuple(args, "", 2, 2, &arg, &value)) |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4160 return NULL; |
|
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4161 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
|
4162 if (i == -1 && PyErr_Occurred()) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4163 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4164 res = (*func)(self, i, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4165 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4166 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4167 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4168 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4169 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4170 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4171 static PyObject * |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4172 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
|
4173 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4174 ssizeobjargproc func = (ssizeobjargproc)wrapped; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4175 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4176 int res; |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4177 PyObject *arg; |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4178 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4179 if (!check_num_args(args, 1)) |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4180 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4181 arg = PyTuple_GET_ITEM(args, 0); |
|
19353
051d8e380f38
Address SF bug #442813. The sequence getitem wrappers should do
Guido van Rossum <guido@python.org>
parents:
19349
diff
changeset
|
4182 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
|
4183 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
|
4184 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4185 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
|
4186 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
|
4187 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4188 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4189 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4190 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4191 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4192 /* 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
|
4193 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4194 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
|
4195 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4196 objobjproc func = (objobjproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4197 int res; |
|
30660
36992ca918a3
Fix leak introduced by previous typeobject.c checkin.
Guido van Rossum <guido@python.org>
parents:
30659
diff
changeset
|
4198 PyObject *value; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4199 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4200 if (!check_num_args(args, 1)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4201 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4202 value = PyTuple_GET_ITEM(args, 0); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4203 res = (*func)(self, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4204 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4205 return NULL; |
|
30660
36992ca918a3
Fix leak introduced by previous typeobject.c checkin.
Guido van Rossum <guido@python.org>
parents:
30659
diff
changeset
|
4206 else |
|
36992ca918a3
Fix leak introduced by previous typeobject.c checkin.
Guido van Rossum <guido@python.org>
parents:
30659
diff
changeset
|
4207 return PyBool_FromLong(res); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4208 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4209 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4210 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4211 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
|
4212 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4213 objobjargproc func = (objobjargproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4214 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4215 PyObject *key, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4216 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4217 if (!PyArg_UnpackTuple(args, "", 2, 2, &key, &value)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4218 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4219 res = (*func)(self, key, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4220 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4221 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4222 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4223 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4224 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4225 |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4226 static PyObject * |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4227 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
|
4228 { |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4229 objobjargproc func = (objobjargproc)wrapped; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4230 int res; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4231 PyObject *key; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4232 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4233 if (!check_num_args(args, 1)) |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4234 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4235 key = PyTuple_GET_ITEM(args, 0); |
|
18941
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4236 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
|
4237 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
|
4238 return NULL; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4239 Py_INCREF(Py_None); |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4240 return Py_None; |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4241 } |
|
013cffcfd8a3
Fix SF #442791 (revisited): No __delitem__ wrapper was defined.
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
4242 |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4243 /* Helper to check for object.__setattr__ or __delattr__ applied to a type. |
|
28621
824dc28f922d
Ouch, it's Carlo Verre, not Verre Carlo.
Guido van Rossum <guido@python.org>
parents:
28608
diff
changeset
|
4244 This is called the Carlo Verre hack after its discoverer. */ |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4245 static int |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4246 hackcheck(PyObject *self, setattrofunc func, char *what) |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4247 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4248 PyTypeObject *type = Py_TYPE(self); |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4249 while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE) |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4250 type = type->tp_base; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
4251 /* If type is NULL now, this is a really weird type. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
4252 In the spirit of backwards compatibility (?), just shut up. */ |
|
36925
7c17e9221f94
Fix three nits found by Coverity, adding null checks and comments.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
4253 if (type && type->tp_setattro != func) { |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4254 PyErr_Format(PyExc_TypeError, |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4255 "can't apply this %s to %s object", |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4256 what, |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4257 type->tp_name); |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4258 return 0; |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4259 } |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4260 return 1; |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4261 } |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4262 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4263 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4264 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
|
4265 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4266 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4267 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4268 PyObject *name, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4269 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4270 if (!PyArg_UnpackTuple(args, "", 2, 2, &name, &value)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4271 return NULL; |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4272 if (!hackcheck(self, func, "__setattr__")) |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4273 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4274 res = (*func)(self, name, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4275 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4276 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4277 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4278 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4279 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4280 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4281 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4282 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
|
4283 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4284 setattrofunc func = (setattrofunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4285 int res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4286 PyObject *name; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4287 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4288 if (!check_num_args(args, 1)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4289 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4290 name = PyTuple_GET_ITEM(args, 0); |
|
28608
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4291 if (!hackcheck(self, func, "__delattr__")) |
|
8322077d234c
Close off the "Verre Carlo hack" as discussed on python-dev.
Guido van Rossum <guido@python.org>
parents:
28607
diff
changeset
|
4292 return NULL; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4293 res = (*func)(self, name, NULL); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4294 if (res < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4295 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4296 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4297 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4298 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4299 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4300 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4301 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
|
4302 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4303 hashfunc func = (hashfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4304 long res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4305 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4306 if (!check_num_args(args, 0)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4307 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4308 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4309 if (res == -1 && PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4310 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
4311 return PyLong_FromLong(res); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4312 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4313 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4314 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
|
4315 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
|
4316 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4317 ternaryfunc func = (ternaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4318 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4319 return (*func)(self, args, kwds); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4320 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4321 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4322 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4323 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
|
4324 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4325 richcmpfunc func = (richcmpfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4326 PyObject *other; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4327 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4328 if (!check_num_args(args, 1)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4329 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4330 other = PyTuple_GET_ITEM(args, 0); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4331 return (*func)(self, other, op); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4332 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4333 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4334 #undef RICHCMP_WRAPPER |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4335 #define RICHCMP_WRAPPER(NAME, OP) \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4336 static PyObject * \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4337 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
|
4338 { \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4339 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
|
4340 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4341 |
|
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
|
4342 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
|
4343 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
|
4344 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
|
4345 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
|
4346 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
|
4347 RICHCMP_WRAPPER(ge, Py_GE) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4348 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4349 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4350 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
|
4351 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4352 unaryfunc func = (unaryfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4353 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4354 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4355 if (!check_num_args(args, 0)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4356 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4357 res = (*func)(self); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4358 if (res == NULL && !PyErr_Occurred()) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4359 PyErr_SetNone(PyExc_StopIteration); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4360 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4361 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4362 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4363 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4364 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
|
4365 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4366 descrgetfunc func = (descrgetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4367 PyObject *obj; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4368 PyObject *type = NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4369 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4370 if (!PyArg_UnpackTuple(args, "", 1, 2, &obj, &type)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4371 return NULL; |
|
27811
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4372 if (obj == Py_None) |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4373 obj = NULL; |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4374 if (type == Py_None) |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4375 type = NULL; |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4376 if (type == NULL &&obj == NULL) { |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4377 PyErr_SetString(PyExc_TypeError, |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4378 "__get__(None, None) is invalid"); |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4379 return NULL; |
|
42396a786f59
Add basic arg sanity checking to wrap_descr_get(). This is called
Guido van Rossum <guido@python.org>
parents:
27807
diff
changeset
|
4380 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4381 return (*func)(self, obj, type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4382 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4383 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4384 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
|
4385 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
|
4386 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4387 descrsetfunc func = (descrsetfunc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4388 PyObject *obj, *value; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4389 int ret; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4390 |
|
30671
adc60015670a
Use the simpler and faster PyArg_UnpackTuple() instead of
Raymond Hettinger <python@rcn.com>
parents:
30670
diff
changeset
|
4391 if (!PyArg_UnpackTuple(args, "", 2, 2, &obj, &value)) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4392 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4393 ret = (*func)(self, obj, value); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4394 if (ret < 0) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4395 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4396 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4397 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4398 } |
|
24614
40eb80dc4250
Fix SF bug 574207 (chained __slots__ dealloc segfault).
Guido van Rossum <guido@python.org>
parents:
24460
diff
changeset
|
4399 |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4400 static PyObject * |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4401 wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped) |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4402 { |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4403 descrsetfunc func = (descrsetfunc)wrapped; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4404 PyObject *obj; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4405 int ret; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4406 |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4407 if (!check_num_args(args, 1)) |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4408 return NULL; |
|
31176
381140e7e9d7
Improve argument checking speed.
Raymond Hettinger <python@rcn.com>
parents:
31172
diff
changeset
|
4409 obj = PyTuple_GET_ITEM(args, 0); |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4410 ret = (*func)(self, obj, NULL); |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4411 if (ret < 0) |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4412 return NULL; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4413 Py_INCREF(Py_None); |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4414 return Py_None; |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
4415 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4416 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4417 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
|
4418 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
|
4419 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4420 initproc func = (initproc)wrapped; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4421 |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
4422 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
|
4423 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4424 Py_INCREF(Py_None); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4425 return Py_None; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4426 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4427 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4428 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
|
4429 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
|
4430 { |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4431 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
|
4432 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
|
4433 |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
4434 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
|
4435 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
|
4436 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
|
4437 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
|
4438 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
|
4439 "%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
|
4440 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
|
4441 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
|
4442 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
4443 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
|
4444 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
|
4445 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
|
4446 "%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
|
4447 type->tp_name, |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4448 Py_TYPE(arg0)->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
|
4449 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
|
4450 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
4451 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
|
4452 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
|
4453 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
|
4454 "%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
|
4455 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4456 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4457 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4458 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
|
4459 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
|
4460 } |
|
19429
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4461 |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4462 /* 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
|
4463 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
|
4464 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
|
4465 staticbase = subtype; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4466 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
|
4467 staticbase = staticbase->tp_base; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
4468 /* If staticbase is NULL now, it is a really weird type. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
4469 In the spirit of backwards compatibility (?), just shut up. */ |
|
36925
7c17e9221f94
Fix three nits found by Coverity, adding null checks and comments.
Guido van Rossum <guido@python.org>
parents:
36882
diff
changeset
|
4470 if (staticbase && 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
|
4471 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
|
4472 "%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
|
4473 type->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4474 subtype->tp_name, |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4475 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
|
4476 return NULL; |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4477 } |
|
9cf669581110
Merge changes from r22a2-branch back into trunk. Also, change patch
Barry Warsaw <barry@python.org>
parents:
19353
diff
changeset
|
4478 |
|
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
|
4479 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
|
4480 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
|
4481 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
|
4482 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
|
4483 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
|
4484 return res; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4485 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4486 |
|
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
|
4487 static struct PyMethodDef tp_new_methoddef[] = { |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41769
diff
changeset
|
4488 {"__new__", (PyCFunction)tp_new_wrapper, METH_VARARGS|METH_KEYWORDS, |
|
24795
452d6a916196
Allow more docstrings to be removed during compilation
Neal Norwitz <nnorwitz@gmail.com>
parents:
24789
diff
changeset
|
4489 PyDoc_STR("T.__new__(S, ...) -> " |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
4490 "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
|
4491 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4492 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4493 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4494 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
|
4495 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
|
4496 { |
| 19036 | 4497 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
|
4498 |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
4499 if (PyDict_GetItemString(type->tp_dict, "__new__") != NULL) |
| 19036 | 4500 return 0; |
| 4501 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
|
4502 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
|
4503 return -1; |
| 32407 | 4504 if (PyDict_SetItemString(type->tp_dict, "__new__", func)) { |
|
32404
75e5d1e8b617
Fix leak found by Eric Huss.
Raymond Hettinger <python@rcn.com>
parents:
32323
diff
changeset
|
4505 Py_DECREF(func); |
|
75e5d1e8b617
Fix leak found by Eric Huss.
Raymond Hettinger <python@rcn.com>
parents:
32323
diff
changeset
|
4506 return -1; |
|
75e5d1e8b617
Fix leak found by Eric Huss.
Raymond Hettinger <python@rcn.com>
parents:
32323
diff
changeset
|
4507 } |
|
75e5d1e8b617
Fix leak found by Eric Huss.
Raymond Hettinger <python@rcn.com>
parents:
32323
diff
changeset
|
4508 Py_DECREF(func); |
|
75e5d1e8b617
Fix leak found by Eric Huss.
Raymond Hettinger <python@rcn.com>
parents:
32323
diff
changeset
|
4509 return 0; |
|
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
|
4510 } |
|
c1daa94c21d8
A totally new way to do the __new__ wrapper. This should address the
Guido van Rossum <guido@python.org>
parents:
18941
diff
changeset
|
4511 |
| 19036 | 4512 /* Slot wrappers that call the corresponding __foo__ slot. See comments |
| 4513 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
|
4514 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4515 #define SLOT0(FUNCNAME, OPSTR) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4516 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4517 FUNCNAME(PyObject *self) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4518 { \ |
|
19540
e141b392b61d
Fix a typo in SLOT0 macro for the declaration of cache_str.
Guido van Rossum <guido@python.org>
parents:
19538
diff
changeset
|
4519 static PyObject *cache_str; \ |
| 19911 | 4520 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
|
4521 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4522 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4523 #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
|
4524 static PyObject * \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4525 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
|
4526 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4527 static PyObject *cache_str; \ |
| 19911 | 4528 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
|
4529 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4530 |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4531 /* Boolean helper for SLOT1BINFULL(). |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4532 right.__class__ is a nontrivial subclass of left.__class__. */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4533 static int |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4534 method_is_overloaded(PyObject *left, PyObject *right, char *name) |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4535 { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4536 PyObject *a, *b; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4537 int ok; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4538 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4539 b = PyObject_GetAttrString((PyObject *)(Py_TYPE(right)), name); |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4540 if (b == NULL) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4541 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4542 /* If right doesn't have it, it's not overloaded */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4543 return 0; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4544 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4545 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4546 a = PyObject_GetAttrString((PyObject *)(Py_TYPE(left)), name); |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4547 if (a == NULL) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4548 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4549 Py_DECREF(b); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4550 /* If right has it but left doesn't, it's overloaded */ |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4551 return 1; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4552 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4553 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4554 ok = PyObject_RichCompareBool(a, b, Py_NE); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4555 Py_DECREF(a); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4556 Py_DECREF(b); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4557 if (ok < 0) { |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4558 PyErr_Clear(); |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4559 return 0; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4560 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4561 |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4562 return ok; |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4563 } |
|
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4564 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4565 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4566 #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
|
4567 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4568 FUNCNAME(PyObject *self, PyObject *other) \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4569 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4570 static PyObject *cache_str, *rcache_str; \ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4571 int do_other = Py_TYPE(self) != Py_TYPE(other) && \ |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4572 Py_TYPE(other)->tp_as_number != NULL && \ |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4573 Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4574 if (Py_TYPE(self)->tp_as_number != NULL && \ |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4575 Py_TYPE(self)->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
|
4576 PyObject *r; \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4577 if (do_other && \ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4578 PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self)) && \ |
|
27124
d1850a36ae41
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
Guido van Rossum <guido@python.org>
parents:
26964
diff
changeset
|
4579 method_is_overloaded(self, other, ROPSTR)) { \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4580 r = call_maybe( \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4581 other, ROPSTR, &rcache_str, "(O)", self); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4582 if (r != Py_NotImplemented) \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4583 return r; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4584 Py_DECREF(r); \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4585 do_other = 0; \ |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4586 } \ |
|
19913
ca0f54dacdd8
Add call_maybe(): a variant of call_method() that returns
Guido van Rossum <guido@python.org>
parents:
19911
diff
changeset
|
4587 r = call_maybe( \ |
| 19911 | 4588 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
|
4589 if (r != Py_NotImplemented || \ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4590 Py_TYPE(other) == Py_TYPE(self)) \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4591 return r; \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4592 Py_DECREF(r); \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4593 } \ |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4594 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
|
4595 return call_maybe( \ |
| 19911 | 4596 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
|
4597 } \ |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4598 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
|
4599 return Py_NotImplemented; \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4600 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4601 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4602 #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
|
4603 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
|
4604 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4605 #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
|
4606 static PyObject * \ |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4607 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
|
4608 { \ |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4609 static PyObject *cache_str; \ |
| 19911 | 4610 return call_method(self, OPSTR, &cache_str, \ |
| 4611 "(" ARGCODES ")", arg1, arg2); \ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4612 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4613 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4614 static Py_ssize_t |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4615 slot_sq_length(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4616 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4617 static PyObject *len_str; |
| 19911 | 4618 PyObject *res = call_method(self, "__len__", &len_str, "()"); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4619 Py_ssize_t len; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4620 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4621 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4622 return -1; |
|
51477
8cfa108e7bdc
fix len() when __len__() returns a non number type #5137
Benjamin Peterson <benjamin@python.org>
parents:
51460
diff
changeset
|
4623 len = PyNumber_AsSsize_t(res, PyExc_OverflowError); |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
4624 Py_DECREF(res); |
|
24376
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
4625 if (len < 0) { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
4626 if (!PyErr_Occurred()) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
4627 PyErr_SetString(PyExc_ValueError, |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
4628 "__len__() should return >= 0"); |
|
24376
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
4629 return -1; |
|
aa9e054270a2
Complain if __len__() returns < 0, just like classic classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24280
diff
changeset
|
4630 } |
|
20197
b4f0f10a6c5f
slot_sq_length(): squash a leak.
Guido van Rossum <guido@python.org>
parents:
20195
diff
changeset
|
4631 return len; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4632 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4633 |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4634 /* 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
|
4635 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
|
4636 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4637 slot_sq_item(PyObject *self, Py_ssize_t i) |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4638 { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4639 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
|
4640 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
|
4641 descrgetfunc f; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4642 |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4643 if (getitem_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
4644 getitem_str = PyUnicode_InternFromString("__getitem__"); |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4645 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
|
4646 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4647 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4648 func = _PyType_Lookup(Py_TYPE(self), getitem_str); |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4649 if (func != NULL) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4650 if ((f = Py_TYPE(func)->tp_descr_get) == NULL) |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4651 Py_INCREF(func); |
|
25853
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
4652 else { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4653 func = f(func, self, (PyObject *)(Py_TYPE(self))); |
|
25853
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
4654 if (func == NULL) { |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
4655 return NULL; |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
4656 } |
|
680bfcc9ca06
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Neal Norwitz <nnorwitz@gmail.com>
parents:
25839
diff
changeset
|
4657 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
4658 ival = PyLong_FromSsize_t(i); |
|
20229
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4659 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
|
4660 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
|
4661 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
|
4662 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
|
4663 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
|
4664 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
|
4665 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
|
4666 return retval; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4667 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4668 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4669 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4670 else { |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4671 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
|
4672 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4673 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
|
4674 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
|
4675 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
|
4676 return NULL; |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4677 } |
|
8bad55edfdf3
*EXPERIMENTAL* speedup of slot_sq_item. This sped up the following
Guido van Rossum <guido@python.org>
parents:
20225
diff
changeset
|
4678 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4679 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
4680 slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4681 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4682 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
|
4683 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
|
4684 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4685 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
|
4686 res = call_method(self, "__delitem__", &delitem_str, |
|
37881
702d85d9418a
Merge trunk up to 45598.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4687 "(n)", index); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4688 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4689 res = call_method(self, "__setitem__", &setitem_str, |
|
37881
702d85d9418a
Merge trunk up to 45598.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4690 "(nO)", index, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4691 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4692 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4693 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4694 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4695 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4696 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4697 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4698 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
|
4699 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4700 PyObject *func, *res, *args; |
|
28390
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4701 int result = -1; |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4702 |
|
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
|
4703 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
|
4704 |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4705 func = lookup_maybe(self, "__contains__", &contains_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4706 if (func != NULL) { |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
4707 args = PyTuple_Pack(1, value); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4708 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4709 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4710 else { |
| 19911 | 4711 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
|
4712 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4713 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4714 Py_DECREF(func); |
|
28390
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4715 if (res != NULL) { |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4716 result = PyObject_IsTrue(res); |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4717 Py_DECREF(res); |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4718 } |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4719 } |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4720 else if (! PyErr_Occurred()) { |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36675
diff
changeset
|
4721 /* Possible results: -1 and 1 */ |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36675
diff
changeset
|
4722 result = (int)_PySequence_IterSearch(self, value, |
|
28390
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4723 PY_ITERSEARCH_CONTAINS); |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4724 } |
|
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
4725 return result; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4726 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4727 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4728 #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
|
4729 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4730 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
|
4731 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4732 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4733 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
|
4734 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4735 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
|
4736 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
|
4737 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4738 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
|
4739 res = call_method(self, "__delitem__", &delitem_str, |
| 19911 | 4740 "(O)", key); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4741 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4742 res = call_method(self, "__setitem__", &setitem_str, |
| 19911 | 4743 "(OO)", key, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4744 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4745 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4746 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4747 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4748 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4749 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4750 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
|
4751 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
|
4752 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
|
4753 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
|
4754 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
|
4755 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24250
diff
changeset
|
4756 static PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *); |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4757 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4758 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
|
4759 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
|
4760 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4761 static PyObject * |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4762 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
|
4763 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
4764 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
|
4765 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4766 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
|
4767 return slot_nb_power_binary(self, other); |
|
23753
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4768 /* Three-arg power doesn't use __rpow__. But ternary_op |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4769 can call this when the second argument's type uses |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4770 slot_nb_power, so check before calling self.__pow__. */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4771 if (Py_TYPE(self)->tp_as_number != NULL && |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4772 Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { |
|
23753
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4773 return call_method(self, "__pow__", &pow_str, |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4774 "(OO)", other, modulus); |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4775 } |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4776 Py_INCREF(Py_NotImplemented); |
|
41097e92f560
Three's a charm: yet another fix for SF bug 551412. Thinking again
Guido van Rossum <guido@python.org>
parents:
23666
diff
changeset
|
4777 return Py_NotImplemented; |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4778 } |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4779 |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4780 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
|
4781 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
|
4782 SLOT0(slot_nb_absolute, "__abs__") |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4783 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4784 static int |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4785 slot_nb_bool(PyObject *self) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4786 { |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4787 PyObject *func, *args; |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4788 static PyObject *bool_str, *len_str; |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4789 int result = -1; |
|
52258
3ab2e52d8d19
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51477
diff
changeset
|
4790 int using_len = 0; |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4791 |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4792 func = lookup_maybe(self, "__bool__", &bool_str); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4793 if (func == NULL) { |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4794 if (PyErr_Occurred()) |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4795 return -1; |
|
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4796 func = lookup_maybe(self, "__len__", &len_str); |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4797 if (func == NULL) |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4798 return PyErr_Occurred() ? -1 : 1; |
|
52258
3ab2e52d8d19
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51477
diff
changeset
|
4799 using_len = 1; |
|
3ab2e52d8d19
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51477
diff
changeset
|
4800 } |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4801 args = PyTuple_New(0); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4802 if (args != NULL) { |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4803 PyObject *temp = PyObject_Call(func, args, NULL); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4804 Py_DECREF(args); |
|
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4805 if (temp != NULL) { |
|
52258
3ab2e52d8d19
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51477
diff
changeset
|
4806 if (using_len) { |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4807 /* enforced by slot_nb_len */ |
|
29607
60b53db14aa3
Check return type of __nonzero__() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29442
diff
changeset
|
4808 result = PyObject_IsTrue(temp); |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4809 } |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4810 else if (PyBool_Check(temp)) { |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4811 result = PyObject_IsTrue(temp); |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
4812 } |
|
29607
60b53db14aa3
Check return type of __nonzero__() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29442
diff
changeset
|
4813 else { |
|
60b53db14aa3
Check return type of __nonzero__() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29442
diff
changeset
|
4814 PyErr_Format(PyExc_TypeError, |
|
55131
59cf5f808c24
Merged revisions 73868 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54555
diff
changeset
|
4815 "__bool__ should return " |
|
59cf5f808c24
Merged revisions 73868 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54555
diff
changeset
|
4816 "bool, returned %s", |
|
52258
3ab2e52d8d19
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51477
diff
changeset
|
4817 Py_TYPE(temp)->tp_name); |
|
29611
cac855387b56
Require that __nonzero__() return a bool or exactly an int.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29607
diff
changeset
|
4818 result = -1; |
|
29607
60b53db14aa3
Check return type of __nonzero__() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29442
diff
changeset
|
4819 } |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4820 Py_DECREF(temp); |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4821 } |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4822 } |
|
20204
8e6f604b0799
Miscellaneous code fiddling:
Guido van Rossum <guido@python.org>
parents:
20197
diff
changeset
|
4823 Py_DECREF(func); |
|
26575
93b5ca9423eb
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
Tim Peters <tim.peters@gmail.com>
parents:
26559
diff
changeset
|
4824 return result; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4825 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4826 |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4827 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
4828 static PyObject * |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4829 slot_nb_index(PyObject *self) |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4830 { |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4831 static PyObject *index_str; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
4832 return call_method(self, "__index__", &index_str, "()"); |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4833 } |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4834 |
|
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
4835 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4836 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
|
4837 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
|
4838 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
|
4839 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
|
4840 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
|
4841 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
|
4842 |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4843 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
|
4844 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
|
4845 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
|
4846 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
|
4847 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
|
4848 SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O") |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4849 /* Can't use SLOT1 here, because nb_inplace_power is ternary */ |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4850 static PyObject * |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4851 slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4852 { |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4853 static PyObject *cache_str; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4854 return call_method(self, "__ipow__", &cache_str, "(" "O" ")", arg1); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40809
diff
changeset
|
4855 } |
|
19082
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4856 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
|
4857 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
|
4858 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
|
4859 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
|
4860 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
|
4861 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
|
4862 "__floordiv__", "__rfloordiv__") |
|
88d124c74766
Proper support for binary operators, including true division and floor
Guido van Rossum <guido@python.org>
parents:
19070
diff
changeset
|
4863 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
|
4864 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
|
4865 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
|
4866 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4867 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4868 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
|
4869 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4870 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
|
4871 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
|
4872 |
|
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
|
4873 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
|
4874 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4875 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
|
4876 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4877 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4878 } |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
19469
diff
changeset
|
4879 PyErr_Clear(); |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4880 return PyUnicode_FromFormat("<%s object at %p>", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4881 Py_TYPE(self)->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
|
4882 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4883 |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4884 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4885 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
|
4886 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4887 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
|
4888 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
|
4889 |
|
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
|
4890 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
|
4891 if (func != NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4892 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
|
4893 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4894 return res; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4895 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4896 else { |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4897 PyObject *ress; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4898 PyErr_Clear(); |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4899 res = slot_tp_repr(self); |
|
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4900 if (!res) |
|
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4901 return NULL; |
|
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4902 ress = _PyUnicode_AsDefaultEncodedString(res, NULL); |
|
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4903 Py_DECREF(res); |
|
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
4904 return ress; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4905 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4906 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4907 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4908 static long |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4909 slot_tp_hash(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4910 { |
|
39548
67e45704c07e
Fix non-C89-compatible syntax.
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
4911 PyObject *func, *res; |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4912 static PyObject *hash_str; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4913 long h; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4914 |
|
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
|
4915 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
|
4916 |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4917 if (func == Py_None) { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
4918 Py_DECREF(func); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4919 func = NULL; |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4920 } |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4921 |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4922 if (func == NULL) { |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
4923 return PyObject_HashNotImplemented(self); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4924 } |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4925 |
|
39548
67e45704c07e
Fix non-C89-compatible syntax.
Guido van Rossum <guido@python.org>
parents:
39536
diff
changeset
|
4926 res = PyEval_CallObject(func, NULL); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4927 Py_DECREF(func); |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4928 if (res == NULL) |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4929 return -1; |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4930 if (PyLong_Check(res)) |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4931 h = PyLong_Type.tp_hash(res); |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4932 else |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
4933 h = PyLong_AsLong(res); |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4934 Py_DECREF(res); |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4935 if (h == -1 && !PyErr_Occurred()) |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4936 h = -2; |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
4937 return h; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4938 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4939 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4940 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4941 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
|
4942 { |
|
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
|
4943 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
|
4944 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
|
4945 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4946 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4947 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4948 return NULL; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4949 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4950 res = PyObject_Call(meth, args, kwds); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
4951 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4952 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4953 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4954 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4955 |
|
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
|
4956 /* 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
|
4957 |
|
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
|
4958 - 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
|
4959 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
|
4960 |
|
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
|
4961 - 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
|
4962 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4963 The code in update_one_slot() always installs slot_tp_getattr_hook(); this |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4964 detects the absence of __getattr__ and then installs the simpler slot if |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
4965 necessary. */ |
|
20499
a0c8c2e5a44d
Remove a bunch of stuff that's no longer needed now that update_slot()
Guido van Rossum <guido@python.org>
parents:
20489
diff
changeset
|
4966 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4967 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4968 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
|
4969 { |
|
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
|
4970 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
|
4971 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
|
4972 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4973 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
4974 |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4975 static PyObject * |
|
49742
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4976 call_attribute(PyObject *self, PyObject *attr, PyObject *name) |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4977 { |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4978 PyObject *res, *descr = NULL; |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4979 descrgetfunc f = Py_TYPE(attr)->tp_descr_get; |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4980 |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4981 if (f != NULL) { |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4982 descr = f(attr, self, (PyObject *)(Py_TYPE(self))); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4983 if (descr == NULL) |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4984 return NULL; |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4985 else |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4986 attr = descr; |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4987 } |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4988 res = PyObject_CallFunctionObjArgs(attr, name, NULL); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4989 Py_XDECREF(descr); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4990 return res; |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4991 } |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4992 |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
4993 static PyObject * |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4994 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
|
4995 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
4996 PyTypeObject *tp = Py_TYPE(self); |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4997 PyObject *getattr, *getattribute, *res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
4998 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
|
4999 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
|
5000 |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5001 if (getattr_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5002 getattr_str = PyUnicode_InternFromString("__getattr__"); |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5003 if (getattr_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5004 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5005 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5006 if (getattribute_str == NULL) { |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5007 getattribute_str = |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5008 PyUnicode_InternFromString("__getattribute__"); |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5009 if (getattribute_str == NULL) |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5010 return NULL; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5011 } |
|
49742
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5012 /* speed hack: we could use lookup_maybe, but that would resolve the |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5013 method fully for each attribute lookup for classes with |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5014 __getattr__, even when the attribute is present. So we use |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5015 _PyType_Lookup and create the method only when needed, with |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5016 call_attribute. */ |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5017 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
|
5018 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
|
5019 /* 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
|
5020 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
|
5021 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
|
5022 } |
|
49742
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5023 Py_INCREF(getattr); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5024 /* speed hack: we could use lookup_maybe, but that would resolve the |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5025 method fully for each attribute lookup for classes with |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5026 __getattr__, even when self has the default __getattribute__ |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5027 method. So we use _PyType_Lookup and create the method only when |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5028 needed, with call_attribute. */ |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5029 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
|
5030 if (getattribute == NULL || |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5031 (Py_TYPE(getattribute) == &PyWrapperDescr_Type && |
|
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
|
5032 ((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
|
5033 (void *)PyObject_GenericGetAttr)) |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5034 res = PyObject_GenericGetAttr(self, name); |
|
49742
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5035 else { |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5036 Py_INCREF(getattribute); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5037 res = call_attribute(self, getattribute, name); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5038 Py_DECREF(getattribute); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5039 } |
|
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
|
5040 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
|
5041 PyErr_Clear(); |
|
49742
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5042 res = call_attribute(self, getattr, name); |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5043 } |
|
356c3e18da5e
Merged revisions 67246 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49518
diff
changeset
|
5044 Py_DECREF(getattr); |
|
20028
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5045 return res; |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5046 } |
|
df1b83fd0ebb
Add the __getattr__ hook back. The rules are now:
Guido van Rossum <guido@python.org>
parents:
20021
diff
changeset
|
5047 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5048 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5049 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
|
5050 { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5051 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
|
5052 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
|
5053 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5054 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
|
5055 res = call_method(self, "__delattr__", &delattr_str, |
| 19911 | 5056 "(O)", name); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5057 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
5058 res = call_method(self, "__setattr__", &setattr_str, |
| 19911 | 5059 "(OO)", name, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5060 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5061 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5062 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5063 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5064 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5065 |
|
44407
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5066 static char *name_op[] = { |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5067 "__lt__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5068 "__le__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5069 "__eq__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5070 "__ne__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5071 "__gt__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5072 "__ge__", |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5073 }; |
|
dda29e712815
Merge changes from 59576 from trunk to p3yk branch; these were skipped
Guido van Rossum <guido@python.org>
parents:
44351
diff
changeset
|
5074 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5075 static PyObject * |
|
57273
c5099818e0d4
Issue #6970: Remove redundant calls made when comparing objects.
Mark Dickinson <dickinsm@gmail.com>
parents:
55399
diff
changeset
|
5076 slot_tp_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
|
5077 { |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5078 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
|
5079 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
|
5080 |
|
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
|
5081 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
|
5082 if (func == NULL) { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5083 PyErr_Clear(); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5084 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
|
5085 return Py_NotImplemented; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5086 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30671
diff
changeset
|
5087 args = PyTuple_Pack(1, other); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5088 if (args == NULL) |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5089 res = NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5090 else { |
| 19911 | 5091 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
|
5092 Py_DECREF(args); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5093 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5094 Py_DECREF(func); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5095 return res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5096 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5097 |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5098 static PyObject * |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5099 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
|
5100 { |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5101 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
|
5102 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
|
5103 |
|
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
|
5104 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
|
5105 if (func != NULL) { |
|
24867
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5106 PyObject *args; |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5107 args = res = PyTuple_New(0); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5108 if (args != NULL) { |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5109 res = PyObject_Call(func, args, NULL); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5110 Py_DECREF(args); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5111 } |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5112 Py_DECREF(func); |
|
255d1d3e66a3
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
Guido van Rossum <guido@python.org>
parents:
24862
diff
changeset
|
5113 return res; |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5114 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5115 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
|
5116 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
|
5117 if (func == NULL) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
5118 PyErr_Format(PyExc_TypeError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
5119 "'%.200s' object is not iterable", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5120 Py_TYPE(self)->tp_name); |
|
19289
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5121 return NULL; |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5122 } |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5123 Py_DECREF(func); |
|
5c2bf6cde123
- Another big step in the right direction. All the overridable
Guido van Rossum <guido@python.org>
parents:
19253
diff
changeset
|
5124 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
|
5125 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5126 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5127 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5128 slot_tp_iternext(PyObject *self) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5129 { |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
5130 static PyObject *next_str; |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41324
diff
changeset
|
5131 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
|
5132 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5133 |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5134 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
|
5135 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
|
5136 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5137 PyTypeObject *tp = Py_TYPE(self); |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5138 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
|
5139 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
|
5140 |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5141 if (get_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5142 get_str = PyUnicode_InternFromString("__get__"); |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5143 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
|
5144 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
|
5145 } |
|
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5146 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
|
5147 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
|
5148 /* 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
|
5149 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
|
5150 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
|
5151 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
|
5152 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
|
5153 } |
|
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
|
5154 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
|
5155 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
|
5156 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
|
5157 type = Py_None; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37881
diff
changeset
|
5158 return PyObject_CallFunctionObjArgs(get, self, obj, type, NULL); |
|
19339
6130deeb4cc6
type_new(): look for __dynamic__ at the module level (after looking in
Guido van Rossum <guido@python.org>
parents:
19329
diff
changeset
|
5159 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5160 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5161 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5162 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
|
5163 { |
|
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
|
5164 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
|
5165 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
|
5166 |
|
45d0e114212e
slot_tp_descr_get(): guard against NULL obj or type (bug reported by
Guido van Rossum <guido@python.org>
parents:
19429
diff
changeset
|
5167 if (value == NULL) |
|
21142
842b280421ba
Fix for SF bug #485678.
Guido van Rossum <guido@python.org>
parents:
20978
diff
changeset
|
5168 res = call_method(self, "__delete__", &del_str, |
| 19911 | 5169 "(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
|
5170 else |
|
19538
b4a3fc147929
Finish the previous checkin: also avoid getattr when calling the method
Guido van Rossum <guido@python.org>
parents:
19535
diff
changeset
|
5171 res = call_method(self, "__set__", &set_str, |
| 19911 | 5172 "(OO)", target, value); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5173 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5174 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5175 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5176 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5177 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5178 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5179 static int |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5180 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
|
5181 { |
|
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
|
5182 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
|
5183 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
|
5184 PyObject *res; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5185 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5186 if (meth == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5187 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5188 res = PyObject_Call(meth, args, kwds); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5189 Py_DECREF(meth); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5190 if (res == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5191 return -1; |
|
34668
9b3a2c4302aa
SF bug #1155938: Missing None check for __init__().
Raymond Hettinger <python@rcn.com>
parents:
33541
diff
changeset
|
5192 if (res != Py_None) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
5193 PyErr_Format(PyExc_TypeError, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
5194 "__init__() should return None, not '%.200s'", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5195 Py_TYPE(res)->tp_name); |
|
34668
9b3a2c4302aa
SF bug #1155938: Missing None check for __init__().
Raymond Hettinger <python@rcn.com>
parents:
33541
diff
changeset
|
5196 Py_DECREF(res); |
|
9b3a2c4302aa
SF bug #1155938: Missing None check for __init__().
Raymond Hettinger <python@rcn.com>
parents:
33541
diff
changeset
|
5197 return -1; |
|
9b3a2c4302aa
SF bug #1155938: Missing None check for __init__().
Raymond Hettinger <python@rcn.com>
parents:
33541
diff
changeset
|
5198 } |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5199 Py_DECREF(res); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5200 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5201 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5202 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5203 static PyObject * |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5204 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
|
5205 { |
|
24680
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5206 static PyObject *new_str; |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5207 PyObject *func; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5208 PyObject *newargs, *x; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5209 Py_ssize_t i, n; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5210 |
|
24680
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5211 if (new_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5212 new_str = PyUnicode_InternFromString("__new__"); |
|
24680
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5213 if (new_str == NULL) |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5214 return NULL; |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5215 } |
|
6d26d4b9c5a3
Significant speedup in new-style object creation: in slot_tp_new(),
Guido van Rossum <guido@python.org>
parents:
24678
diff
changeset
|
5216 func = PyObject_GetAttr((PyObject *)type, new_str); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5217 if (func == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5218 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5219 assert(PyTuple_Check(args)); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5220 n = PyTuple_GET_SIZE(args); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5221 newargs = PyTuple_New(n+1); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5222 if (newargs == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5223 return NULL; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5224 Py_INCREF(type); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5225 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
|
5226 for (i = 0; i < n; i++) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5227 x = PyTuple_GET_ITEM(args, i); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5228 Py_INCREF(x); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5229 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
|
5230 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5231 x = PyObject_Call(func, newargs, kwds); |
|
20195
3408d929bb94
slot_tp_new(): newargs was leaking.
Guido van Rossum <guido@python.org>
parents:
20190
diff
changeset
|
5232 Py_DECREF(newargs); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5233 Py_DECREF(func); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5234 return x; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5235 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5236 |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5237 static void |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5238 slot_tp_del(PyObject *self) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5239 { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5240 static PyObject *del_str = NULL; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5241 PyObject *del, *res; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5242 PyObject *error_type, *error_value, *error_traceback; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5243 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5244 /* Temporarily resurrect the object. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5245 assert(self->ob_refcnt == 0); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5246 self->ob_refcnt = 1; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5247 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5248 /* Save the current exception, if any. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5249 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5250 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5251 /* Execute __del__ method, if any. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5252 del = lookup_maybe(self, "__del__", &del_str); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5253 if (del != NULL) { |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5254 res = PyEval_CallObject(del, NULL); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5255 if (res == NULL) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5256 PyErr_WriteUnraisable(del); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5257 else |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5258 Py_DECREF(res); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5259 Py_DECREF(del); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5260 } |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5261 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5262 /* Restore the saved exception. */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5263 PyErr_Restore(error_type, error_value, error_traceback); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5264 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5265 /* Undo the temporary resurrection; can't use DECREF here, it would |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5266 * cause a recursive call. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5267 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5268 assert(self->ob_refcnt > 0); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5269 if (--self->ob_refcnt == 0) |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5270 return; /* this is the normal path out */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5271 |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5272 /* __del__ resurrected it! Make it look like the original Py_DECREF |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5273 * never happened. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5274 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5275 { |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36675
diff
changeset
|
5276 Py_ssize_t refcnt = self->ob_refcnt; |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5277 _Py_NewReference(self); |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5278 self->ob_refcnt = refcnt; |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5279 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5280 assert(!PyType_IS_GC(Py_TYPE(self)) || |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5281 _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); |
|
32916
ff77727555ae
Repair the same thinko in two places about handling of _Py_RefTotal in
Michael W. Hudson <mwh@python.net>
parents:
32407
diff
changeset
|
5282 /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so |
|
ff77727555ae
Repair the same thinko in two places about handling of _Py_RefTotal in
Michael W. Hudson <mwh@python.net>
parents:
32407
diff
changeset
|
5283 * we need to undo that. */ |
|
ff77727555ae
Repair the same thinko in two places about handling of _Py_RefTotal in
Michael W. Hudson <mwh@python.net>
parents:
32407
diff
changeset
|
5284 _Py_DEC_REFTOTAL; |
|
ff77727555ae
Repair the same thinko in two places about handling of _Py_RefTotal in
Michael W. Hudson <mwh@python.net>
parents:
32407
diff
changeset
|
5285 /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object |
|
ff77727555ae
Repair the same thinko in two places about handling of _Py_RefTotal in
Michael W. Hudson <mwh@python.net>
parents:
32407
diff
changeset
|
5286 * chain, so no more to do there. |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5287 * If COUNT_ALLOCS, the original decref bumped tp_frees, and |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5288 * _Py_NewReference bumped tp_allocs: both of those need to be |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5289 * undone. |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5290 */ |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5291 #ifdef COUNT_ALLOCS |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5292 --Py_TYPE(self)->tp_frees; |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5293 --Py_TYPE(self)->tp_allocs; |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5294 #endif |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5295 } |
|
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5296 |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5297 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5298 /* Table mapping __foo__ names to tp_foo offsets and slot_tp_foo wrapper |
|
28390
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
5299 functions. The offsets here are relative to the 'PyHeapTypeObject' |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5300 structure, which incorporates the additional structures used for numbers, |
|
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5301 sequences and mappings. |
|
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5302 Note that multiple names may map to the same slot (e.g. __eq__, |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5303 __ne__ etc. all map to tp_richcompare) and one name may map to multiple |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5304 slots (e.g. __str__ affects tp_str as well as tp_repr). The table is |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5305 terminated with an all-zero entry. (This table is further initialized and |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5306 sorted in init_slotdefs() below.) */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5307 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5308 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
|
5309 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5310 #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
|
5311 #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
|
5312 #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
|
5313 #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
|
5314 #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
|
5315 #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
|
5316 #undef UNSLOT |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5317 #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
|
5318 #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
|
5319 #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
|
5320 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5321 #define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
5322 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
5323 PyDoc_STR(DOC)} |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
5324 #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
|
5325 {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
5326 PyDoc_STR(DOC), FLAGS} |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5327 #define ETSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \ |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5328 {NAME, offsetof(PyHeapTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \ |
|
24789
fcbde226545c
Allow docstrings to be removed during compilation for *SLOT macro and friends
Neal Norwitz <nnorwitz@gmail.com>
parents:
24785
diff
changeset
|
5329 PyDoc_STR(DOC)} |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5330 #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
|
5331 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
|
5332 #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
|
5333 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
|
5334 #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
|
5335 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
|
5336 #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
|
5337 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
|
5338 "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
|
5339 #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
|
5340 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
|
5341 "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
|
5342 #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
|
5343 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
|
5344 "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
|
5345 #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
|
5346 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
|
5347 "x." NAME "(y) <==> y" DOC "x") |
|
35004
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5348 #define BINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) \ |
|
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5349 ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \ |
|
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5350 "x." NAME "(y) <==> " DOC) |
|
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5351 #define RBINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) \ |
|
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5352 ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \ |
|
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5353 "x." NAME "(y) <==> " DOC) |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5354 |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5355 static slotdef slotdefs[] = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5356 SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5357 "x.__len__() <==> len(x)"), |
| 36150 | 5358 /* Heap types defining __add__/__mul__ have sq_concat/sq_repeat == NULL. |
| 5359 The logic in abstract.c always falls back to nb_add/nb_multiply in | |
| 5360 this case. Defining both the nb_* and the sq_* slots to call the | |
| 5361 user-defined methods has unexpected side-effects, as shown by | |
| 5362 test_descr.notimplemented() */ | |
| 5363 SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc, | |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5364 "x.__add__(y) <==> x+y"), |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5365 SQSLOT("__mul__", sq_repeat, NULL, wrap_indexargfunc, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5366 "x.__mul__(n) <==> x*n"), |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5367 SQSLOT("__rmul__", sq_repeat, NULL, wrap_indexargfunc, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5368 "x.__rmul__(n) <==> n*x"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5369 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
|
5370 "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
|
5371 SQSLOT("__setitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_setitem, |
|
29173
421ffd7c57af
Fixing the previous patch to have the changes be to the proper docstrings.
Brett Cannon <bcannon@gmail.com>
parents:
29172
diff
changeset
|
5372 "x.__setitem__(i, y) <==> x[i]=y"), |
|
421ffd7c57af
Fixing the previous patch to have the changes be to the proper docstrings.
Brett Cannon <bcannon@gmail.com>
parents:
29172
diff
changeset
|
5373 SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem, |
|
421ffd7c57af
Fixing the previous patch to have the changes be to the proper docstrings.
Brett Cannon <bcannon@gmail.com>
parents:
29172
diff
changeset
|
5374 "x.__delitem__(y) <==> del x[y]"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5375 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
|
5376 "x.__contains__(y) <==> y in x"), |
| 36150 | 5377 SQSLOT("__iadd__", sq_inplace_concat, NULL, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5378 wrap_binaryfunc, "x.__iadd__(y) <==> x+=y"), |
| 36150 | 5379 SQSLOT("__imul__", sq_inplace_repeat, NULL, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5380 wrap_indexargfunc, "x.__imul__(y) <==> x*=y"), |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5381 |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5382 MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5383 "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
|
5384 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
|
5385 wrap_binaryfunc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5386 "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
|
5387 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
|
5388 wrap_objobjargproc, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5389 "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
|
5390 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
|
5391 wrap_delitem, |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5392 "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
|
5393 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5394 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
|
5395 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5396 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
|
5397 "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5398 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
|
5399 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5400 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
|
5401 "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5402 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
|
5403 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5404 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
|
5405 "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5406 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
|
5407 "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5408 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
|
5409 "%"), |
|
35004
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5410 BINSLOTNOTINFIX("__divmod__", nb_divmod, slot_nb_divmod, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5411 "divmod(x, y)"), |
|
35004
8880d91cdb09
fix object.__divmod__.__doc__
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34958
diff
changeset
|
5412 RBINSLOTNOTINFIX("__rdivmod__", nb_divmod, slot_nb_divmod, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5413 "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
|
5414 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
|
5415 "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
|
5416 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
|
5417 "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
|
5418 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
|
5419 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
|
5420 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
|
5421 "abs(x)"), |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39703
diff
changeset
|
5422 UNSLOT("__bool__", nb_bool, slot_nb_bool, wrap_inquirypred, |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5423 "x != 0"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5424 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
|
5425 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
|
5426 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
|
5427 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
|
5428 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
|
5429 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
|
5430 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
|
5431 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
|
5432 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
|
5433 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
|
5434 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
|
5435 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
|
5436 "int(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5437 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
|
5438 "float(x)"), |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
5439 NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc, |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36866
diff
changeset
|
5440 "x[y:z] <==> x[y.__index__():z.__index__()]"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5441 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
|
5442 wrap_binaryfunc, "+"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5443 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
|
5444 wrap_binaryfunc, "-"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5445 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
|
5446 wrap_binaryfunc, "*"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5447 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
|
5448 wrap_binaryfunc, "%"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5449 IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power, |
|
25794
001b789f1f84
For some reason (probably cut and paste), __ipow__ for new-style
Guido van Rossum <guido@python.org>
parents:
25793
diff
changeset
|
5450 wrap_binaryfunc, "**"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5451 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
|
5452 wrap_binaryfunc, "<<"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5453 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
|
5454 wrap_binaryfunc, ">>"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5455 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
|
5456 wrap_binaryfunc, "&"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5457 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
|
5458 wrap_binaryfunc, "^"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5459 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
|
5460 wrap_binaryfunc, "|"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5461 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
|
5462 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
|
5463 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
|
5464 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
|
5465 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
|
5466 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
|
5467 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
|
5468 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
|
5469 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5470 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
|
5471 "x.__str__() <==> str(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5472 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
|
5473 "x.__repr__() <==> repr(x)"), |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5474 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
|
5475 "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
|
5476 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
|
5477 "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
|
5478 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
|
5479 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
|
5480 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
|
5481 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
|
5482 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
|
5483 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
|
5484 "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
|
5485 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
|
5486 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
|
5487 "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
|
5488 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
|
5489 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
|
5490 "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
|
5491 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
|
5492 "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
|
5493 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
|
5494 "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
|
5495 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
|
5496 "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
|
5497 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
|
5498 "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
|
5499 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
|
5500 "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
|
5501 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
|
5502 "x.__iter__() <==> iter(x)"), |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41324
diff
changeset
|
5503 TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next, |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41324
diff
changeset
|
5504 "x.__next__() <==> next(x)"), |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5505 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
|
5506 "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
|
5507 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
|
5508 "descr.__set__(obj, value)"), |
|
24460
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
5509 TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set, |
|
2d77be41ee5f
SF patch 588728 (Nathan Srebro).
Guido van Rossum <guido@python.org>
parents:
24427
diff
changeset
|
5510 wrap_descr_delete, "descr.__delete__(obj)"), |
|
20599
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
5511 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
|
5512 "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
|
5513 "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
|
5514 PyWrapperFlag_KEYWORDS), |
|
ff57a1a370b3
Methods of built-in types now properly check for keyword arguments
Guido van Rossum <guido@python.org>
parents:
20595
diff
changeset
|
5515 TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""), |
|
24678
71dca7c76fa2
A modest speedup of object deallocation. call_finalizer() did rather
Guido van Rossum <guido@python.org>
parents:
24653
diff
changeset
|
5516 TPSLOT("__del__", tp_del, slot_tp_del, NULL, ""), |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5517 {NULL} |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5518 }; |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5519 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5520 /* Given a type pointer and an offset gotten from a slotdef entry, return a |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5521 pointer to the actual slot. This is not quite the same as simply adding |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5522 the offset to the type pointer, since it takes care to indirect through the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5523 proper indirection pointer (as_buffer, etc.); it returns NULL if the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5524 indirection pointer is NULL. */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5525 static void ** |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5526 slotptr(PyTypeObject *type, int ioffset) |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5527 { |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5528 char *ptr; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5529 long offset = ioffset; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5530 |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5531 /* Note: this depends on the order of the members of PyHeapTypeObject! */ |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5532 assert(offset >= 0); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5533 assert((size_t)offset < offsetof(PyHeapTypeObject, as_buffer)); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5534 if ((size_t)offset >= offsetof(PyHeapTypeObject, as_sequence)) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5535 ptr = (char *)type->tp_as_sequence; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5536 offset -= offsetof(PyHeapTypeObject, as_sequence); |
|
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5537 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5538 else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_mapping)) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5539 ptr = (char *)type->tp_as_mapping; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5540 offset -= offsetof(PyHeapTypeObject, as_mapping); |
|
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5541 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5542 else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_number)) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5543 ptr = (char *)type->tp_as_number; |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5544 offset -= offsetof(PyHeapTypeObject, as_number); |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5545 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5546 else { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
5547 ptr = (char *)type; |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5548 } |
|
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5549 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
|
5550 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
|
5551 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
|
5552 } |
| 19036 | 5553 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5554 /* Length of array of slotdef pointers used to store slots with the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5555 same __name__. There should be at most MAX_EQUIV-1 slotdef entries with |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5556 the same __name__, for any __name__. Since that's a static property, it is |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5557 appropriate to declare fixed-size arrays for this. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5558 #define MAX_EQUIV 10 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5559 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5560 /* Return a slot pointer for a given name, but ONLY if the attribute has |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5561 exactly one slot function. The name must be an interned string. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5562 static void ** |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5563 resolve_slotdups(PyTypeObject *type, PyObject *name) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5564 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5565 /* XXX Maybe this could be optimized more -- but is it worth it? */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5566 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5567 /* pname and ptrs act as a little cache */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5568 static PyObject *pname; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5569 static slotdef *ptrs[MAX_EQUIV]; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5570 slotdef *p, **pp; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5571 void **res, **ptr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5572 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5573 if (pname != name) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5574 /* Collect all slotdefs that match name into ptrs. */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5575 pname = name; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5576 pp = ptrs; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5577 for (p = slotdefs; p->name_strobj; p++) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5578 if (p->name_strobj == name) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5579 *pp++ = p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5580 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5581 *pp = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5582 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5583 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5584 /* Look in all matching slots of the type; if exactly one of these has |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5585 a filled-in slot, return its value. Otherwise return NULL. */ |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5586 res = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5587 for (pp = ptrs; *pp; pp++) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5588 ptr = slotptr(type, (*pp)->offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5589 if (ptr == NULL || *ptr == NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5590 continue; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5591 if (res != NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5592 return NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5593 res = ptr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5594 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5595 return res; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5596 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5597 |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5598 /* Common code for update_slots_callback() and fixup_slot_dispatchers(). This |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5599 does some incredibly complex thinking and then sticks something into the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5600 slot. (It sees if the adjacent slotdefs for the same slot have conflicting |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5601 interests, and then stores a generic wrapper or a specific function into |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5602 the slot.) Return a pointer to the next slotdef with a different offset, |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5603 because that's convenient for fixup_slot_dispatchers(). */ |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5604 static slotdef * |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5605 update_one_slot(PyTypeObject *type, slotdef *p) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5606 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5607 PyObject *descr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5608 PyWrapperDescrObject *d; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5609 void *generic = NULL, *specific = NULL; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5610 int use_generic = 0; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5611 int offset = p->offset; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5612 void **ptr = slotptr(type, offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5613 |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5614 if (ptr == NULL) { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5615 do { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5616 ++p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5617 } while (p->offset == offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5618 return p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5619 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5620 do { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5621 descr = _PyType_Lookup(type, p->name_strobj); |
|
50755
c99ce0164699
Merged revisions 68560 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50717
diff
changeset
|
5622 if (descr == NULL) { |
|
c99ce0164699
Merged revisions 68560 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50717
diff
changeset
|
5623 if (ptr == (void**)&type->tp_iternext) { |
|
c99ce0164699
Merged revisions 68560 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50717
diff
changeset
|
5624 specific = _PyObject_NextNotImplemented; |
|
c99ce0164699
Merged revisions 68560 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50717
diff
changeset
|
5625 } |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5626 continue; |
|
50755
c99ce0164699
Merged revisions 68560 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
50717
diff
changeset
|
5627 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5628 if (Py_TYPE(descr) == &PyWrapperDescr_Type) { |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5629 void **tptr = resolve_slotdups(type, p->name_strobj); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5630 if (tptr == NULL || tptr == ptr) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5631 generic = p->function; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5632 d = (PyWrapperDescrObject *)descr; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5633 if (d->d_base->wrapper == p->wrapper && |
|
55399
b7aabba84ee1
Issue #6151: Make PyDescr_COMMON conform to standard C.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55131
diff
changeset
|
5634 PyType_IsSubtype(type, PyDescr_TYPE(d))) |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5635 { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5636 if (specific == NULL || |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5637 specific == d->d_wrapped) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5638 specific = d->d_wrapped; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5639 else |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5640 use_generic = 1; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5641 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5642 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5643 else if (Py_TYPE(descr) == &PyCFunction_Type && |
|
24685
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5644 PyCFunction_GET_FUNCTION(descr) == |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5645 (PyCFunction)tp_new_wrapper && |
|
50884
e14ec6d18ab8
Merged revisions 68568,68665 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50821
diff
changeset
|
5646 ptr == (void**)&type->tp_new) |
|
24685
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5647 { |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5648 /* The __new__ wrapper is not a wrapper descriptor, |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5649 so must be special-cased differently. |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5650 If we don't do this, creating an instance will |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5651 always use slot_tp_new which will look up |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5652 __new__ in the MRO which will call tp_new_wrapper |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5653 which will look through the base classes looking |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5654 for a static base and call its tp_new (usually |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5655 PyType_GenericNew), after performing various |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5656 sanity checks and constructing a new argument |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5657 list. Cut all that nonsense short -- this speeds |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5658 up instance creation tremendously. */ |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
28737
diff
changeset
|
5659 specific = (void *)type->tp_new; |
|
24685
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5660 /* XXX I'm not 100% sure that there isn't a hole |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5661 in this reasoning that requires additional |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5662 sanity checks. I'll buy the first person to |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5663 point out a bug in this reasoning a beer. */ |
|
36493a7c6253
Major speedup for new-style class creation. Turns out there was some
Guido van Rossum <guido@python.org>
parents:
24680
diff
changeset
|
5664 } |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5665 else if (descr == Py_None && |
|
50884
e14ec6d18ab8
Merged revisions 68568,68665 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50821
diff
changeset
|
5666 ptr == (void**)&type->tp_hash) { |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5667 /* We specifically allow __hash__ to be set to None |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5668 to prevent inheritance of the default |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5669 implementation from object.__hash__ */ |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5670 specific = PyObject_HashNotImplemented; |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5671 } |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5672 else { |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5673 use_generic = 1; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5674 generic = p->function; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5675 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5676 } while ((++p)->offset == offset); |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5677 if (specific && !use_generic) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5678 *ptr = specific; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5679 else |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5680 *ptr = generic; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5681 return p; |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5682 } |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5683 |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5684 /* In the type, update the slots whose slotdefs are gathered in the pp array. |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5685 This is a callback for update_subclasses(). */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5686 static int |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5687 update_slots_callback(PyTypeObject *type, void *data) |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5688 { |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5689 slotdef **pp = (slotdef **)data; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5690 |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5691 for (; *pp; pp++) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5692 update_one_slot(type, *pp); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5693 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
|
5694 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5695 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5696 /* Comparison function for qsort() to compare slotdefs by their offset, and |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5697 for equal offset by their address (to force a stable sort). */ |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5698 static int |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5699 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
|
5700 { |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5701 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
|
5702 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
|
5703 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
|
5704 return c; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5705 else |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5706 /* Cannot use a-b, as this gives off_t, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5707 which may lose precision when converted to int. */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5708 return (a > b) ? 1 : (a < b) ? -1 : 0; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5709 } |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5710 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5711 /* Initialize the slotdefs table by adding interned string objects for the |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5712 names and sorting the entries. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5713 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
|
5714 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
|
5715 { |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5716 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
|
5717 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
|
5718 |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5719 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
|
5720 return; |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5721 for (p = slotdefs; p->name; p++) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5722 p->name_strobj = PyUnicode_InternFromString(p->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
|
5723 if (!p->name_strobj) |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5724 Py_FatalError("Out of memory interning slotdef names"); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5725 } |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
5726 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
|
5727 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
|
5728 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
|
5729 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5730 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5731 /* Update the slots after assignment to a class (type) attribute. */ |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5732 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
|
5733 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
|
5734 { |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5735 slotdef *ptrs[MAX_EQUIV]; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5736 slotdef *p; |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5737 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
|
5738 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
|
5739 |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5740 /* Clear the VALID_VERSION flag of 'type' and all its |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5741 subclasses. This could possibly be unified with the |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5742 update_subclasses() recursion below, but carefully: |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5743 they each have their own conditions on which to stop |
|
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5744 recursing into subclasses. */ |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47466
diff
changeset
|
5745 PyType_Modified(type); |
|
44654
5a71dcc71eff
Merged revisions 59921-59932 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44626
diff
changeset
|
5746 |
|
20457
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
5747 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
|
5748 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
|
5749 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
|
5750 /* 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
|
5751 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
|
5752 *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
|
5753 } |
|
4f71dcfd0a93
Refactored the update_slot() code a bit to be hopefully slightly more
Guido van Rossum <guido@python.org>
parents:
20445
diff
changeset
|
5754 *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
|
5755 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
|
5756 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
|
5757 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
|
5758 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
|
5759 --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
|
5760 *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
|
5761 } |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5762 if (ptrs[0] == NULL) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5763 return 0; /* Not an attribute that affects any slots */ |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5764 return update_subclasses(type, name, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5765 update_slots_callback, (void *)ptrs); |
|
20382
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5766 } |
|
be08734b0afd
Another step in the right direction: when a new class's attribute
Guido van Rossum <guido@python.org>
parents:
20345
diff
changeset
|
5767 |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5768 /* Store the proper functions in the slot dispatches at class (type) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5769 definition time, based upon which operations the class overrides in its |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5770 dict. */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5771 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
|
5772 fixup_slot_dispatchers(PyTypeObject *type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5773 { |
|
20343
7bd12270dc3e
Halfway checkin. This is still messy, but it's beginning to address
Guido van Rossum <guido@python.org>
parents:
20328
diff
changeset
|
5774 slotdef *p; |
|
20423
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5775 |
|
4698a3ec5fa8
Redid the slot computation. The initial slot assignments are now done
Guido van Rossum <guido@python.org>
parents:
20386
diff
changeset
|
5776 init_slotdefs(); |
|
22834
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5777 for (p = slotdefs; p->name; ) |
|
0908729e94e0
A much revised version of SF patch 514662, by Naofumi Honda. This
Guido van Rossum <guido@python.org>
parents:
22804
diff
changeset
|
5778 p = update_one_slot(type, p); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18068
diff
changeset
|
5779 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5780 |
| 26421 | 5781 static void |
| 5782 update_all_slots(PyTypeObject* type) | |
| 5783 { | |
| 5784 slotdef *p; | |
| 5785 | |
| 5786 init_slotdefs(); | |
| 5787 for (p = slotdefs; p->name; p++) { | |
| 5788 /* update_slot returns int but can't actually fail */ | |
| 5789 update_slot(type, p->name_strobj); | |
| 5790 } | |
| 5791 } | |
| 5792 | |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5793 /* recurse_down_subclasses() and update_subclasses() are mutually |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5794 recursive functions to call a callback for all subclasses, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5795 but refraining from recursing into subclasses that define 'name'. */ |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5796 |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5797 static int |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5798 update_subclasses(PyTypeObject *type, PyObject *name, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5799 update_callback callback, void *data) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5800 { |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5801 if (callback(type, data) < 0) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5802 return -1; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5803 return recurse_down_subclasses(type, name, callback, data); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5804 } |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5805 |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5806 static int |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5807 recurse_down_subclasses(PyTypeObject *type, PyObject *name, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5808 update_callback callback, void *data) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5809 { |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5810 PyTypeObject *subclass; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5811 PyObject *ref, *subclasses, *dict; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5812 Py_ssize_t i, n; |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5813 |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5814 subclasses = type->tp_subclasses; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5815 if (subclasses == NULL) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5816 return 0; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5817 assert(PyList_Check(subclasses)); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5818 n = PyList_GET_SIZE(subclasses); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5819 for (i = 0; i < n; i++) { |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5820 ref = PyList_GET_ITEM(subclasses, i); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5821 assert(PyWeakref_CheckRef(ref)); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5822 subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5823 assert(subclass != NULL); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5824 if ((PyObject *)subclass == Py_None) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5825 continue; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5826 assert(PyType_Check(subclass)); |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5827 /* Avoid recursing down into unaffected classes */ |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5828 dict = subclass->tp_dict; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5829 if (dict != NULL && PyDict_Check(dict) && |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5830 PyDict_GetItem(dict, name) != NULL) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5831 continue; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5832 if (update_subclasses(subclass, name, callback, data) < 0) |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5833 return -1; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5834 } |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5835 return 0; |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5836 } |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5837 |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5838 /* 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
|
5839 dictionary with method descriptors for function slots. For each |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5840 function slot (like tp_repr) that's defined in the type, one or more |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5841 corresponding descriptors are added in the type's tp_dict dictionary |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5842 under the appropriate name (like __repr__). Some function slots |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5843 cause more than one descriptor to be added (for example, the nb_add |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5844 slot adds both __add__ and __radd__ descriptors) and some function |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5845 slots compete for the same descriptor (for example both sq_item and |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5846 mp_subscript generate a __getitem__ descriptor). |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5847 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
5848 In the latter case, the first slotdef entry encoutered wins. Since |
|
28390
33319458fe99
slot_sq_contains(): This leaked a reference to the result of calling
Tim Peters <tim.peters@gmail.com>
parents:
28389
diff
changeset
|
5849 slotdef entries are sorted by the offset of the slot in the |
|
28219
7c8e8807aed2
- The extended type structure used for heap types (new-style
Guido van Rossum <guido@python.org>
parents:
28016
diff
changeset
|
5850 PyHeapTypeObject, this gives us some control over disambiguating |
|
28403
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5851 between competing slots: the members of PyHeapTypeObject are listed |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5852 from most general to least general, so the most general slot is |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5853 preferred. In particular, because as_mapping comes before as_sequence, |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5854 for a type that defines both mp_subscript and sq_item, mp_subscript |
|
63ed85290413
Refactoring: rename update_these_slots() into update_subclasses() and
Guido van Rossum <guido@python.org>
parents:
28396
diff
changeset
|
5855 wins. |
|
23830
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5856 |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5857 This only adds new descriptors and doesn't overwrite entries in |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5858 tp_dict that were previously defined. The descriptors contain a |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5859 reference to the C function they must call, so that it's safe if they |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5860 are copied into a subtype's __dict__ and the subtype has a different |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5861 C function in its slot -- calling the method defined by the |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5862 descriptor will call the C function that was used to create it, |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5863 rather than the C function present in the slot when it is called. |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5864 (This is important because a subtype may have a C function in the |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5865 slot that calls the method from the dictionary, and we want to avoid |
|
ade1d56109a8
Hopefully this addresses the remaining issues of SF bugs 459235 and
Guido van Rossum <guido@python.org>
parents:
23756
diff
changeset
|
5866 infinite recursion here.) */ |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5867 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5868 static int |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5869 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
|
5870 { |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5871 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
|
5872 slotdef *p; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5873 PyObject *descr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5874 void **ptr; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5875 |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5876 init_slotdefs(); |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5877 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
|
5878 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
|
5879 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5880 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
|
5881 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
|
5882 continue; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5883 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
|
5884 continue; |
|
48475
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5885 if (*ptr == PyObject_HashNotImplemented) { |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5886 /* Classes may prevent the inheritance of the tp_hash |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5887 slot by storing PyObject_HashNotImplemented in it. Make it |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5888 visible as a None value for the __hash__ attribute. */ |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5889 if (PyDict_SetItem(dict, p->name_strobj, Py_None) < 0) |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5890 return -1; |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5891 } |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5892 else { |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5893 descr = PyDescr_NewWrapper(type, p, *ptr); |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5894 if (descr == NULL) |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5895 return -1; |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5896 if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5897 return -1; |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5898 Py_DECREF(descr); |
|
f4e7ef4329a9
Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents:
47557
diff
changeset
|
5899 } |
|
20586
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5900 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5901 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
|
5902 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
|
5903 return -1; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5904 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5905 return 0; |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5906 } |
|
9bd603d434f5
Big internal change that should have no external effects: unify the
Guido van Rossum <guido@python.org>
parents:
20516
diff
changeset
|
5907 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5908 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5909 /* Cooperative 'super' */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5910 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5911 typedef struct { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5912 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
|
5913 PyTypeObject *type; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5914 PyObject *obj; |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5915 PyTypeObject *obj_type; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5916 } superobject; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5917 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
5918 static PyMemberDef super_members[] = { |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
5919 {"__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
|
5920 "the class invoking super()"}, |
|
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
5921 {"__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
|
5922 "the instance invoking super(); may be None"}, |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5923 {"__self_class__", T_OBJECT, offsetof(superobject, obj_type), READONLY, |
|
30722
651fc8d98d99
Fix a bunch of typos in documentation, docstrings and comments.
Walter Dörwald <walter@livinglogic.de>
parents:
30683
diff
changeset
|
5924 "the type of 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
|
5925 {0} |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5926 }; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5927 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5928 static void |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5929 super_dealloc(PyObject *self) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5930 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5931 superobject *su = (superobject *)self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5932 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
5933 _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
|
5934 Py_XDECREF(su->obj); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5935 Py_XDECREF(su->type); |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5936 Py_XDECREF(su->obj_type); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
5937 Py_TYPE(self)->tp_free(self); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5938 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5939 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5940 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
|
5941 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
|
5942 { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5943 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
|
5944 |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5945 if (su->obj_type) |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
5946 return PyUnicode_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
|
5947 "<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
|
5948 su->type ? su->type->tp_name : "NULL", |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5949 su->obj_type->tp_name); |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5950 else |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41716
diff
changeset
|
5951 return PyUnicode_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
|
5952 "<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
|
5953 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
|
5954 } |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5955 |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5956 static PyObject * |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5957 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
|
5958 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5959 superobject *su = (superobject *)self; |
|
28638
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5960 int skip = su->obj_type == NULL; |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5961 |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5962 if (!skip) { |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5963 /* We want __class__ to return the class of the super object |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5964 (i.e. super, or a subclass), not the class of su->obj. */ |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5965 skip = (PyUnicode_Check(name) && |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5966 PyUnicode_GET_SIZE(name) == 9 && |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
5967 PyUnicode_CompareWithASCIIString(name, "__class__") == 0); |
|
28638
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5968 } |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5969 |
|
9be4103807f5
- super() no longer ignores data descriptors, except __class__. See
Guido van Rossum <guido@python.org>
parents:
28625
diff
changeset
|
5970 if (!skip) { |
|
20978
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5971 PyObject *mro, *res, *tmp, *dict; |
|
22770
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5972 PyTypeObject *starttype; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5973 descrgetfunc f; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36169
diff
changeset
|
5974 Py_ssize_t i, n; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5975 |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
5976 starttype = su->obj_type; |
|
22770
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5977 mro = starttype->tp_mro; |
|
314e1416aa5d
SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
Guido van Rossum <guido@python.org>
parents:
22713
diff
changeset
|
5978 |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5979 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
|
5980 n = 0; |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5981 else { |
|
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
5982 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
|
5983 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
|
5984 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5985 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
|
5986 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
|
5987 break; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5988 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5989 i++; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5990 res = NULL; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5991 for (; i < n; i++) { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5992 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
|
5993 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
|
5994 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
|
5995 else |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5996 continue; |
|
44f3f5a5bfe2
Changing diapers reminded Guido that he wanted to allow for some measure
Tim Peters <tim.peters@gmail.com>
parents:
20754
diff
changeset
|
5997 res = PyDict_GetItem(dict, name); |
|
28640
4824aab12549
Sigh. The crucial change was still missing from the previous
Guido van Rossum <guido@python.org>
parents:
28638
diff
changeset
|
5998 if (res != NULL) { |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
5999 Py_INCREF(res); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6000 f = Py_TYPE(res)->tp_descr_get; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6001 if (f != NULL) { |
|
31800
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6002 tmp = f(res, |
|
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6003 /* Only pass 'obj' param if |
|
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6004 this is instance-mode super |
|
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6005 (See SF ID #743627) |
|
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6006 */ |
|
31813
8184c677713f
Get rid of gcc warning.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31800
diff
changeset
|
6007 (su->obj == (PyObject *) |
|
8184c677713f
Get rid of gcc warning.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31800
diff
changeset
|
6008 su->obj_type |
|
31800
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6009 ? (PyObject *)NULL |
|
37dc8c80ca7e
Ensure super() lookup of descriptor from classmethod works (SF #743627)
Phillip J. Eby <pje@telecommunity.com>
parents:
31477
diff
changeset
|
6010 : su->obj), |
|
22774
02fddf7c25c2
Fold some long lines. Delete blank initial line.
Guido van Rossum <guido@python.org>
parents:
22770
diff
changeset
|
6011 (PyObject *)starttype); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6012 Py_DECREF(res); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6013 res = tmp; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6014 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6015 return res; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6016 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6017 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6018 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6019 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
|
6020 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6021 |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6022 static PyTypeObject * |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6023 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
|
6024 { |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6025 /* Check that a super() call makes sense. Return a type object. |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6026 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6027 obj can be a new-style class, or an instance of one: |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6028 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6029 - If it is a class, it must be a subclass of 'type'. This case is |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6030 used for class methods; the return value is obj. |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6031 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6032 - If it is an instance, it must be an instance of 'type'. This is |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6033 the normal case; the return value is obj.__class__. |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6034 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6035 But... when obj is an instance, we want to allow for the case where |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6036 Py_TYPE(obj) is not a subclass of type, but obj.__class__ is! |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6037 This will allow using super() with a proxy for obj. |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6038 */ |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6039 |
|
27942
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6040 /* Check for first bullet above (special case) */ |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6041 if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, type)) { |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6042 Py_INCREF(obj); |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6043 return (PyTypeObject *)obj; |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6044 } |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6045 |
|
9255fbde43f3
The recent changes to super(), in particular supercheck(), broke when
Guido van Rossum <guido@python.org>
parents:
27866
diff
changeset
|
6046 /* Normal case */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6047 if (PyType_IsSubtype(Py_TYPE(obj), type)) { |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6048 Py_INCREF(Py_TYPE(obj)); |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6049 return Py_TYPE(obj); |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6050 } |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6051 else { |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6052 /* Try the slow way */ |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6053 static PyObject *class_str = NULL; |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6054 PyObject *class_attr; |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6055 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6056 if (class_str == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41824
diff
changeset
|
6057 class_str = PyUnicode_FromString("__class__"); |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6058 if (class_str == NULL) |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6059 return NULL; |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6060 } |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6061 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6062 class_attr = PyObject_GetAttr(obj, class_str); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6063 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6064 if (class_attr != NULL && |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6065 PyType_Check(class_attr) && |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6066 (PyTypeObject *)class_attr != Py_TYPE(obj)) |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6067 { |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6068 int ok = PyType_IsSubtype( |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6069 (PyTypeObject *)class_attr, type); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6070 if (ok) |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6071 return (PyTypeObject *)class_attr; |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6072 } |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6073 |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6074 if (class_attr == NULL) |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6075 PyErr_Clear(); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6076 else |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6077 Py_DECREF(class_attr); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6078 } |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6079 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6080 PyErr_SetString(PyExc_TypeError, |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6081 "super(type, obj): " |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6082 "obj must be an instance or subtype of type"); |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6083 return NULL; |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6084 } |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6085 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6086 static PyObject * |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6087 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
|
6088 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6089 superobject *su = (superobject *)self; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6090 superobject *newobj; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6091 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6092 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
|
6093 /* 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
|
6094 Py_INCREF(self); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6095 return self; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6096 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6097 if (Py_TYPE(su) != &PySuper_Type) |
|
34958
c91e5e31c5ff
Fixed a quite misleading comment: a "not" should not have been there.
Armin Rigo <arigo@tunes.org>
parents:
34668
diff
changeset
|
6098 /* If su is an instance of a (strict) subclass of super, |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6099 call its type */ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6100 return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su), |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6101 su->type, obj, NULL); |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6102 else { |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6103 /* Inline the common case */ |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6104 PyTypeObject *obj_type = supercheck(su->type, obj); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6105 if (obj_type == NULL) |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6106 return NULL; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6107 newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type, |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6108 NULL, NULL); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6109 if (newobj == NULL) |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6110 return NULL; |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6111 Py_INCREF(su->type); |
|
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6112 Py_INCREF(obj); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6113 newobj->type = su->type; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6114 newobj->obj = obj; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6115 newobj->obj_type = obj_type; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6116 return (PyObject *)newobj; |
|
21151
918b57354d87
Address SF patch #480716 as well as related issues.
Guido van Rossum <guido@python.org>
parents:
21142
diff
changeset
|
6117 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6118 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6119 |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6120 static int |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6121 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
|
6122 { |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6123 superobject *su = (superobject *)self; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6124 PyTypeObject *type = NULL; |
|
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
|
6125 PyObject *obj = NULL; |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6126 PyTypeObject *obj_type = NULL; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6127 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
6128 if (!_PyArg_NoKeywords("super", kwds)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40401
diff
changeset
|
6129 return -1; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6130 if (!PyArg_ParseTuple(args, "|O!O:super", &PyType_Type, &type, &obj)) |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6131 return -1; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6132 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6133 if (type == NULL) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6134 /* Call super(), without args -- fill in from __class__ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6135 and first local variable on the stack. */ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6136 PyFrameObject *f = PyThreadState_GET()->frame; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6137 PyCodeObject *co = f->f_code; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6138 int i, n; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6139 if (co == NULL) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6140 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6141 "super(): no code object"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6142 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6143 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6144 if (co->co_argcount == 0) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6145 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6146 "super(): no arguments"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6147 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6148 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6149 obj = f->f_localsplus[0]; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6150 if (obj == NULL) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6151 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6152 "super(): arg[0] deleted"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6153 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6154 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6155 if (co->co_freevars == NULL) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6156 n = 0; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6157 else { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6158 assert(PyTuple_Check(co->co_freevars)); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6159 n = PyTuple_GET_SIZE(co->co_freevars); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6160 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6161 for (i = 0; i < n; i++) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6162 PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6163 assert(PyUnicode_Check(name)); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6164 if (!PyUnicode_CompareWithASCIIString(name, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6165 "__class__")) { |
|
49775
2ca964d724d5
Fix for bug 4360 "SystemError when method has both super() & closure". Patch
Barry Warsaw <barry@python.org>
parents:
49742
diff
changeset
|
6166 Py_ssize_t index = co->co_nlocals + |
|
2ca964d724d5
Fix for bug 4360 "SystemError when method has both super() & closure". Patch
Barry Warsaw <barry@python.org>
parents:
49742
diff
changeset
|
6167 PyTuple_GET_SIZE(co->co_cellvars) + i; |
|
2ca964d724d5
Fix for bug 4360 "SystemError when method has both super() & closure". Patch
Barry Warsaw <barry@python.org>
parents:
49742
diff
changeset
|
6168 PyObject *cell = f->f_localsplus[index]; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6169 if (cell == NULL || !PyCell_Check(cell)) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6170 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6171 "super(): bad __class__ cell"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6172 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6173 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6174 type = (PyTypeObject *) PyCell_GET(cell); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6175 if (type == NULL) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6176 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6177 "super(): empty __class__ cell"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6178 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6179 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6180 if (!PyType_Check(type)) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6181 PyErr_Format(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6182 "super(): __class__ is not a type (%s)", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
6183 Py_TYPE(type)->tp_name); |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6184 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6185 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6186 break; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6187 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6188 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6189 if (type == NULL) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6190 PyErr_SetString(PyExc_SystemError, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6191 "super(): __class__ cell not found"); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6192 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6193 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6194 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6195 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6196 if (obj == Py_None) |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6197 obj = NULL; |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6198 if (obj != NULL) { |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6199 obj_type = supercheck(type, obj); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6200 if (obj_type == NULL) |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6201 return -1; |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6202 Py_INCREF(obj); |
|
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6203 } |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6204 Py_INCREF(type); |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6205 su->type = type; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6206 su->obj = obj; |
|
27831
6b5696541ba4
Implement another useful feature for proxies: in super(X, x), x may
Guido van Rossum <guido@python.org>
parents:
27821
diff
changeset
|
6207 su->obj_type = obj_type; |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6208 return 0; |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6209 } |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6210 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23830
diff
changeset
|
6211 PyDoc_STRVAR(super_doc, |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6212 "super() -> same as super(__class__, <first argument>)\n" |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6213 "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
|
6214 "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
|
6215 "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
|
6216 "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
|
6217 "class C(B):\n" |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6218 " def meth(self, arg):\n" |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6219 " super().meth(arg)\n" |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6220 "This works for class methods too:\n" |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6221 "class C(B):\n" |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6222 " @classmethod\n" |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6223 " def cmeth(cls, arg):\n" |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42081
diff
changeset
|
6224 " super().cmeth(arg)\n"); |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6225 |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
6226 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
|
6227 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
|
6228 { |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
6229 superobject *su = (superobject *)self; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6230 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6231 Py_VISIT(su->obj); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6232 Py_VISIT(su->type); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37191
diff
changeset
|
6233 Py_VISIT(su->obj_type); |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
6234 |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
6235 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
|
6236 } |
|
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20204
diff
changeset
|
6237 |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6238 PyTypeObject PySuper_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42203
diff
changeset
|
6239 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6240 "super", /* tp_name */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6241 sizeof(superobject), /* tp_basicsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6242 0, /* tp_itemsize */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6243 /* methods */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6244 super_dealloc, /* tp_dealloc */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6245 0, /* tp_print */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6246 0, /* tp_getattr */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6247 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51251
diff
changeset
|
6248 0, /* tp_reserved */ |
|
19630
ae056f114974
Give 'super' a decent repr(), and readonly attributes to access the
Guido van Rossum <guido@python.org>
parents:
19618
diff
changeset
|
6249 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
|
6250 0, /* tp_as_number */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6251 0, /* tp_as_sequence */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6252 0, /* tp_as_mapping */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6253 0, /* tp_hash */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6254 0, /* tp_call */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6255 0, /* tp_str */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6256 super_getattro, /* tp_getattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6257 0, /* tp_setattro */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6258 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
|
6259 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
|
6260 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6261 super_doc, /* tp_doc */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6262 super_traverse, /* tp_traverse */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6263 0, /* tp_clear */ |
|
19469
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6264 0, /* tp_richcompare */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6265 0, /* tp_weaklistoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6266 0, /* tp_iter */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6267 0, /* tp_iternext */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6268 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
|
6269 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
|
6270 0, /* tp_getset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6271 0, /* tp_base */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6272 0, /* tp_dict */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6273 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
|
6274 0, /* tp_descr_set */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6275 0, /* tp_dictoffset */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6276 super_init, /* tp_init */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6277 PyType_GenericAlloc, /* tp_alloc */ |
|
b3c92f013869
Add 'super', another new object type with magical properties.
Guido van Rossum <guido@python.org>
parents:
19464
diff
changeset
|
6278 PyType_GenericNew, /* tp_new */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
6279 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
|
6280 }; |
