Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 033f312

Browse files
committed
Use a type flag to determine the applicability of the tp_weaklistoffset
field. This should avoid binary incompatibility problems with older modules that have not been recompiled.
1 parent 26d1f14 commit 033f312

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Include/object.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,18 @@ given type object has a specified feature.
344344

345345
#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
346346

347+
/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
348+
/* XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE?
349+
* These both indicate a feature that appeared in the same alpha release.
350+
*/
351+
#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
352+
347353
#define Py_TPFLAGS_DEFAULT ( \
348354
Py_TPFLAGS_HAVE_GETCHARBUFFER | \
349355
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
350356
Py_TPFLAGS_HAVE_INPLACEOPS | \
351357
Py_TPFLAGS_HAVE_RICHCOMPARE | \
358+
Py_TPFLAGS_HAVE_WEAKREFS | \
352359
0)
353360

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

Include/objimpl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ extern DL_IMPORT(void) _PyGC_Dump(PyGC_Head *);
271271
#endif /* WITH_CYCLE_GC */
272272

273273
/* Test if a type supports weak references */
274-
#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
274+
#define PyType_SUPPORTS_WEAKREFS(t) \
275+
(PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
276+
&& ((t)->tp_weaklistoffset > 0))
275277

276278
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
277279
((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))

0 commit comments

Comments
 (0)