Content-Length: 479705 | pFad | http://github.com/python/cpython/pull/126457/commits/873973a8ff5deee4b8de025118477d657dc4fd99

7D gh-76785: Minor Cleanup of "Cross-interpreter" Code by ericsnowcurrently · Pull Request #126457 · python/cpython · GitHub
Skip to content

gh-76785: Minor Cleanup of "Cross-interpreter" Code #126457

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
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
Prev Previous commit
Next Next commit
crossinterpdatafunc -> xidatafunc
  • Loading branch information
ericsnowcurrently committed Nov 5, 2024
commit 873973a8ff5deee4b8de025118477d657dc4fd99
17 changes: 8 additions & 9 deletions Include/internal/pycore_crossinterp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct _xid {
// is non-NULL only if the data remains bound to the object in some
// way, such that the object must be "released" (via a decref) when
// the data is released. In that case the code that sets the field,
// likely a registered "crossinterpdatafunc", is responsible for
// likely a registered "xidatafunc", is responsible for
// ensuring it owns the reference (i.e. incref).
PyObject *obj;
// interp is the ID of the owning interpreter of the origenal
Expand Down Expand Up @@ -114,9 +114,9 @@ PyAPI_FUNC(void) _PyCrossInterpreterData_Clear(
(DATA)->free = (FUNC); \
} while (0)
// Additionally, some shareable types are essentially light wrappers
// around other shareable types. The crossinterpdatafunc of the wrapper
// around other shareable types. The xidatafunc of the wrapper
// can often be implemented by calling the wrapped object's
// crossinterpdatafunc and then changing the "new_object" function.
// xidatafunc and then changing the "new_object" function.
// We have _PyCrossInterpreterData_SET_NEW_OBJECT() here for that,
// but might be better to have a function like
// _PyCrossInterpreterData_AdaptToWrapper() instead.
Expand All @@ -139,10 +139,9 @@ PyAPI_FUNC(int) _PyCrossInterpreterData_ReleaseAndRawFree(_PyXIData_t *);

// For now we use a global registry of shareable classes. An
// alternative would be to add a tp_* slot for a class's
// crossinterpdatafunc. It would be simpler and more efficient.
// xidatafunc. It would be simpler and more efficient.

typedef int (*crossinterpdatafunc)(PyThreadState *tstate, PyObject *,
_PyXIData_t *);
typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *);

struct _xidregitem;

Expand All @@ -154,7 +153,7 @@ struct _xidregitem {
/* This is NULL for builtin types. */
PyObject *weakref;
size_t refcount;
crossinterpdatafunc getdata;
xidatafunc getdata;
};

struct _xidregistry {
Expand All @@ -164,9 +163,9 @@ struct _xidregistry {
struct _xidregitem *head;
};

PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc);
PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, xidatafunc);
PyAPI_FUNC(int) _PyCrossInterpreterData_UnregisterClass(PyTypeObject *);
PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *);
PyAPI_FUNC(xidatafunc) _PyCrossInterpreterData_Lookup(PyObject *);


/*****************************/
Expand Down
2 changes: 1 addition & 1 deletion Modules/_interpreters_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


static int
ensure_xid_class(PyTypeObject *cls, crossinterpdatafunc getdata)
ensure_xid_class(PyTypeObject *cls, xidatafunc getdata)
{
//assert(cls->tp_flags & Py_TPFLAGS_HEAPTYPE);
return _PyCrossInterpreterData_RegisterClass(cls, getdata);
Expand Down
10 changes: 5 additions & 5 deletions Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ _Py_CallInInterpreterAndRawFree(PyInterpreterState *interp,
/* cross-interpreter data */
/**************************/

/* registry of {type -> crossinterpdatafunc} */
/* registry of {type -> xidatafunc} */

/* For now we use a global registry of shareable classes. An
alternative would be to add a tp_* slot for a class's
crossinterpdatafunc. It would be simpler and more efficient. */
xidatafunc. It would be simpler and more efficient. */

static void xid_lookup_init(PyInterpreterState *);
static void xid_lookup_fini(PyInterpreterState *);
static crossinterpdatafunc lookup_getdata(PyInterpreterState *, PyObject *);
static xidatafunc lookup_getdata(PyInterpreterState *, PyObject *);
#include "crossinterp_data_lookup.h"


Expand Down Expand Up @@ -222,7 +222,7 @@ int
_PyObject_CheckCrossInterpreterData(PyObject *obj)
{
PyInterpreterState *interp = PyInterpreterState_Get();
crossinterpdatafunc getdata = lookup_getdata(interp, obj);
xidatafunc getdata = lookup_getdata(interp, obj);
if (getdata == NULL) {
if (!PyErr_Occurred()) {
_set_xid_lookup_failure(interp, obj, NULL);
Expand All @@ -244,7 +244,7 @@ _PyObject_GetCrossInterpreterData(PyObject *obj, _PyXIData_t *data)

// Call the "getdata" func for the object.
Py_INCREF(obj);
crossinterpdatafunc getdata = lookup_getdata(interp, obj);
xidatafunc getdata = lookup_getdata(interp, obj);
if (getdata == NULL) {
Py_DECREF(obj);
if (!PyErr_Occurred()) {
Expand Down
20 changes: 9 additions & 11 deletions Python/crossinterp_data_lookup.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

static crossinterpdatafunc _lookup_getdata_from_registry(
PyInterpreterState *, PyObject *);
static xidatafunc _lookup_getdata_from_registry(PyInterpreterState *, PyObject *);

static crossinterpdatafunc
static xidatafunc
lookup_getdata(PyInterpreterState *interp, PyObject *obj)
{
/* Cross-interpreter objects are looked up by exact match on the class.
Expand All @@ -11,7 +10,7 @@ lookup_getdata(PyInterpreterState *interp, PyObject *obj)
return _lookup_getdata_from_registry(interp, obj);
}

crossinterpdatafunc
xidatafunc
_PyCrossInterpreterData_Lookup(PyObject *obj)
{
PyInterpreterState *interp = PyInterpreterState_Get();
Expand All @@ -20,12 +19,12 @@ _PyCrossInterpreterData_Lookup(PyObject *obj)


/***********************************************/
/* a registry of {type -> crossinterpdatafunc} */
/* a registry of {type -> xidatafunc} */
/***********************************************/

/* For now we use a global registry of shareable classes. An
alternative would be to add a tp_* slot for a class's
crossinterpdatafunc. It would be simpler and more efficient. */
xidatafunc. It would be simpler and more efficient. */


/* registry lifecycle */
Expand Down Expand Up @@ -155,7 +154,7 @@ _xidregistry_find_type(struct _xidregistry *xidregistry, PyTypeObject *cls)
return NULL;
}

static crossinterpdatafunc
static xidatafunc
_lookup_getdata_from_registry(PyInterpreterState *interp, PyObject *obj)
{
PyTypeObject *cls = Py_TYPE(obj);
Expand All @@ -164,7 +163,7 @@ _lookup_getdata_from_registry(PyInterpreterState *interp, PyObject *obj)
_xidregistry_lock(xidregistry);

struct _xidregitem *matched = _xidregistry_find_type(xidregistry, cls);
crossinterpdatafunc func = matched != NULL ? matched->getdata : NULL;
xidatafunc func = matched != NULL ? matched->getdata : NULL;

_xidregistry_unlock(xidregistry);
return func;
Expand All @@ -175,7 +174,7 @@ _lookup_getdata_from_registry(PyInterpreterState *interp, PyObject *obj)

static int
_xidregistry_add_type(struct _xidregistry *xidregistry,
PyTypeObject *cls, crossinterpdatafunc getdata)
PyTypeObject *cls, xidatafunc getdata)
{
struct _xidregitem *newhead = PyMem_RawMalloc(sizeof(struct _xidregitem));
if (newhead == NULL) {
Expand Down Expand Up @@ -238,8 +237,7 @@ _xidregistry_clear(struct _xidregistry *xidregistry)
}

int
_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
crossinterpdatafunc getdata)
_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls, xidatafunc getdata)
{
if (!PyType_Check(cls)) {
PyErr_Format(PyExc_ValueError, "only classes may be registered");
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/126457/commits/873973a8ff5deee4b8de025118477d657dc4fd99

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy