summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-03-07 09:57:45 (GMT)
committerGitHub <noreply@github.com>2022-03-07 09:57:45 (GMT)
commit5c06dba21b9767127f042b8a168703f06338c3f4 (patch)
tree9d0120fe1fea5512b8e875ecd7597d2c05f78e48
parent496c428de3318c9c5770937491b71dc3d3f18a6a (diff)
downloadcpython-5c06dba21b9767127f042b8a168703f06338c3f4.zip
cpython-5c06dba21b9767127f042b8a168703f06338c3f4.tar.gz
cpython-5c06dba21b9767127f042b8a168703f06338c3f4.tar.bz2
bpo-46937: convert remaining functions to AC in _weakref (GH-31705)
-rw-r--r--Modules/_weakref.c47
-rw-r--r--Modules/clinic/_weakref.c.h48
2 files changed, 73 insertions, 22 deletions
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index edc09b9..157a852 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -76,12 +76,17 @@ _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct,
}
-PyDoc_STRVAR(weakref_getweakrefs__doc__,
-"getweakrefs(object) -- return a list of all weak reference objects\n"
-"that point to 'object'.");
+/*[clinic input]
+_weakref.getweakrefs
+ object: object
+ /
+
+Return a list of all weak reference objects pointing to 'object'.
+[clinic start generated code]*/
static PyObject *
-weakref_getweakrefs(PyObject *self, PyObject *object)
+_weakref_getweakrefs(PyObject *module, PyObject *object)
+/*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693]*/
{
PyObject *result = NULL;
@@ -107,22 +112,24 @@ weakref_getweakrefs(PyObject *self, PyObject *object)
}
-PyDoc_STRVAR(weakref_proxy__doc__,
-"proxy(object[, callback]) -- create a proxy object that weakly\n"
-"references 'object'. 'callback', if given, is called with a\n"
-"reference to the proxy when 'object' is about to be finalized.");
+/*[clinic input]
+
+_weakref.proxy
+ object: object
+ callback: object(c_default="NULL") = None
+ /
+
+Create a proxy object that weakly references 'object'.
+
+'callback', if given, is called with a reference to the
+proxy when 'object' is about to be finalized.
+[clinic start generated code]*/
static PyObject *
-weakref_proxy(PyObject *self, PyObject *args)
+_weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback)
+/*[clinic end generated code: output=d68fa4ad9ea40519 input=4808adf22fd137e7]*/
{
- PyObject *object;
- PyObject *callback = NULL;
- PyObject *result = NULL;
-
- if (PyArg_UnpackTuple(args, "proxy", 1, 2, &object, &callback)) {
- result = PyWeakref_NewProxy(object, callback);
- }
- return result;
+ return PyWeakref_NewProxy(object, callback);
}
@@ -130,10 +137,8 @@ static PyMethodDef
weakref_functions[] = {
_WEAKREF_GETWEAKREFCOUNT_METHODDEF
_WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF
- {"getweakrefs", weakref_getweakrefs, METH_O,
- weakref_getweakrefs__doc__},
- {"proxy", weakref_proxy, METH_VARARGS,
- weakref_proxy__doc__},
+ _WEAKREF_GETWEAKREFS_METHODDEF
+ _WEAKREF_PROXY_METHODDEF
{NULL, NULL, 0, NULL}
};
diff --git a/Modules/clinic/_weakref.c.h b/Modules/clinic/_weakref.c.h
index c3a908f..02f0168 100644
--- a/Modules/clinic/_weakref.c.h
+++ b/Modules/clinic/_weakref.c.h
@@ -64,4 +64,50 @@ _weakref__remove_dead_weakref(PyObject *module, PyObject *const *args, Py_ssize_
exit:
return return_value;
}
-/*[clinic end generated code: output=c543dc2cd6ece975 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(_weakref_getweakrefs__doc__,
+"getweakrefs($module, object, /)\n"
+"--\n"
+"\n"
+"Return a list of all weak reference objects pointing to \'object\'.");
+
+#define _WEAKREF_GETWEAKREFS_METHODDEF \
+ {"getweakrefs", (PyCFunction)_weakref_getweakrefs, METH_O, _weakref_getweakrefs__doc__},
+
+PyDoc_STRVAR(_weakref_proxy__doc__,
+"proxy($module, object, callback=None, /)\n"
+"--\n"
+"\n"
+"Create a proxy object that weakly references \'object\'.\n"
+"\n"
+"\'callback\', if given, is called with a reference to the\n"
+"proxy when \'object\' is about to be finalized.");
+
+#define _WEAKREF_PROXY_METHODDEF \
+ {"proxy", (PyCFunction)(void(*)(void))_weakref_proxy, METH_FASTCALL, _weakref_proxy__doc__},
+
+static PyObject *
+_weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback);
+
+static PyObject *
+_weakref_proxy(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *object;
+ PyObject *callback = NULL;
+
+ if (!_PyArg_CheckPositional("proxy", nargs, 1, 2)) {
+ goto exit;
+ }
+ object = args[0];
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ callback = args[1];
+skip_optional:
+ return_value = _weakref_proxy_impl(module, object, callback);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=5a10a1fa43722399 input=a9049054013a1b77]*/