Sergei Lebedev <[email protected]> added the comment:
I know this patch has already been rejected, but I wanted to give another
potential use-case for accessing GC status from C: JIT compilers.
Imagine a JIT compiler which uses alternative storage for instance attributes.
In order to maintain correctness, it should "materialize" the stored attributes
whenever __dict__ (or rather a pointer to __dict__) is accessed. In this
context materialization means something like:
__dict__ = {}
for key, value in zip(keys, values):
__dict__[key] = value
Now, what if a __dict__ is accessed during a GC collection (which is possible:
collect->deduce_unreachable->subtract_refs->subtype_traverse via tp_traverse)?
The JIT compiler should be able to detect such calls and avoid allocating
anything:
if collecting:
return
__dict__ = {}
# ...
This is possible to implement in pure Python using gc.isenabled and
gc.callbacks, but there is no existing API to do that in C.
Does this sounds convincing enough to motivate adding
int PyGC_IsEnabled(void)
int PyGC_IsCollecting(void)
to the C API?
----------
nosy: +sergei.lebedev
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue28254>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com