Repository navigation
gh-158445: Allocate memory in the heap in Py_GetVersion() - #158608
Conversation
Py_GetVersion() now allocates memory on the heap, instead of using a static buffer, to no longer truncate the version if it's longer than 299 bytes. Update Py_GetCompiler() and Py_GetBuildInfo() tests: they are now always a part of sys.version.
Documentation build overview
|
|
On my Fedora 44, |
|
hey @vstinner, we ran into a side effect of moving the buffer to the heap - some debuggers and core-dump tools find the interpreter version by reading the can we make the static buffer bigger, at least enough to hold the version, tag, and free-threading marker (~64 bytes)? let me know if I should file a separate issue |
|
py-spy: I understand that in Python 3.15, py-spy copies 128 bytes from the Would it be possible for py-spy to (1) call Py_GetVersion() function and (2) copy the return string? I suppose that it's better to not call functions in a debugger to leave the process state unchanged.
I didn't think about these use cases. That's not how I expected the Python C API to be used. Well, they just inspect memory, they don't even call functions, if I understand correctly.
Would you recommend to revert my change and add a comment explaining the debugger/crash reporter use cases? Or just restore the static buffer to its Python 3.15 size (300 bytes)? I suppose that the static buffer name should be restored to Thanks for rising the issue! |
|
Or there is another approach, build strings at build time, to avoid the complex code building strings at runtime: #158951. |
yeah, I think not calling function in the debugged process is the point. for core-dump tools, there isn't even a process around.
sounds right. like you say, they're inspecting memories, not "using" the C API per se.
I don't think we need to revert, just restoring the thanks for looking into this! I didn't look closely at your gh-158951, it looks like a bigger change than just restoring the static buffer, so if you think that's the better way to go, I may be able to test it in the next few days, or maybe next week. |
Py_GetVersion() now allocates memory on the heap, instead of using a static buffer, to no longer truncate the version if it's longer than 299 bytes.
Update Py_GetCompiler() and Py_GetBuildInfo() tests: they are now always a part of sys.version.