mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +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
|
@ -100,6 +100,10 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
|
|||
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
|
||||
op->ob_type = tp;
|
||||
_Py_NewReference(op);
|
||||
if (PyType_SUPPORTS_WEAKREFS(tp)) {
|
||||
PyObject **weaklist = PyObject_GET_WEAKREFS_LISTPTR(op);
|
||||
*weaklist = NULL;
|
||||
}
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -119,6 +123,10 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, int size)
|
|||
op->ob_size = size;
|
||||
op->ob_type = tp;
|
||||
_Py_NewReference((PyObject *)op);
|
||||
if (PyType_SUPPORTS_WEAKREFS(tp)) {
|
||||
PyObject **weaklist = PyObject_GET_WEAKREFS_LISTPTR(op);
|
||||
*weaklist = NULL;
|
||||
}
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -1458,6 +1466,21 @@ PyObject_Free(void *p)
|
|||
}
|
||||
|
||||
|
||||
/* Hook to clear up weak references only once the _weakref module is
|
||||
imported. We use a dummy implementation to simplify the code at each
|
||||
call site instead of requiring a test for NULL.
|
||||
*/
|
||||
|
||||
static int
|
||||
empty_clear_weak_refs(PyObject *o)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int (*PyObject_ClearWeakRefs)(PyObject *) = empty_clear_weak_refs;
|
||||
|
||||
|
||||
|
||||
/* These methods are used to control infinite recursion in repr, str, print,
|
||||
etc. Container objects that may recursively contain themselves,
|
||||
e.g. builtin dictionaries and lists, should used Py_ReprEnter() and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue