| 1 |
#include "parts.h" |
| 2 |
#include "util.h" |
| 3 |
|
| 4 |
|
| 5 |
static PyObject * |
| 6 |
pyweakref_getref(PyObject *module, PyObject *ref) |
| 7 |
{ |
| 8 |
NULLABLE(ref); |
| 9 |
PyObject *obj = UNINITIALIZED_PTR; |
| 10 |
int rc = PyWeakref_GetRef(ref, &obj); |
| 11 |
if (rc == -1 && PyErr_Occurred()) { |
| 12 |
assert(obj == NULL); |
| 13 |
return NULL; |
| 14 |
} |
| 15 |
if (obj == NULL) { |
| 16 |
return Py_BuildValue("i", rc); |
| 17 |
} |
| 18 |
else { |
| 19 |
assert(obj != UNINITIALIZED_PTR); |
| 20 |
return Py_BuildValue("iN", rc, obj); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
static PyObject * |
| 25 |
pyweakref_isdead(PyObject *module, PyObject *obj) |
| 26 |
{ |
| 27 |
NULLABLE(obj); |
| 28 |
int rc = PyWeakref_IsDead(obj); |
| 29 |
if (rc == -1 && PyErr_Occurred()) { |
| 30 |
return NULL; |
| 31 |
} |
| 32 |
return PyLong_FromLong(rc); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
static PyMethodDef test_methods[] = { |
| 37 |
{"pyweakref_getref", pyweakref_getref, METH_O}, |
| 38 |
{"pyweakref_isdead", pyweakref_isdead, METH_O}, |
| 39 |
{NULL}, |
| 40 |
}; |
| 41 |
|
| 42 |
int |
| 43 |
_PyTestCapi_Init_Weakref(PyObject *m) |
| 44 |
{ |
| 45 |
return PyModule_AddFunctions(m, test_methods); |
| 46 |
} |