Skip to content

bpo-46937: convert remaining functions to AC in _weakref #31705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions Modules/_weakref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -107,33 +112,33 @@ 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);
}


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}
};

Expand Down
48 changes: 47 additions & 1 deletion Modules/clinic/_weakref.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.