Skip to content

Commit

Permalink
Revert "[3.11] GH-92678: Expose managed dict clear and visit functions (
Browse files Browse the repository at this point in the history
GH-95246). (#95256)"

This reverts commit 7f73194.
  • Loading branch information
markshannon authored Aug 4, 2022
1 parent 2ab5601 commit 5dc94e7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 55 deletions.
3 changes: 0 additions & 3 deletions Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,3 @@ typedef struct {

PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *);
PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);

PyAPI_FUNC(int) _PyObject_VisitManagedDict(PyObject *self, visitproc visit, void *arg);
PyAPI_FUNC(void) _PyObject_ClearManagedDict(PyObject *self);
14 changes: 0 additions & 14 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,20 +724,6 @@ def test_export_symbols(self):
with self.subTest(name=name):
self.assertTrue(hasattr(ctypes.pythonapi, name))

def test_clear_managed_dict(self):

class C:
def __init__(self):
self.a = 1

c = C()
_testcapi.clear_managed_dict(c)
self.assertEqual(c.__dict__, {})
c = C()
self.assertEqual(c.__dict__, {'a':1})
_testcapi.clear_managed_dict(c)
self.assertEqual(c.__dict__, {})


class TestPendingCalls(unittest.TestCase):

Expand Down
9 changes: 0 additions & 9 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6014,14 +6014,6 @@ settrace_to_record(PyObject *self, PyObject *list)
Py_RETURN_NONE;
}

static PyObject *
clear_managed_dict(PyObject *self, PyObject *obj)
{
_PyObject_ClearManagedDict(obj);
Py_RETURN_NONE;
}


static PyObject *negative_dictoffset(PyObject *, PyObject *);
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*);
Expand Down Expand Up @@ -6323,7 +6315,6 @@ static PyMethodDef TestMethods[] = {
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{"test_code_api", test_code_api, METH_NOARGS, NULL},
{"settrace_to_record", settrace_to_record, METH_O, NULL},
{"clear_managed_dict", clear_managed_dict, METH_O, NULL},
{NULL, NULL} /* sentinel */
};

Expand Down
29 changes: 0 additions & 29 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5583,35 +5583,6 @@ _PyObject_FreeInstanceAttributes(PyObject *self)
free_values(*values_ptr);
}

int
_PyObject_VisitManagedDict(PyObject *self, visitproc visit, void *arg)
{
PyTypeObject *tp = Py_TYPE(self);
if((tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0) {
return 0;
}
assert(tp->tp_dictoffset);
int err = _PyObject_VisitInstanceAttributes(self, visit, arg);
if (err) {
return err;
}
Py_VISIT(*_PyObject_ManagedDictPointer(self));
return 0;
}


void
_PyObject_ClearManagedDict(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
if((tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0) {
return;
}
_PyObject_FreeInstanceAttributes(self);
*_PyObject_ValuesPointer(self) = NULL;
Py_CLEAR(*_PyObject_ManagedDictPointer(self));
}

PyObject *
PyObject_GenericGetDict(PyObject *obj, void *context)
{
Expand Down

0 comments on commit 5dc94e7

Please sign in to comment.