Skip to content

Commit

Permalink
Redo how CinderX initialization handles getters/setters on callable t…
Browse files Browse the repository at this point in the history
…ypes

Summary:
The way this works today with 3.10 is that we statically initialize a copy of
the same tables that CPython uses internally.  We had to patch the runtime to
export the getters with `Cix_` prefixes so we could access them in CinderX.

The new way in this diff is to dynamically arrays and then copy the getset
tables into them on CinderX initialization, tacking on the extra
`__typed_signature__` getter.  The arrays are cleaned up by global destructors.

This drops the requirement that we have the `Cix_` wrappers.

The thing that I noticed while working on this is that we never actually reset
these tables when CinderX is unloaded, they stick around until the runtime
process itself dies.  This diff doesn't make that any better, but at least it
tries to document what needs to be modified to make that work.

Reviewed By: jbower-fb

Differential Revision: D59883485

fbshipit-source-id: 204b76465b927a9d78204bcc5346cc9cfb8cc91e
  • Loading branch information
Alex Malyshev authored and facebook-github-bot committed Jul 22, 2024
1 parent e73e6ed commit bb3aca2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 68 deletions.
20 changes: 0 additions & 20 deletions Include/cinder/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,6 @@ CiAPI_DATA(Ci_HookType_PyJIT_GenMaterializeFrame)
typedef PyObject *(*Ci_HookType_MaybeStrictModule_Dict)(PyObject *op);
CiAPI_DATA(Ci_HookType_MaybeStrictModule_Dict) Ci_hook_MaybeStrictModule_Dict;

CiAPI_FUNC(PyObject *)
Cix_method_get_doc(PyMethodDescrObject *descr, void *closure);

CiAPI_FUNC(PyObject *)
Cix_method_get_text_signature(PyMethodDescrObject *descr, void *closure);

CiAPI_FUNC(PyObject *) Cix_meth_get__doc__(PyCFunctionObject *m, void *closure);

CiAPI_FUNC(PyObject *)
Cix_meth_get__name__(PyCFunctionObject *m, void *closure);

CiAPI_FUNC(PyObject *)
Cix_meth_get__qualname__(PyCFunctionObject *m, void *closure);

CiAPI_FUNC(PyObject *)
Cix_meth_get__self__(PyCFunctionObject *m, void *closure);

CiAPI_FUNC(PyObject *)
Cix_meth_get__text_signature__(PyCFunctionObject *m, void *closure);

CiAPI_DATA(_PyFrameEvalFunction) Ci_hook_EvalFrame;

typedef PyFrameObject *(*Ci_HookType_PyJIT_GetFrame)(PyThreadState *tstate);
Expand Down
18 changes: 0 additions & 18 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1924,26 +1924,8 @@ PyTypeObject PyProperty_Type = {
PyObject_GC_Del, /* tp_free */
};

PyObject *
Cix_descr_get_qualname(PyDescrObject *descr, void *closure)
{
return descr_get_qualname(descr, closure);
}

funcptr
Cix_method_enter_call(PyThreadState *tstate, PyObject *func)
{
return method_enter_call(tstate, func);
}

PyObject *
Cix_method_get_doc(PyMethodDescrObject *descr, void *closure)
{
return method_get_doc(descr, closure);
}

PyObject *
Cix_method_get_text_signature(PyMethodDescrObject *descr, void *closure)
{
return method_get_text_signature(descr, closure);
}
30 changes: 0 additions & 30 deletions Objects/methodobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,33 +570,3 @@ funcptr
Cix_cfunction_enter_call(PyThreadState *tstate, PyObject *func) {
return cfunction_enter_call(tstate, func);
}

PyObject *
Cix_meth_get__doc__(PyCFunctionObject *m, void *closure)
{
return meth_get__doc__(m, closure);
}

PyObject *
Cix_meth_get__name__(PyCFunctionObject *m, void *closure)
{
return meth_get__name__(m, closure);
}

PyObject *
Cix_meth_get__qualname__(PyCFunctionObject *m, void *closure)
{
return meth_get__qualname__(m, closure);
}

PyObject *
Cix_meth_get__self__(PyCFunctionObject *m, void *closure)
{
return meth_get__self__(m, closure);
}

PyObject *
Cix_meth_get__text_signature__(PyCFunctionObject *m, void *closure)
{
return meth_get__text_signature__(m, closure);
}

0 comments on commit bb3aca2

Please sign in to comment.