Debian Codegraph @

Modules/_testlimitedcapi/weakref.c

raw
1 #include "pyconfig.h" // Py_GIL_DISABLED
2 #ifndef Py_GIL_DISABLED
3 // Need limited C API 3.5 for PyModule_AddFunctions()
4 # define Py_LIMITED_API 0x03050000
5 #endif
6
7 #include "parts.h"
8 #include "util.h"
9
10
11 static PyObject *
12 pyweakref_check(PyObject *module, PyObject *obj)
13 {
14 NULLABLE(obj);
15 return PyLong_FromLong(PyWeakref_Check(obj));
16 }
17
18 static PyObject *
19 pyweakref_checkref(PyObject *module, PyObject *obj)
20 {
21 NULLABLE(obj);
22 return PyLong_FromLong(PyWeakref_CheckRef(obj));
23 }
24
25 static PyObject *
26 pyweakref_checkrefexact(PyObject *module, PyObject *obj)
27 {
28 NULLABLE(obj);
29 return PyLong_FromLong(PyWeakref_CheckRefExact(obj));
30 }
31
32 static PyObject *
33 pyweakref_checkproxy(PyObject *module, PyObject *obj)
34 {
35 NULLABLE(obj);
36 return PyLong_FromLong(PyWeakref_CheckProxy(obj));
37 }
38
39 static PyObject *
40 pyweakref_newref(PyObject *module, PyObject *args)
41 {
42 PyObject *obj;
43 PyObject *callback = NULL;
44 if (!PyArg_ParseTuple(args, "O|O", &obj, &callback)) {
45 return NULL;
46 }
47 NULLABLE(obj);
48 return PyWeakref_NewRef(obj, callback);
49 }
50
51 static PyObject *
52 pyweakref_newproxy(PyObject *module, PyObject *args)
53 {
54 PyObject *obj;
55 PyObject *callback = NULL;
56 if (!PyArg_ParseTuple(args, "O|O", &obj, &callback)) {
57 return NULL;
58 }
59 NULLABLE(obj);
60 return PyWeakref_NewProxy(obj, callback);
61 }
62
63
64 static PyMethodDef test_methods[] = {
65 {"pyweakref_check", pyweakref_check, METH_O},
66 {"pyweakref_checkref", pyweakref_checkref, METH_O},
67 {"pyweakref_checkrefexact", pyweakref_checkrefexact, METH_O},
68 {"pyweakref_checkproxy", pyweakref_checkproxy, METH_O},
69 {"pyweakref_newref", pyweakref_newref, METH_VARARGS},
70 {"pyweakref_newproxy", pyweakref_newproxy, METH_VARARGS},
71 {NULL},
72 };
73
74 int
75 _PyTestLimitedCAPI_Init_Weakref(PyObject *m)
76 {
77 return PyModule_AddFunctions(m, test_methods);
78 }