diff options
author | Fred Drake <fdrake@acm.org> | 2001-02-01 05:27:45 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-02-01 05:27:45 (GMT) |
commit | 41deb1efc2f969b58e49af669cc20d15ccdb04c6 (patch) | |
tree | 6478ef737151fb4e091594b78f611318a15d3a31 /Include/objimpl.h | |
parent | 2de7471d69b950a64e52a950675d59d9f4071da1 (diff) | |
download | cpython-41deb1efc2f969b58e49af669cc20d15ccdb04c6.zip cpython-41deb1efc2f969b58e49af669cc20d15ccdb04c6.tar.gz cpython-41deb1efc2f969b58e49af669cc20d15ccdb04c6.tar.bz2 |
PEP 205, Weak References -- initial checkin.
Diffstat (limited to 'Include/objimpl.h')
-rw-r--r-- | Include/objimpl.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h index 4909517..93c5b23 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -160,7 +160,11 @@ extern DL_IMPORT(void) _PyObject_Del(PyObject *); /* Macros trading binary compatibility for speed. See also pymem.h. Note that these macros expect non-NULL object pointers.*/ #define PyObject_INIT(op, typeobj) \ - ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) + ((op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), \ + (PyType_SUPPORTS_WEAKREFS((typeobj)) \ + ? *(PyObject_GET_WEAKREFS_LISTPTR(op)) = NULL \ + : NULL), \ + (op)) #define PyObject_INIT_VAR(op, typeobj, size) \ ( (op)->ob_size = (size), PyObject_INIT((op), (typeobj)) ) @@ -266,6 +270,12 @@ 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 PyObject_GET_WEAKREFS_LISTPTR(o) \ + ((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset)) + #ifdef __cplusplus } #endif |