Skip to content

[3.8] Revert "bpo-33418: Add tp_clear for function object (GH-8058)" #15826

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 1 commit into from
Sep 10, 2019
Merged
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
34 changes: 13 additions & 21 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,31 +570,23 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
return (PyObject *)newfunc;
}

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 != NULL) {
if (op->func_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) op);
}
(void)func_clear(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);
PyObject_GC_Del(op);
}

Expand Down Expand Up @@ -669,7 +661,7 @@ PyTypeObject PyFunction_Type = {
Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */
func_new__doc__, /* tp_doc */
(traverseproc)func_traverse, /* tp_traverse */
(inquiry)func_clear, /* tp_clear */
0, /* tp_clear */
0, /* tp_richcompare */
offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */
0, /* tp_iter */
Expand Down