Skip to content

Commit cf16da0

Browse files
committed
Clarify JIT publication registration semantics
1 parent 01df239 commit cf16da0

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

Include/internal/pycore_jit_publish.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ typedef struct _PyJitCodeRegistration _PyJitCodeRegistration;
1111

1212
#ifdef _Py_JIT
1313

14-
/* Return a teardown handle when any backend stores registration state.
15-
* A NULL result is valid when publication succeeded only through backends
16-
* with no unregister step, such as perf map output.
14+
/* Publish JIT code to optional tooling backends.
15+
*
16+
* The return value is a backend-specific deregistration handle, not a
17+
* success/failure indicator. NULL means there is nothing to unregister later:
18+
* perf does not need a handle, and GDB/GNU backtrace registration failures
19+
* are intentionally non-fatal because tooling support must not make JIT
20+
* compilation fail.
1721
*/
1822
_PyJitCodeRegistration *_PyJit_RegisterCode(const void *code_addr,
1923
size_t code_size,

Python/jit_publish.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ _PyJit_RegisterCode(const void *code_addr, size_t code_size,
8282
const char *entry, const char *filename)
8383
{
8484
jit_register_perf_code(code_addr, code_size, entry, filename);
85+
// Perf publication has no teardown handle, so it is intentionally
86+
// not counted below.
8587

8688
#if !defined(PY_HAVE_JIT_GDB_UNWIND) \
8789
&& !defined(PY_HAVE_JIT_GNU_BACKTRACE_UNWIND)
@@ -93,18 +95,20 @@ _PyJit_RegisterCode(const void *code_addr, size_t code_size,
9395
return NULL;
9496
}
9597

96-
int registered = 0;
98+
// Partial failures are non-fatal: the JIT code can still execute, but
99+
// unavailable tooling may not be able to unwind it.
100+
int any_registered = 0;
97101
# if defined(PY_HAVE_JIT_GDB_UNWIND)
98102
jit_register_gdb_code(
99103
registration, code_addr, code_size, entry, filename);
100-
registered |= registration->gdb_handle != NULL;
104+
any_registered |= registration->gdb_handle != NULL;
101105
# endif
102106
# if defined(PY_HAVE_JIT_GNU_BACKTRACE_UNWIND)
103107
jit_register_gnu_backtrace_code(
104108
registration, code_addr, code_size);
105-
registered |= registration->gnu_backtrace_handle != NULL;
109+
any_registered |= registration->gnu_backtrace_handle != NULL;
106110
# endif
107-
if (!registered) {
111+
if (!any_registered) {
108112
PyMem_RawFree(registration);
109113
return NULL;
110114
}

0 commit comments

Comments
 (0)