diff options
author | Victor Stinner <vstinner@python.org> | 2023-06-21 09:40:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 09:40:09 (GMT) |
commit | 9c44656febdcf72583e192ea4530fcfb0936c309 (patch) | |
tree | 57fc76b2d09c68541c2f6da186494768d52c6502 /Objects | |
parent | 4d140e5e067d3315e163c0f1ac2f80c05ec790c6 (diff) | |
download | cpython-9c44656febdcf72583e192ea4530fcfb0936c309.zip cpython-9c44656febdcf72583e192ea4530fcfb0936c309.tar.gz cpython-9c44656febdcf72583e192ea4530fcfb0936c309.tar.bz2 |
gh-105927: Add PyWeakref_GetRef() function (#105932)
Add tests on PyWeakref_NewRef(), PyWeakref_GetObject(),
PyWeakref_GET_OBJECT() and PyWeakref_GetRef().
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/weakrefobject.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 9995a77..49342d0 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -894,6 +894,24 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback) } +int +PyWeakref_GetRef(PyObject *ref, PyObject **pobj) +{ + if (ref == NULL) { + *pobj = NULL; + PyErr_BadInternalCall(); + return -1; + } + if (!PyWeakref_Check(ref)) { + *pobj = NULL; + PyErr_SetString(PyExc_TypeError, "expected a weakref"); + return -1; + } + *pobj = _PyWeakref_GET_REF(ref); + return 0; +} + + PyObject * PyWeakref_GetObject(PyObject *ref) { |