diff options
author | Larry Hastings <larry@hastings.org> | 2013-10-19 07:09:25 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2013-10-19 07:09:25 (GMT) |
commit | 3182680210fa0cf570233382bbaec8b64d57f4da (patch) | |
tree | 93932cf52fd5cbbdeab62b2fc43851e3cb637e3d /Modules/_weakref.c | |
parent | 5ceae41083f3bec479fe8f135f442e6576c6e273 (diff) | |
download | cpython-3182680210fa0cf570233382bbaec8b64d57f4da.zip cpython-3182680210fa0cf570233382bbaec8b64d57f4da.tar.gz cpython-3182680210fa0cf570233382bbaec8b64d57f4da.tar.bz2 |
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
for C files to generate argument parsing code. (See PEP 436.)
Diffstat (limited to 'Modules/_weakref.c')
-rw-r--r-- | Modules/_weakref.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/Modules/_weakref.c b/Modules/_weakref.c index 88995b8..1e8debc 100644 --- a/Modules/_weakref.c +++ b/Modules/_weakref.c @@ -4,25 +4,54 @@ #define GET_WEAKREFS_LISTPTR(o) \ ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o)) +/*[clinic] -PyDoc_STRVAR(weakref_getweakrefcount__doc__, -"getweakrefcount(object) -- return the number of weak references\n" -"to 'object'."); +module _weakref + +_weakref.getweakrefcount -> Py_ssize_t + + object: object + / + +Return the number of weak references to 'object'. +[clinic]*/ + +PyDoc_STRVAR(_weakref_getweakrefcount__doc__, +"Return the number of weak references to \'object\'.\n" +"\n" +"_weakref.getweakrefcount(object)"); + +#define _WEAKREF_GETWEAKREFCOUNT_METHODDEF \ + {"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_O, _weakref_getweakrefcount__doc__}, + +static Py_ssize_t +_weakref_getweakrefcount_impl(PyObject *self, PyObject *object); static PyObject * -weakref_getweakrefcount(PyObject *self, PyObject *object) +_weakref_getweakrefcount(PyObject *self, PyObject *object) { - PyObject *result = NULL; - - if (PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) { - PyWeakReference **list = GET_WEAKREFS_LISTPTR(object); + PyObject *return_value = NULL; + Py_ssize_t _return_value; + _return_value = _weakref_getweakrefcount_impl(self, object); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromSsize_t(_return_value); + +exit: + return return_value; +} - result = PyLong_FromSsize_t(_PyWeakref_GetWeakrefCount(*list)); - } - else - result = PyLong_FromLong(0); +static Py_ssize_t +_weakref_getweakrefcount_impl(PyObject *self, PyObject *object) +/*[clinic checksum: 0b7e7ddd87d483719ebac0fba364fff0ed0182d9]*/ +{ + PyWeakReference **list; - return result; + if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) + return 0; + + list = GET_WEAKREFS_LISTPTR(object); + return _PyWeakref_GetWeakrefCount(*list); } @@ -78,8 +107,7 @@ weakref_proxy(PyObject *self, PyObject *args) static PyMethodDef weakref_functions[] = { - {"getweakrefcount", weakref_getweakrefcount, METH_O, - weakref_getweakrefcount__doc__}, + _WEAKREF_GETWEAKREFCOUNT_METHODDEF {"getweakrefs", weakref_getweakrefs, METH_O, weakref_getweakrefs__doc__}, {"proxy", weakref_proxy, METH_VARARGS, @@ -106,7 +134,7 @@ PyInit__weakref(void) PyObject *m; m = PyModule_Create(&weakrefmodule); - + if (m != NULL) { Py_INCREF(&_PyWeakref_RefType); PyModule_AddObject(m, "ref", |