/src/cpython/Modules/clinic/_weakref.c.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #include "pycore_modsupport.h" // _PyArg_CheckPositional() |
6 | | |
7 | | PyDoc_STRVAR(_weakref_getweakrefcount__doc__, |
8 | | "getweakrefcount($module, object, /)\n" |
9 | | "--\n" |
10 | | "\n" |
11 | | "Return the number of weak references to \'object\'."); |
12 | | |
13 | | #define _WEAKREF_GETWEAKREFCOUNT_METHODDEF \ |
14 | | {"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_O, _weakref_getweakrefcount__doc__}, |
15 | | |
16 | | static Py_ssize_t |
17 | | _weakref_getweakrefcount_impl(PyObject *module, PyObject *object); |
18 | | |
19 | | static PyObject * |
20 | | _weakref_getweakrefcount(PyObject *module, PyObject *object) |
21 | 0 | { |
22 | 0 | PyObject *return_value = NULL; |
23 | 0 | Py_ssize_t _return_value; |
24 | |
|
25 | 0 | _return_value = _weakref_getweakrefcount_impl(module, object); |
26 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
27 | 0 | goto exit; |
28 | 0 | } |
29 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
30 | |
|
31 | 0 | exit: |
32 | 0 | return return_value; |
33 | 0 | } |
34 | | |
35 | | PyDoc_STRVAR(_weakref__remove_dead_weakref__doc__, |
36 | | "_remove_dead_weakref($module, dct, key, /)\n" |
37 | | "--\n" |
38 | | "\n" |
39 | | "Atomically remove key from dict if it points to a dead weakref."); |
40 | | |
41 | | #define _WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF \ |
42 | | {"_remove_dead_weakref", _PyCFunction_CAST(_weakref__remove_dead_weakref), METH_FASTCALL, _weakref__remove_dead_weakref__doc__}, |
43 | | |
44 | | static PyObject * |
45 | | _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct, |
46 | | PyObject *key); |
47 | | |
48 | | static PyObject * |
49 | | _weakref__remove_dead_weakref(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
50 | 2.91k | { |
51 | 2.91k | PyObject *return_value = NULL; |
52 | 2.91k | PyObject *dct; |
53 | 2.91k | PyObject *key; |
54 | | |
55 | 2.91k | if (!_PyArg_CheckPositional("_remove_dead_weakref", nargs, 2, 2)) { |
56 | 0 | goto exit; |
57 | 0 | } |
58 | 2.91k | if (!PyDict_Check(args[0])) { |
59 | 0 | _PyArg_BadArgument("_remove_dead_weakref", "argument 1", "dict", args[0]); |
60 | 0 | goto exit; |
61 | 0 | } |
62 | 2.91k | dct = args[0]; |
63 | 2.91k | key = args[1]; |
64 | 2.91k | return_value = _weakref__remove_dead_weakref_impl(module, dct, key); |
65 | | |
66 | 2.91k | exit: |
67 | 2.91k | return return_value; |
68 | 2.91k | } |
69 | | |
70 | | PyDoc_STRVAR(_weakref_getweakrefs__doc__, |
71 | | "getweakrefs($module, object, /)\n" |
72 | | "--\n" |
73 | | "\n" |
74 | | "Return a list of all weak reference objects pointing to \'object\'."); |
75 | | |
76 | | #define _WEAKREF_GETWEAKREFS_METHODDEF \ |
77 | | {"getweakrefs", (PyCFunction)_weakref_getweakrefs, METH_O, _weakref_getweakrefs__doc__}, |
78 | | |
79 | | PyDoc_STRVAR(_weakref_proxy__doc__, |
80 | | "proxy($module, object, callback=None, /)\n" |
81 | | "--\n" |
82 | | "\n" |
83 | | "Create a proxy object that weakly references \'object\'.\n" |
84 | | "\n" |
85 | | "\'callback\', if given, is called with a reference to the\n" |
86 | | "proxy when \'object\' is about to be finalized."); |
87 | | |
88 | | #define _WEAKREF_PROXY_METHODDEF \ |
89 | | {"proxy", _PyCFunction_CAST(_weakref_proxy), METH_FASTCALL, _weakref_proxy__doc__}, |
90 | | |
91 | | static PyObject * |
92 | | _weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback); |
93 | | |
94 | | static PyObject * |
95 | | _weakref_proxy(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
96 | 0 | { |
97 | 0 | PyObject *return_value = NULL; |
98 | 0 | PyObject *object; |
99 | 0 | PyObject *callback = NULL; |
100 | |
|
101 | 0 | if (!_PyArg_CheckPositional("proxy", nargs, 1, 2)) { |
102 | 0 | goto exit; |
103 | 0 | } |
104 | 0 | object = args[0]; |
105 | 0 | if (nargs < 2) { |
106 | 0 | goto skip_optional; |
107 | 0 | } |
108 | 0 | callback = args[1]; |
109 | 0 | skip_optional: |
110 | 0 | return_value = _weakref_proxy_impl(module, object, callback); |
111 | |
|
112 | 0 | exit: |
113 | 0 | return return_value; |
114 | 0 | } |
115 | | /*[clinic end generated code: output=60f59adc1dc9eab8 input=a9049054013a1b77]*/ |