You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partial moving of core objects to interpreter state is incorrect at best, unsafe at worse. #89854
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-11-02.16:04:49.885>labels= ['interpreter-core', 'type-bug', '3.11']
title='Partial moving of core objects to interpreter state is incorrect at best, unsafe at worse.'updated_at=<Date2022-01-18.12:45:01.315>user='https://github.com/markshannon'
We currently have an unstable state in the VM where some core objects are static and some are per-interpreter.
For example, smalls ints are allocated per-interpreter, but many classes are allocated statically.
This means that if any int is reachable from a class, then references to per-interpreter objects can be left dangling, or be out of date.
E.g. consider this sequence:
Create an interpreter
Destroy it.
Create a new interpreter
sys.float_info.n_unnamed_fields causes a memory violation if the per-interpreter allocated 0 held by sys.float_info.n_unnamed_fields is freed.
If it is not freed, then sys.float_info.n_unnamed_fields is 0 is False, meaning that there are two zeros present.
The above is just an example. Classes have many references to ints, floats, code objects, etc. Any of those could have the same issue.
All objects that form the core object graph must either be entirely static, or entirely per-interpreter.
We cannot change from static to per-interpreter in a piecemeal fashion. It must be done all at once.
sys.float_info.n_unnamed_fields causes a memory violation if the per-interpreter allocated 0 held by sys.float_info.n_unnamed_fields is freed.
If it is not freed, then sys.float_info.n_unnamed_fields is 0 is False, meaning that there are two zeros present.
Python 3.9 and 3.10 are concerned by this issue: integer singletons are per-interpreter since Python 3.9.
Should Python 3.9 and 3.10 be fixed? "x is 0" is recommended and should be used. For example, the compiler emits a SyntaxWarning:
$ python3.9
>>> x=0
>>> x is0
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True
I propose to only fix the main branch and so close the issue.
This wasn't closed. Is fixing this still targeted for 3.11? In that case it should probably be made a release blocker. If not, the label should be changed to 3.12. @vstinner@markshannon@ericsnowcurrently
Activity
markshannon commentedon Nov 2, 2021
We currently have an unstable state in the VM where some core objects are static and some are per-interpreter.
For example, smalls ints are allocated per-interpreter, but many classes are allocated statically.
This means that if any int is reachable from a class, then references to per-interpreter objects can be left dangling, or be out of date.
E.g. consider this sequence:
sys.float_info.n_unnamed_fieldscauses a memory violation if the per-interpreter allocated 0 held by sys.float_info.n_unnamed_fields is freed.If it is not freed, then
sys.float_info.n_unnamed_fields is 0is False, meaning that there are two zeros present.The above is just an example. Classes have many references to ints, floats, code objects, etc. Any of those could have the same issue.
All objects that form the core object graph must either be entirely static, or entirely per-interpreter.
We cannot change from static to per-interpreter in a piecemeal fashion. It must be done all at once.
markshannon commentedon Nov 3, 2021
New changeset acc89db by Mark Shannon in branch 'main':
bpo-45691: Make array of small ints static to fix use-after-free error. (GH-29366)
acc89db
vstinner commentedon Nov 17, 2021
Right. Changing that is an hard problem :-( See for example bpo-40601 "[C API] Hide static types from the limited C API".
I tried once to "free" / reset static types in Py_Finalize(), but it's hard to implement properly :-(
vstinner commentedon Jan 17, 2022
Mark:
I created bpo-46417 follow-up issue: "[subinterpreters] Clear static types in Py_Finalize()".
vstinner commentedon Jan 17, 2022
Python 3.9 and 3.10 are concerned by this issue: integer singletons are per-interpreter since Python 3.9.
Should Python 3.9 and 3.10 be fixed? "x is 0" is recommended and should be used. For example, the compiler emits a SyntaxWarning:
I propose to only fix the main branch and so close the issue.
gvanrossum commentedon Jul 3, 2022
This wasn't closed. Is fixing this still targeted for 3.11? In that case it should probably be made a release blocker. If not, the label should be changed to 3.12. @vstinner @markshannon @ericsnowcurrently
vstinner commentedon Jul 3, 2022
@markshannon fixed the issue with acc89db
This issue can now be closed, no? Or is there a remaining issue?
I implemented that in issue #90575.
gvanrossum commentedon Jul 4, 2022
The array of small ints got moved again, it's now in pycore_global_objects.h. I will close this issue.