mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
PEP 205, Weak References -- initial checkin.
This commit is contained in:
parent
2de7471d69
commit
41deb1efc2
9 changed files with 1158 additions and 4 deletions
|
|
@ -24,6 +24,7 @@ typedef struct {
|
|||
PyObject_HEAD
|
||||
PyClassObject *in_class; /* The class object */
|
||||
PyObject *in_dict; /* A dictionary */
|
||||
PyObject *in_weakreflist; /* List of weak references */
|
||||
} PyInstanceObject;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -246,8 +246,8 @@ typedef struct _typeobject {
|
|||
/* rich comparisons */
|
||||
richcmpfunc tp_richcompare;
|
||||
|
||||
/* More spares */
|
||||
long tp_xxx8;
|
||||
/* weak reference enabler */
|
||||
long tp_weaklistoffset;
|
||||
|
||||
#ifdef COUNT_ALLOCS
|
||||
/* these must be last */
|
||||
|
|
@ -284,6 +284,8 @@ extern DL_IMPORT(int) PyCallable_Check(PyObject *);
|
|||
extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **);
|
||||
extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **);
|
||||
|
||||
extern DL_IMPORT(int) (*PyObject_ClearWeakRefs)(PyObject *);
|
||||
|
||||
/* Helpers for printing recursive container types */
|
||||
extern DL_IMPORT(int) Py_ReprEnter(PyObject *);
|
||||
extern DL_IMPORT(void) Py_ReprLeave(PyObject *);
|
||||
|
|
@ -418,7 +420,7 @@ extern DL_IMPORT(long) _Py_RefTotal;
|
|||
|
||||
#define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++)
|
||||
#define Py_DECREF(op) \
|
||||
if (--_Py_RefTotal, --(op)->ob_refcnt != 0) \
|
||||
if (--_Py_RefTotal, (--((op)->ob_refcnt) != 0)) \
|
||||
; \
|
||||
else \
|
||||
_Py_Dealloc((PyObject *)(op))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue