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
Prev Previous commit
Next Next commit
interp_utils -> crossinterp
  • Loading branch information
ericsnowcurrently committed Oct 30, 2023
commit 7870af1502ec8c16196b2c8fe81e593ecb79317e
2 changes: 1 addition & 1 deletion Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#include "iterobject.h"
#include "cpython/initconfig.h"
#include "pystate.h"
#include "interp_utils.h"
#include "crossinterp.h"
#include "cpython/genobject.h"
#include "descrobject.h"
#include "genericaliasobject.h"
Expand Down
80 changes: 80 additions & 0 deletions Include/cpython/crossinterp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef Py_CPYTHON_CROSSINTERP_H
# error "this header file must not be included directly"
#endif


/* cross-interpreter data */

// _PyCrossInterpreterData is similar to Py_buffer as an effectively
// opaque struct that holds data outside the object machinery. This
// is necessary to pass safely between interpreters in the same process.
typedef struct _xid _PyCrossInterpreterData;

typedef PyObject *(*xid_newobjectfunc)(_PyCrossInterpreterData *);
typedef void (*xid_freefunc)(void *);

struct _xid {
// data is the cross-interpreter-safe derivation of a Python object
// (see _PyObject_GetCrossInterpreterData). It will be NULL if the
// new_object func (below) encodes the data.
void *data;
// obj is the Python object from which the data was derived. This
// 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
// ensuring it owns the reference (i.e. incref).
PyObject *obj;
// interp is the ID of the owning interpreter of the original
// object. It corresponds to the active interpreter when
// _PyObject_GetCrossInterpreterData() was called. This should only
// be set by the cross-interpreter machinery.
//
// We use the ID rather than the PyInterpreterState to avoid issues
// with deleted interpreters. Note that IDs are never re-used, so
// each one will always correspond to a specific interpreter
// (whether still alive or not).
int64_t interpid;
// new_object is a function that returns a new object in the current
// interpreter given the data. The resulting object (a new
// reference) will be equivalent to the original object. This field
// is required.
xid_newobjectfunc new_object;
// free is called when the data is released. If it is NULL then
// nothing will be done to free the data. For some types this is
// okay (e.g. bytes) and for those types this field should be set
// to NULL. However, for most the data was allocated just for
// cross-interpreter use, so it must be freed when
// _PyCrossInterpreterData_Release is called or the memory will
// leak. In that case, at the very least this field should be set
// to PyMem_RawFree (the default if not explicitly set to NULL).
// The call will happen with the original interpreter activated.
xid_freefunc free;
};

PyAPI_FUNC(void) _PyCrossInterpreterData_Init(
_PyCrossInterpreterData *data,
PyInterpreterState *interp, void *shared, PyObject *obj,
xid_newobjectfunc new_object);
PyAPI_FUNC(int) _PyCrossInterpreterData_InitWithSize(
_PyCrossInterpreterData *,
PyInterpreterState *interp, const size_t, PyObject *,
xid_newobjectfunc);
PyAPI_FUNC(void) _PyCrossInterpreterData_Clear(
PyInterpreterState *, _PyCrossInterpreterData *);

PyAPI_FUNC(int) _PyObject_GetCrossInterpreterData(PyObject *, _PyCrossInterpreterData *);
PyAPI_FUNC(PyObject *) _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *);
PyAPI_FUNC(int) _PyCrossInterpreterData_Release(_PyCrossInterpreterData *);
PyAPI_FUNC(int) _PyCrossInterpreterData_ReleaseAndRawFree(_PyCrossInterpreterData *);

PyAPI_FUNC(int) _PyObject_CheckCrossInterpreterData(PyObject *);

/* cross-interpreter data registry */

typedef int (*crossinterpdatafunc)(PyThreadState *tstate, PyObject *,
_PyCrossInterpreterData *);

PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc);
PyAPI_FUNC(int) _PyCrossInterpreterData_UnregisterClass(PyTypeObject *);
PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *);
2 changes: 1 addition & 1 deletion Include/cpython/interp_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef Py_CPYTHON_INTERP_UTILS_H
#ifndef Py_CPYTHON_CROSSINTERP_H
# error "this header file must not be included directly"
#endif

Expand Down
16 changes: 16 additions & 0 deletions Include/crossinterp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef Py_CROSSINTERP_H
#define Py_CROSSINTERP_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_LIMITED_API
# define Py_CPYTHON_CROSSINTERP_H
# include "cpython/crossinterp.h"
# undef Py_CPYTHON_CROSSINTERP_H
#endif

#ifdef __cplusplus
}
#endif
#endif /* !Py_CROSSINTERP_H */
16 changes: 0 additions & 16 deletions Include/interp_utils.h

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ PYTHON_OBJS= \
Python/importdl.o \
Python/initconfig.o \
Python/instrumentation.o \
Python/interp_utils.o \
Python/crossinterp.o \
Python/intrinsics.o \
Python/legacy_tracing.o \
Python/lock.o \
Expand Down Expand Up @@ -1676,7 +1676,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/frameobject.h \
$(srcdir)/Include/import.h \
$(srcdir)/Include/interpreteridobject.h \
$(srcdir)/Include/interp_utils.h \
$(srcdir)/Include/crossinterp.h \
$(srcdir)/Include/intrcheck.h \
$(srcdir)/Include/iterobject.h \
$(srcdir)/Include/listobject.h \
Expand Down Expand Up @@ -1748,7 +1748,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/cpython/import.h \
$(srcdir)/Include/cpython/initconfig.h \
$(srcdir)/Include/cpython/interpreteridobject.h \
$(srcdir)/Include/cpython/interp_utils.h \
$(srcdir)/Include/cpython/crossinterp.h \
$(srcdir)/Include/cpython/listobject.h \
$(srcdir)/Include/cpython/longintrepr.h \
$(srcdir)/Include/cpython/longobject.h \
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/_freeze_module.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<ClCompile Include="..\Python\instrumentation.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\interp_utils.c">
<ClCompile Include="..\Python\crossinterp.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\legacy_tracing.c">
Expand Down
6 changes: 3 additions & 3 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<ClInclude Include="..\Include\cpython\genobject.h" />
<ClInclude Include="..\Include\cpython\import.h" />
<ClInclude Include="..\Include\cpython\initconfig.h" />
<ClInclude Include="..\Include\cpython\interp_utils.h" />
<ClInclude Include="..\Include\cpython\crossinterp.h" />
<ClInclude Include="..\Include\cpython\interpreteridobject.h" />
<ClInclude Include="..\Include\cpython\listobject.h" />
<ClInclude Include="..\Include\cpython\longintrepr.h" />
Expand Down Expand Up @@ -293,7 +293,7 @@
<ClInclude Include="..\Include\internal\pycore_uops.h" />
<ClInclude Include="..\Include\internal\pycore_warnings.h" />
<ClInclude Include="..\Include\internal\pycore_weakref.h" />
<ClInclude Include="..\Include\interp_utils.h" />
<ClInclude Include="..\Include\crossinterp.h" />
<ClInclude Include="..\Include\interpreteridobject.h" />
<ClInclude Include="..\Include\intrcheck.h" />
<ClInclude Include="..\Include\iterobject.h" />
Expand Down Expand Up @@ -585,7 +585,7 @@
<ClCompile Include="..\Python\import.c" />
<ClCompile Include="..\Python\importdl.c" />
<ClCompile Include="..\Python\initconfig.c" />
<ClCompile Include="..\Python\interp_utils.c" />
<ClCompile Include="..\Python\crossinterp.c" />
<ClCompile Include="..\Python\intrinsics.c" />
<ClCompile Include="..\Python\instrumentation.c" />
<ClCompile Include="..\Python\legacy_tracing.c" />
Expand Down
6 changes: 3 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
<ClInclude Include="..\Include\pyhash.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\interp_utils.h">
<ClInclude Include="..\Include\crossinterp.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\interpreteridobject.h">
Expand Down Expand Up @@ -492,7 +492,7 @@
<ClInclude Include="..\Include\cpython\genobject.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\interp_utils.h">
<ClInclude Include="..\Include\cpython\crossinterp.h">
<Filter>Include\cpython</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\interpreteridobject.h">
Expand Down Expand Up @@ -1352,7 +1352,7 @@
<ClCompile Include="..\Python\instrumentation.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\interp_utils.c">
<ClCompile Include="..\Python\crossinterp.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\legacy_tracing.c">
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
return _PyStatus_OK();
}

// This is defined in interp_utils.c.
// This is defined in crossinterp.c (for now).
void _xidregistry_clear(struct _xidregistry *);

void
Expand Down