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