gh-132781: Cleanup Code Related to NotShareableError (gh-132782)

The following are added to the internal C-API:

* _PyErr_FormatV()
* _PyErr_SetModuleNotFoundError()
* _PyXIData_GetNotShareableErrorType()
* _PyXIData_FormatNotShareableError()

We also drop _PyXIData_lookup_context_t and _PyXIData_GetLookupContext().
This commit is contained in:
Eric Snow 2025-04-25 14:43:38 -06:00 committed by GitHub
parent 4c20f46fa0
commit cd9536a087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 322 additions and 177 deletions

View file

@ -97,26 +97,22 @@ PyAPI_FUNC(void) _PyXIData_Free(_PyXIData_t *data);
typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *);
typedef struct _xid_lookup_state _PyXIData_lookup_t;
typedef struct {
_PyXIData_lookup_t *global;
_PyXIData_lookup_t *local;
PyObject *PyExc_NotShareableError;
} _PyXIData_lookup_context_t;
PyAPI_FUNC(int) _PyXIData_GetLookupContext(
PyInterpreterState *,
_PyXIData_lookup_context_t *);
PyAPI_FUNC(PyObject *) _PyXIData_GetNotShareableErrorType(PyThreadState *);
PyAPI_FUNC(void) _PyXIData_SetNotShareableError(PyThreadState *, const char *);
PyAPI_FUNC(void) _PyXIData_FormatNotShareableError(
PyThreadState *,
const char *,
...);
PyAPI_FUNC(xidatafunc) _PyXIData_Lookup(
_PyXIData_lookup_context_t *,
PyThreadState *,
PyObject *);
PyAPI_FUNC(int) _PyObject_CheckXIData(
_PyXIData_lookup_context_t *,
PyThreadState *,
PyObject *);
PyAPI_FUNC(int) _PyObject_GetXIData(
_PyXIData_lookup_context_t *,
PyThreadState *,
PyObject *,
_PyXIData_t *);
@ -171,6 +167,8 @@ PyAPI_FUNC(void) _PyXIData_Clear( PyInterpreterState *, _PyXIData_t *);
/* runtime state & lifecycle */
/*****************************/
typedef struct _xid_lookup_state _PyXIData_lookup_t;
typedef struct {
// builtin types
_PyXIData_lookup_t data_lookup;

View file

@ -28,11 +28,11 @@ typedef struct {
} _PyXIData_registry_t;
PyAPI_FUNC(int) _PyXIData_RegisterClass(
_PyXIData_lookup_context_t *,
PyThreadState *,
PyTypeObject *,
xidatafunc);
PyAPI_FUNC(int) _PyXIData_UnregisterClass(
_PyXIData_lookup_context_t *,
PyThreadState *,
PyTypeObject *);
struct _xid_lookup_state {

View file

@ -60,6 +60,7 @@ extern PyObject* _PyErr_SetImportErrorWithNameFrom(
PyObject *,
PyObject *,
PyObject *);
extern int _PyErr_SetModuleNotFoundError(PyObject *name);
/* runtime lifecycle */
@ -113,6 +114,7 @@ extern void _PyErr_SetObject(
PyObject *value);
extern void _PyErr_ChainStackItem(void);
extern void _PyErr_ChainExceptions1Tstate(PyThreadState *, PyObject *);
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
@ -148,6 +150,12 @@ PyAPI_FUNC(PyObject*) _PyErr_Format(
const char *format,
...);
PyAPI_FUNC(PyObject*) _PyErr_FormatV(
PyThreadState *tstate,
PyObject *exception,
const char *format,
va_list vargs);
extern void _PyErr_NormalizeException(
PyThreadState *tstate,
PyObject **exc,