Skip to content

Commit 3cf5b1e

Browse files
committed
Get rid of most of the flags (in tp_flags) that keep track of various
variations of the type struct and its attachments. In Py3k, all type structs have to have all fields -- no binary backwards compatibility. Had to change the complex object to a new-style number!
1 parent 73e5a5b commit 3cf5b1e

36 files changed

+170
-357
lines changed

Include/abstract.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
534534
is an iterator, this returns itself. */
535535

536536
#define PyIter_Check(obj) \
537-
(PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
538-
(obj)->ob_type->tp_iternext != NULL)
537+
((obj)->ob_type->tp_iternext != NULL)
539538

540539
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
541540
/* Takes an iterator object and calls its tp_iternext slot,

Include/object.h

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ typedef int (*visitproc)(PyObject *, void *);
147147
typedef int (*traverseproc)(PyObject *, visitproc, void *);
148148

149149
typedef struct {
150-
/* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
151-
arguments are guaranteed to be of the object's type (modulo
152-
coercion hacks -- i.e. if the type's coercion function
153-
returns other types, then these are allowed as well). Numbers that
154-
have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
150+
/* Number implementations should check *both*
155151
arguments for proper type and implement the necessary conversions
156152
in the slot functions themselves. */
157153

@@ -444,42 +440,16 @@ Arbitration of the flag bit positions will need to be coordinated among
444440
all extension writers who publically release their extensions (this will
445441
be fewer than you might expect!)..
446442
447-
Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
443+
Most flags were removed as of Python 3.0 to make room for new flags. (Some
444+
flags are not for backwards compatibility but to indicate the presence of an
445+
optional feature; these flags remain of course.)
448446
449447
Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
450448
451449
Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
452450
given type object has a specified feature.
453451
*/
454452

455-
/* PyBufferProcs contains bf_getcharbuffer */
456-
#define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
457-
458-
/* PySequenceMethods contains sq_contains */
459-
#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
460-
461-
/* This is here for backwards compatibility. Extensions that use the old GC
462-
* API will still compile but the objects will not be tracked by the GC. */
463-
#define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */
464-
465-
/* PySequenceMethods and PyNumberMethods contain in-place operators */
466-
#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
467-
468-
/* PyNumberMethods do their own coercion */
469-
#define Py_TPFLAGS_CHECKTYPES (1L<<4)
470-
471-
/* tp_richcompare is defined */
472-
#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
473-
474-
/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
475-
#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
476-
477-
/* tp_iter is defined */
478-
#define Py_TPFLAGS_HAVE_ITER (1L<<7)
479-
480-
/* New members introduced by Python 2.2 exist */
481-
#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
482-
483453
/* Set if the type object is dynamically allocated */
484454
#define Py_TPFLAGS_HEAPTYPE (1L<<9)
485455

@@ -502,19 +472,8 @@ given type object has a specified feature.
502472
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
503473
#endif
504474

505-
/* Objects support nb_index in PyNumberMethods */
506-
#define Py_TPFLAGS_HAVE_INDEX (1L<<17)
507-
508475
#define Py_TPFLAGS_DEFAULT ( \
509-
Py_TPFLAGS_HAVE_GETCHARBUFFER | \
510-
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
511-
Py_TPFLAGS_HAVE_INPLACEOPS | \
512-
Py_TPFLAGS_HAVE_RICHCOMPARE | \
513-
Py_TPFLAGS_HAVE_WEAKREFS | \
514-
Py_TPFLAGS_HAVE_ITER | \
515-
Py_TPFLAGS_HAVE_CLASS | \
516476
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
517-
Py_TPFLAGS_HAVE_INDEX | \
518477
0)
519478

520479
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)

Include/objimpl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
323323

324324

325325
/* Test if a type supports weak references */
326-
#define PyType_SUPPORTS_WEAKREFS(t) \
327-
(PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
328-
&& ((t)->tp_weaklistoffset > 0))
326+
#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
329327

330328
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
331329
((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))

Lib/plat-mac/aetools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self, signature=None, start=0, timeout=0):
169169
signature = self._signature
170170
if type(signature) == AEDescType:
171171
self.target = signature
172-
elif type(signature) == InstanceType and hasattr(signature, '__aepack__'):
172+
elif hasattr(signature, '__aepack__'):
173173
self.target = signature.__aepack__()
174174
elif type(signature) == StringType and len(signature) == 4:
175175
self.target = AE.AECreateDesc(AppleEvents.typeApplSignature, signature)

Lib/test/test_class.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
]
5050

5151
# These need to return something other than None
52-
# "coerce",
5352
# "hash",
5453
# "str",
5554
# "repr",
@@ -65,10 +64,6 @@
6564
# "delattr",
6665

6766
class AllTests:
68-
def __coerce__(self, *args):
69-
print "__coerce__:", args
70-
return (self,) + args
71-
7267
def __hash__(self, *args):
7368
print "__hash__:", args
7469
return hash(id(self))

Lib/test/test_weakref.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ def test_weak_values(self):
713713
#
714714
dict, objects = self.make_weak_valued_dict()
715715
for o in objects:
716-
self.assert_(weakref.getweakrefcount(o) == 1,
717-
"wrong number of weak references to %r!" % o)
716+
self.assertEqual(weakref.getweakrefcount(o), 1)
718717
self.assert_(o is dict[o.arg],
719718
"wrong object returned by weak dict!")
720719
items1 = dict.items()

Modules/_bsddb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,7 +5350,7 @@ static PyTypeObject DB_Type = {
53505350
0, /* tp_getattro */
53515351
0, /* tp_setattro */
53525352
0, /* tp_as_buffer */
5353-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5353+
Py_TPFLAGS_DEFAULT, /* tp_flags */
53545354
0, /* tp_doc */
53555355
0, /* tp_traverse */
53565356
0, /* tp_clear */
@@ -5383,7 +5383,7 @@ static PyTypeObject DBCursor_Type = {
53835383
0, /* tp_getattro */
53845384
0, /* tp_setattro */
53855385
0, /* tp_as_buffer */
5386-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5386+
Py_TPFLAGS_DEFAULT, /* tp_flags */
53875387
0, /* tp_doc */
53885388
0, /* tp_traverse */
53895389
0, /* tp_clear */
@@ -5416,7 +5416,7 @@ static PyTypeObject DBEnv_Type = {
54165416
0, /* tp_getattro */
54175417
0, /* tp_setattro */
54185418
0, /* tp_as_buffer */
5419-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5419+
Py_TPFLAGS_DEFAULT, /* tp_flags */
54205420
0, /* tp_doc */
54215421
0, /* tp_traverse */
54225422
0, /* tp_clear */
@@ -5448,7 +5448,7 @@ static PyTypeObject DBTxn_Type = {
54485448
0, /* tp_getattro */
54495449
0, /* tp_setattro */
54505450
0, /* tp_as_buffer */
5451-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5451+
Py_TPFLAGS_DEFAULT, /* tp_flags */
54525452
0, /* tp_doc */
54535453
0, /* tp_traverse */
54545454
0, /* tp_clear */
@@ -5481,7 +5481,7 @@ static PyTypeObject DBLock_Type = {
54815481
0, /* tp_getattro */
54825482
0, /* tp_setattro */
54835483
0, /* tp_as_buffer */
5484-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5484+
Py_TPFLAGS_DEFAULT, /* tp_flags */
54855485
0, /* tp_doc */
54865486
0, /* tp_traverse */
54875487
0, /* tp_clear */
@@ -5514,7 +5514,7 @@ static PyTypeObject DBSequence_Type = {
55145514
0, /* tp_getattro */
55155515
0, /* tp_setattro */
55165516
0, /* tp_as_buffer */
5517-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
5517+
Py_TPFLAGS_DEFAULT, /* tp_flags */
55185518
0, /* tp_doc */
55195519
0, /* tp_traverse */
55205520
0, /* tp_clear */

Modules/_ctypes/stgdict.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ PyType_stgdict(PyObject *obj)
128128
if (!PyType_Check(obj))
129129
return NULL;
130130
type = (PyTypeObject *)obj;
131-
if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS))
132-
return NULL;
133131
if (!type->tp_dict || !StgDict_Check(type->tp_dict))
134132
return NULL;
135133
return (StgDictObject *)type->tp_dict;

Modules/_functoolsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static PyTypeObject partial_type = {
219219
PyObject_GenericSetAttr, /* tp_setattro */
220220
0, /* tp_as_buffer */
221221
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
222-
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
222+
Py_TPFLAGS_BASETYPE, /* tp_flags */
223223
partial_doc, /* tp_doc */
224224
(traverseproc)partial_traverse, /* tp_traverse */
225225
0, /* tp_clear */

Modules/_sqlite/cursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ PyTypeObject CursorType = {
998998
0, /* tp_getattro */
999999
0, /* tp_setattro */
10001000
0, /* tp_as_buffer */
1001-
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER|Py_TPFLAGS_BASETYPE, /* tp_flags */
1001+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
10021002
cursor_doc, /* tp_doc */
10031003
0, /* tp_traverse */
10041004
0, /* tp_clear */

0 commit comments

Comments
 (0)