Author superbobry
Recipients gregory.p.smith, llllllllll, rhettinger, superbobry
Date 2019-12-13.13:24:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:

    __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?
Date User Action Args
2019-12-13 13:24:48superbobrysetrecipients: + superbobry, rhettinger, gregory.p.smith, llllllllll
2019-12-13 13:24:48superbobrysetmessageid: <>
2019-12-13 13:24:48superbobrylinkissue28254 messages
2019-12-13 13:24:48superbobrycreate