Skip to content

Commit

Permalink
Extract tp_getset initialization from methodobject.c
Browse files Browse the repository at this point in the history
Reviewed By: carljm

Differential Revision: D50916669

fbshipit-source-id: 047be0a1fee87442eafd4f4d41d4d391b18f54be
  • Loading branch information
Johnston Jiaa authored and facebook-github-bot committed Nov 28, 2023
1 parent fc53676 commit 9de5040
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CinderX/_cinderx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ static PyGetSetDef Ci_method_getset[] = {
{},
};

static PyGetSetDef Ci_meth_getset[] = {
{.name = "__doc__", .get = (getter)Cix_meth_get__doc__, .set = nullptr, .doc = nullptr, .closure = nullptr},
{.name = "__name__", .get = (getter)Cix_meth_get__name__, .set = nullptr, .doc = nullptr, .closure = nullptr},
{.name = "__qualname__", .get = (getter)Cix_meth_get__qualname__, .set = nullptr, .doc = nullptr, .closure = nullptr},
{.name = "__text_signature__", .get = (getter)Cix_meth_get__text_signature__, .set = nullptr, .doc = nullptr, .closure = nullptr},
{.name = "__typed_signature__", .get = (getter)Ci_meth_get__typed_signature__, .set = nullptr, .doc = nullptr, .closure = nullptr},
{},
};

static int init_already_existing_types() {
PyUnstable_GC_VisitObjects([](PyObject* obj, void*) {
if (PyType_Check(obj) && PyType_HasFeature((PyTypeObject*)obj, Py_TPFLAGS_READY)) {
Expand All @@ -65,6 +74,9 @@ static int init_already_existing_types() {
if (override_tp_getset(&PyClassMethodDescr_Type, Ci_method_getset) < 0) {
return -1;
}
if (override_tp_getset(&PyCFunction_Type, Ci_meth_getset) < 0) {
return -1;
}

return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions Objects/methodobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#ifdef ENABLE_CINDERX
#include "StaticPython/classloader.h"
#include "StaticPython/methodobject_vectorcall.h"
#endif

/* undefine macro trampoline to PyCFunction_NewEx */
Expand Down Expand Up @@ -435,9 +434,6 @@ static PyGetSetDef meth_getsets [] = {
{"__qualname__", (getter)meth_get__qualname__, NULL, NULL},
{"__self__", (getter)meth_get__self__, NULL, NULL},
{"__text_signature__", (getter)meth_get__text_signature__, NULL, NULL},
#ifdef ENABLE_CINDERX
{"__typed_signature__", (getter)Ci_meth_get__typed_signature__, NULL, NULL},
#endif
{0}
};

Expand Down

0 comments on commit 9de5040

Please sign in to comment.