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