cpython/Modules/_testcapi/weakref.c
Serhiy Storchaka 52ffdeda1d
[3.13] gh-151130: Add more tests for PyWeakref_* C API (GH-151131) (GH-151141) (#151148)
(cherry picked from commit cb96d5ea4a)


(cherry picked from commit c3cd75afdf)
2026-06-09 22:24:39 +02:00

34 lines
684 B
C

#include "parts.h"
#include "util.h"
static PyObject *
pyweakref_getref(PyObject *module, PyObject *ref)
{
NULLABLE(ref);
PyObject *obj = UNINITIALIZED_PTR;
int rc = PyWeakref_GetRef(ref, &obj);
if (rc == -1 && PyErr_Occurred()) {
assert(obj == NULL);
return NULL;
}
if (obj == NULL) {
return Py_BuildValue("i", rc);
}
else {
assert(obj != UNINITIALIZED_PTR);
return Py_BuildValue("iN", rc, obj);
}
}
static PyMethodDef test_methods[] = {
{"pyweakref_getref", pyweakref_getref, METH_O},
{NULL},
};
int
_PyTestCapi_Init_Weakref(PyObject *m)
{
return PyModule_AddFunctions(m, test_methods);
}