• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
_weakref_getweakrefcount(PyObject * module,PyObject * object)20 _weakref_getweakrefcount(PyObject *module, PyObject *object)
21 {
22     PyObject *return_value = NULL;
23     Py_ssize_t _return_value;
24 
25     _return_value = _weakref_getweakrefcount_impl(module, object);
26     if ((_return_value == -1) && PyErr_Occurred()) {
27         goto exit;
28     }
29     return_value = PyLong_FromSsize_t(_return_value);
30 
31 exit:
32     return return_value;
33 }
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 *
_weakref__remove_dead_weakref(PyObject * module,PyObject * const * args,Py_ssize_t nargs)49 _weakref__remove_dead_weakref(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
50 {
51     PyObject *return_value = NULL;
52     PyObject *dct;
53     PyObject *key;
54 
55     if (!_PyArg_CheckPositional("_remove_dead_weakref", nargs, 2, 2)) {
56         goto exit;
57     }
58     if (!PyDict_Check(args[0])) {
59         _PyArg_BadArgument("_remove_dead_weakref", "argument 1", "dict", args[0]);
60         goto exit;
61     }
62     dct = args[0];
63     key = args[1];
64     return_value = _weakref__remove_dead_weakref_impl(module, dct, key);
65 
66 exit:
67     return return_value;
68 }
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 *
_weakref_proxy(PyObject * module,PyObject * const * args,Py_ssize_t nargs)95 _weakref_proxy(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
96 {
97     PyObject *return_value = NULL;
98     PyObject *object;
99     PyObject *callback = NULL;
100 
101     if (!_PyArg_CheckPositional("proxy", nargs, 1, 2)) {
102         goto exit;
103     }
104     object = args[0];
105     if (nargs < 2) {
106         goto skip_optional;
107     }
108     callback = args[1];
109 skip_optional:
110     return_value = _weakref_proxy_impl(module, object, callback);
111 
112 exit:
113     return return_value;
114 }
115 /*[clinic end generated code: output=60f59adc1dc9eab8 input=a9049054013a1b77]*/
116