]> granicus.if.org Git - python/commitdiff
Use a type flag to determine the applicability of the tp_weaklistoffset
authorFred Drake <fdrake@acm.org>
Fri, 2 Feb 2001 18:17:30 +0000 (18:17 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 2 Feb 2001 18:17:30 +0000 (18:17 +0000)
field.  This should avoid binary incompatibility problems with older modules
that have not been recompiled.

Include/object.h
Include/objimpl.h

index 972e05b1e7f7329a51c21543602776c7cbbb881e..2f683eb58857175b264efe6669a33cf2cce7e691 100644 (file)
@@ -344,11 +344,18 @@ given type object has a specified feature.
 
 #define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
 
+/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
+/* XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE?
+ * These both indicate a feature that appeared in the same alpha release.
+ */
+#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
+
 #define Py_TPFLAGS_DEFAULT  ( \
                              Py_TPFLAGS_HAVE_GETCHARBUFFER | \
                              Py_TPFLAGS_HAVE_SEQUENCE_IN | \
                              Py_TPFLAGS_HAVE_INPLACEOPS | \
                              Py_TPFLAGS_HAVE_RICHCOMPARE | \
+                             Py_TPFLAGS_HAVE_WEAKREFS | \
                             0)
 
 #define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
index 93c5b2346abb889f6a84f262570f9b2a87d0b8a7..9c13e71e0f053faec25a21831be90d6e3d10b45f 100644 (file)
@@ -271,7 +271,9 @@ extern DL_IMPORT(void) _PyGC_Dump(PyGC_Head *);
 #endif /* WITH_CYCLE_GC */
 
 /* Test if a type supports weak references */
-#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
+#define PyType_SUPPORTS_WEAKREFS(t) \
+        (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
+         && ((t)->tp_weaklistoffset > 0))
 
 #define PyObject_GET_WEAKREFS_LISTPTR(o) \
        ((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))