Skip to content

Commit 299de38

Browse files
authored
gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242)
1 parent dd15a2e commit 299de38

File tree

9 files changed

+54
-32
lines changed

9 files changed

+54
-32
lines changed

Include/internal/pycore_call.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ _PyObject_CallNoArgs(PyObject *func) {
186186
}
187187

188188

189-
extern PyObject *const *
189+
PyAPI_FUNC(PyObject *const *)
190190
_PyStack_UnpackDict(PyThreadState *tstate,
191191
PyObject *const *args, Py_ssize_t nargs,
192192
PyObject *kwargs, PyObject **p_kwnames);
@@ -196,7 +196,7 @@ extern void _PyStack_UnpackDict_Free(
196196
Py_ssize_t nargs,
197197
PyObject *kwnames);
198198

199-
extern void _PyStack_UnpackDict_FreeNoDecRef(
199+
PyAPI_FUNC(void) _PyStack_UnpackDict_FreeNoDecRef(
200200
PyObject *const *stack,
201201
PyObject *kwnames);
202202

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ PyAPI_FUNC(int) _Py_CheckRecursiveCall(
226226
PyThreadState *tstate,
227227
const char *where);
228228

229-
int _Py_CheckRecursiveCallPy(
229+
PyAPI_FUNC(int) _Py_CheckRecursiveCallPy(
230230
PyThreadState *tstate);
231231

232232
static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,

Include/internal/pycore_code.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ extern PyObject* _PyCode_GetFreevars(PyCodeObject *);
262262
extern PyObject* _PyCode_GetCode(PyCodeObject *);
263263

264264
/** API for initializing the line number tables. */
265-
extern int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
265+
PyAPI_FUNC(int) _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
266266

267267
/** Out of process API for initializing the location table. */
268268
extern void _PyLineTable_InitAddressRange(
@@ -272,7 +272,7 @@ extern void _PyLineTable_InitAddressRange(
272272
PyCodeAddressRange *range);
273273

274274
/** API for traversing the line number table. */
275-
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
275+
PyAPI_FUNC(int) _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
276276
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
277277
// This is used in dump_frame() in traceback.c without an attached tstate.
278278
extern int _PyCode_Addr2LineNoTstate(PyCodeObject *co, int addr);
@@ -293,33 +293,34 @@ extern void _PyCode_Clear_Executors(PyCodeObject *code);
293293
#define ENABLE_SPECIALIZATION_FT ENABLE_SPECIALIZATION
294294
#endif
295295

296-
/* Specialization functions */
296+
/* Specialization functions, these are exported only for other re-generated
297+
* interpreters to call */
297298

298-
extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef cls,
299+
PyAPI_FUNC(void) _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef cls,
299300
_Py_CODEUNIT *instr, int load_method);
300-
extern void _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
301+
PyAPI_FUNC(void) _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
301302
PyObject *name);
302-
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
303+
PyAPI_FUNC(void) _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
303304
PyObject *name);
304-
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
305+
PyAPI_FUNC(void) _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
305306
_Py_CODEUNIT *instr, PyObject *name);
306-
extern void _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
307+
PyAPI_FUNC(void) _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
307308
_Py_CODEUNIT *instr);
308-
extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
309+
PyAPI_FUNC(void) _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
309310
int nargs);
310-
extern void _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
311+
PyAPI_FUNC(void) _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
311312
int nargs);
312-
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
313+
PyAPI_FUNC(void) _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
313314
int oparg, _PyStackRef *locals);
314-
extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
315+
PyAPI_FUNC(void) _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
315316
_Py_CODEUNIT *instr, int oparg);
316-
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
317+
PyAPI_FUNC(void) _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
317318
int oparg);
318-
extern void _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT *instr, int oparg);
319-
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
320-
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
321-
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
322-
extern void _Py_GatherStats_GetIter(_PyStackRef iterable);
319+
PyAPI_FUNC(void) _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT *instr, int oparg);
320+
PyAPI_FUNC(void) _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
321+
PyAPI_FUNC(void) _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
322+
PyAPI_FUNC(void) _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
323+
PyAPI_FUNC(void) _Py_GatherStats_GetIter(_PyStackRef iterable);
323324

324325
// Utility functions for reading/writing 32/64-bit values in the inline caches.
325326
// Great care should be taken to ensure that these functions remain correct and
@@ -514,7 +515,7 @@ typedef struct {
514515

515516
#define COMPARISON_NOT_EQUALS (COMPARISON_UNORDERED | COMPARISON_LESS_THAN | COMPARISON_GREATER_THAN)
516517

517-
extern int _Py_Instrument(PyCodeObject *co, PyInterpreterState *interp);
518+
PyAPI_FUNC(int) _Py_Instrument(PyCodeObject *co, PyInterpreterState *interp);
518519

519520
extern _Py_CODEUNIT _Py_GetBaseCodeUnit(PyCodeObject *code, int offset);
520521

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ PyAPI_FUNC(int) _PyDict_SetItem_KnownHash_LockHeld(PyDictObject *mp, PyObject *k
144144
PyAPI_FUNC(int) _PyDict_GetItemRef_KnownHash_LockHeld(PyDictObject *op, PyObject *key, Py_hash_t hash, PyObject **result);
145145
extern int _PyDict_GetItemRef_KnownHash(PyDictObject *op, PyObject *key, Py_hash_t hash, PyObject **result);
146146
extern int _PyDict_GetItemRef_Unicode_LockHeld(PyDictObject *op, PyObject *key, PyObject **result);
147-
extern int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject *obj, PyObject **dictptr, PyObject *name, PyObject *value);
147+
PyAPI_FUNC(int) _PyObjectDict_SetItem(PyTypeObject *tp, PyObject *obj, PyObject **dictptr, PyObject *name, PyObject *value);
148148

149149
extern int _PyDict_Pop_KnownHash(
150150
PyDictObject *dict,

Include/internal/pycore_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
extern PyObject* _PyFunction_Vectorcall(
11+
PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall(
1212
PyObject *func,
1313
PyObject *const *stack,
1414
size_t nargsf,

Include/internal/pycore_genobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
3131
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
3232

3333
PyAPI_FUNC(PyObject *)_PyCoro_GetAwaitableIter(PyObject *o);
34-
extern PyObject *_PyAsyncGenValueWrapperNew(PyThreadState *state, PyObject *);
34+
PyAPI_FUNC(PyObject *)_PyAsyncGenValueWrapperNew(PyThreadState *state, PyObject *);
3535

3636
extern PyTypeObject _PyCoroWrapper_Type;
3737
extern PyTypeObject _PyAsyncGenWrappedValue_Type;

Include/internal/pycore_instruments.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,34 @@ int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events);
3333
int _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet events);
3434
int _PyMonitoring_GetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet *events);
3535

36-
extern int
36+
37+
// these are exported only for other re-generated interpreters to call
38+
PyAPI_FUNC(int)
3739
_Py_call_instrumentation(PyThreadState *tstate, int event,
3840
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
3941

40-
extern int
42+
PyAPI_FUNC(int)
4143
_Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
4244
_Py_CODEUNIT *instr, _Py_CODEUNIT *prev);
4345

44-
extern int
46+
PyAPI_FUNC(int)
4547
_Py_call_instrumentation_instruction(
4648
PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);
4749

48-
_Py_CODEUNIT *
50+
PyAPI_FUNC(_Py_CODEUNIT *)
4951
_Py_call_instrumentation_jump(
5052
_Py_CODEUNIT *instr, PyThreadState *tstate, int event,
5153
_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest);
5254

53-
extern int
55+
PyAPI_FUNC(int)
5456
_Py_call_instrumentation_arg(PyThreadState *tstate, int event,
5557
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);
5658

57-
extern int
59+
PyAPI_FUNC(int)
5860
_Py_call_instrumentation_2args(PyThreadState *tstate, int event,
5961
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
6062

61-
extern void
63+
PyAPI_FUNC(void)
6264
_Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
6365
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
6466

Include/internal/pycore_typeobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ _PyType_GetModuleState(PyTypeObject *type)
9090
// function
9191
PyAPI_FUNC(PyObject *) _PyType_GetDict(PyTypeObject *);
9292

93+
PyAPI_FUNC(PyObject *) _PyType_LookupSubclasses(PyTypeObject *);
94+
PyAPI_FUNC(PyObject *) _PyType_InitSubclasses(PyTypeObject *);
95+
9396
extern PyObject * _PyType_GetBases(PyTypeObject *type);
9497
extern PyObject * _PyType_GetMRO(PyTypeObject *type);
9598
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);

Objects/typeobject.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,22 @@ lookup_tp_subclasses(PyTypeObject *self)
752752
return (PyObject *)self->tp_subclasses;
753753
}
754754

755+
PyObject *
756+
_PyType_LookupSubclasses(PyTypeObject *self)
757+
{
758+
return lookup_tp_subclasses(self);
759+
}
760+
761+
PyObject *
762+
_PyType_InitSubclasses(PyTypeObject *self)
763+
{
764+
PyObject *existing = lookup_tp_subclasses(self);
765+
if (existing != NULL) {
766+
return existing;
767+
}
768+
return init_tp_subclasses(self);
769+
}
770+
755771
int
756772
_PyType_HasSubclasses(PyTypeObject *self)
757773
{

0 commit comments

Comments
 (0)