Skip to content

Commit b77ccaf

Browse files
committed
gh-149196: Hide executor array layout from ABI tools
1 parent c92e2fd commit b77ccaf

12 files changed

Lines changed: 56 additions & 31 deletions

File tree

Include/cpython/code.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ typedef struct {
1515
PyObject *_co_freevars;
1616
} _PyCoCached;
1717

18-
typedef struct {
19-
int size;
20-
int capacity;
21-
struct _PyExecutorObject *executors[1];
22-
} _PyExecutorArray;
18+
typedef struct _PyExecutorArray _PyExecutorArray;
2319

2420

2521
#ifdef Py_GIL_DISABLED

Include/internal/pycore_interp_structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ struct _Py_unique_id_pool {
819819

820820
#endif
821821

822+
struct _PyExecutorObject;
823+
822824
typedef _Py_CODEUNIT *(*_PyJitEntryFuncPtr)(struct _PyExecutorObject *exec, _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate);
823825

824826
#define _PyInterpreterGuard_GUARDS_NOT_ALLOWED UINTPTR_MAX

Include/internal/pycore_optimizer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ typedef struct _PyExecutorObject {
202202
_PyExitData exits[1];
203203
} _PyExecutorObject;
204204

205+
typedef struct _PyExecutorArrayInternal {
206+
int size;
207+
int capacity;
208+
_PyExecutorObject *executors[1];
209+
} _PyExecutorArrayInternal;
210+
211+
static inline _PyExecutorArrayInternal *
212+
_PyExecutorArray_CAST(_PyExecutorArray *executors)
213+
{
214+
return (_PyExecutorArrayInternal *)executors;
215+
}
216+
217+
static inline int
218+
_PyExecutorArray_SIZE(_PyExecutorArray *executors)
219+
{
220+
return _PyExecutorArray_CAST(executors)->size;
221+
}
222+
223+
static inline _PyExecutorObject **
224+
_PyExecutorArray_EXECUTORS(_PyExecutorArray *executors)
225+
{
226+
return _PyExecutorArray_CAST(executors)->executors;
227+
}
228+
205229
// Export for '_opcode' shared extension (JIT compiler).
206230
PyAPI_FUNC(_PyExecutorObject*) _Py_GetExecutor(PyCodeObject *code, int offset);
207231

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hide internal Tier 2 executor implementation details from ABI analysis tools
2+
by making the executor array referenced by :c:type:`PyCodeObject` opaque.

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/codeobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,10 +2181,10 @@ static void
21812181
clear_executors(PyCodeObject *co)
21822182
{
21832183
assert(co->co_executors);
2184-
for (int i = 0; i < co->co_executors->size; i++) {
2185-
if (co->co_executors->executors[i]) {
2186-
_Py_ExecutorDetach(co->co_executors->executors[i]);
2187-
assert(co->co_executors->executors[i] == NULL);
2184+
for (int i = 0; i < _PyExecutorArray_SIZE(co->co_executors); i++) {
2185+
if (_PyExecutorArray_EXECUTORS(co->co_executors)[i]) {
2186+
_Py_ExecutorDetach(_PyExecutorArray_EXECUTORS(co->co_executors)[i]);
2187+
assert(_PyExecutorArray_EXECUTORS(co->co_executors)[i] == NULL);
21882188
}
21892189
}
21902190
PyMem_Free(co->co_executors);

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ dummy_func(
35903590
tier1 inst(ENTER_EXECUTOR, (--)) {
35913591
#ifdef _Py_TIER2
35923592
PyCodeObject *code = _PyFrame_GetCode(frame);
3593-
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
3593+
_PyExecutorObject *executor = _PyExecutorArray_EXECUTORS(code->co_executors)[oparg & 255];
35943594
if (IS_JIT_TRACING()) {
35953595
int og_opcode = executor->vm_data.opcode;
35963596
int og_oparg = (oparg & ~255) | executor->vm_data.oparg;
@@ -6266,7 +6266,7 @@ dummy_func(
62666266
_PyExecutorObject *executor;
62676267
if (target->op.code == ENTER_EXECUTOR) {
62686268
PyCodeObject *code = _PyFrame_GetCode(frame);
6269-
executor = code->co_executors->executors[target->op.arg];
6269+
executor = _PyExecutorArray_EXECUTORS(code->co_executors)[target->op.arg];
62706270
if (executor == _PyExecutor_FromExit(exit)) {
62716271
_Py_ExecutorDetach(executor);
62726272
GOTO_TIER_ONE(target);

Python/executor_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/instrumentation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ _Py_GetBaseCodeUnit(PyCodeObject *code, int i)
647647
return inst;
648648
}
649649
if (opcode == ENTER_EXECUTOR) {
650-
_PyExecutorObject *exec = code->co_executors->executors[inst.op.arg];
650+
_PyExecutorObject *exec = _PyExecutorArray_EXECUTORS(code->co_executors)[inst.op.arg];
651651
opcode = _PyOpcode_Deopt[exec->vm_data.opcode];
652652
inst.op.code = opcode;
653653
inst.op.arg = exec->vm_data.oparg;

0 commit comments

Comments
 (0)