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