8000 bpo-42972: Fully support GC for hashlib heap types (GH-26374) by erlend-aasland · Pull Request #26374 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42972: Fully support GC for hashlib heap types (GH-26374) #26374

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
May 27, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
bpo-42972: Fully support GC for md5 heap types
  • Loading branch information
Erlend E. Aasland committed May 25, 2021
commit 49226ddc36de6a03172dc8910ecbc4e0faab656c
17 changes: 14 additions & 3 deletions Modules/md5module.c
BE82
Original file line numberDiff line number Diff line change
Expand Up @@ -333,16 +333,25 @@ md5_get_state(PyObject *module)
static MD5object *
newMD5object(MD5State * st)
{
return (MD5object *)PyObject_New(MD5object, st->md5_type);
MD5object *md5 = (MD5object *)PyObject_GC_New(MD5object, st->md5_type);
PyObject_GC_Track(md5);
return md5;
}

/* Internal methods for a hash object */
static int
MD5_traverse(PyObject *ptr, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(ptr));
return 0;
}

static void
MD5_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Free(ptr);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -478,13 +487,15 @@ static PyType_Slot md5_type_slots[] = {
{Py_tp_dealloc, MD5_dealloc},
{Py_tp_methods, MD5_methods},
{Py_tp_getset, MD5_getseters},
{Py_tp_traverse, MD5_traverse},
{0,0}
};

static PyType_Spec md5_type_spec = {
.name = "_md5.md5",
.basicsize = sizeof(MD5object),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
.slots = md5_type_slots
};

Expand Down
0