[Python-checkins] (no subject)
Łukasz Langa
webhook-mailer at python.org
Tue Oct 1 03:49:42 EDT 2019
To: python-checkins at python.org
Subject: Restore tp_clear for function object. (#16502)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
https://github.com/python/cpython/commit/b3612070b746f799901443b65725008bc035=
872b
commit: b3612070b746f799901443b65725008bc035872b
branch: 3.8
author: Neil Schemenauer <nas-github at arctrix.com>
committer: =C5=81ukasz Langa <lukasz at langa.pl>
date: 2019-10-01T09:49:36+02:00
summary:
Restore tp_clear for function object. (#16502)
This is a revert of the revert (GH-15826). Having a tp_clear for
functions should be safe (and helpful) now that bpo-38006 has been
fixed.
files:
M Objects/funcobject.c
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 53aebf12f550..df5cc2d3f570 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -570,23 +570,31 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, P=
yObject *globals,
return (PyObject *)newfunc;
}
=20
+static int
+func_clear(PyFunctionObject *op)
+{
+ Py_CLEAR(op->func_code);
+ Py_CLEAR(op->func_globals);
+ Py_CLEAR(op->func_module);
+ Py_CLEAR(op->func_name);
+ Py_CLEAR(op->func_defaults);
+ Py_CLEAR(op->func_kwdefaults);
+ Py_CLEAR(op->func_doc);
+ Py_CLEAR(op->func_dict);
+ Py_CLEAR(op->func_closure);
+ Py_CLEAR(op->func_annotations);
+ Py_CLEAR(op->func_qualname);
+ return 0;
+}
+
static void
func_dealloc(PyFunctionObject *op)
{
_PyObject_GC_UNTRACK(op);
- if (op->func_weakreflist !=3D NULL)
+ if (op->func_weakreflist !=3D NULL) {
PyObject_ClearWeakRefs((PyObject *) op);
- Py_DECREF(op->func_code);
- Py_DECREF(op->func_globals);
- Py_XDECREF(op->func_module);
- Py_DECREF(op->func_name);
- Py_XDECREF(op->func_defaults);
- Py_XDECREF(op->func_kwdefaults);
- Py_XDECREF(op->func_doc);
- Py_XDECREF(op->func_dict);
- Py_XDECREF(op->func_closure);
- Py_XDECREF(op->func_annotations);
- Py_XDECREF(op->func_qualname);
+ }
+ (void)func_clear(op);
PyObject_GC_Del(op);
}
=20
@@ -661,7 +669,7 @@ PyTypeObject PyFunction_Type =3D {
Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */
func_new__doc__, /* tp_doc */
(traverseproc)func_traverse, /* tp_traverse */
- 0, /* tp_clear */
+ (inquiry)func_clear, /* tp_clear */
0, /* tp_richcompare */
offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */
0, /* tp_iter */
More information about the Python-checkins
mailing list