gh-126703: Add freelist for PyMethodObject by eendebakpt · Pull Request #128594 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Add freelist for PyMethodObject
  • Loading branch information
eendebakpt committed Jan 7, 2025
commit 512efff0dff4c1de5ce4b1eae75f3dffadfd7c93
2 changes: 2 additions & 0 deletions Include/internal/pycore_freelist_state.h
11 changes: 8 additions & 3 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_VectorcallTstate()
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
#include "pycore_freelist.h"
#include "pycore_object.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
Expand Down Expand Up @@ -112,9 +113,12 @@ PyMethod_New(PyObject *func, PyObject *self)
PyErr_BadInternalCall();
return NULL;
}
PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
PyMethodObject *im = _Py_FREELIST_POP(PyMethodObject, pymethodobjects);
if (im == NULL) {
return NULL;
im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
if (im == NULL) {
return NULL;
}
}
im->im_weakreflist = NULL;
im->im_func = Py_NewRef(func);
Expand Down Expand Up @@ -245,7 +249,8 @@ method_dealloc(PyObject *self)
PyObject_ClearWeakRefs((PyObject *)im);
Py_DECREF(im->im_func);
Py_XDECREF(im->im_self);
PyObject_GC_Del(im);
assert(Py_IS_TYPE(self, &PyMethod_Type));
_Py_FREELIST_FREE(pymethodobjects, (PyObject *)im, PyObject_GC_Del);
}

static PyObject *
Expand Down
1 change: 1 addition & 0 deletions Objects/object.c