Repository navigation
Conversation
Use the new API in: * Modules/_abc.c * Modules/_asynciomodule.c * Modules/_hashopenssl.c * Modules/_ssl.c
Documentation build overview
|
PyFrozenSetWriter C APIPyFrozenSetWriter C API
|
Updating |
| // Now that the frozenset is fully initialized, it's safe to track it in | ||
| // the GC. Track the frozenset if at least one item is tracked by the GC. | ||
| Py_ssize_t pos = 0; | ||
| setentry *entry; | ||
| while (set_next(frozenset, &pos, &entry)) { | ||
| PyObject *item = entry->key; | ||
| if (_PyObject_IS_GC(item) && _PyObject_GC_IS_TRACKED(item)) { | ||
| _PyObject_GC_TRACK(frozenset); | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Maybe we can skip iterating on the items and just always track the frozenset in the GC. Most set functions already do that: always call _PyObject_GC_TRACK() without checking items.
|
cc @corona10 |
|
This C API is just an abstraction on top of existing |
|
The edits to |
There multiple advantages of this new API. The current The internal frozenset is not tracked by the GC until Finish() is called (when the frozenset is fully initialized). So it's not possible to observe a frozenset being modified in Python (which must not be possible, frozenset are immutable, right?). See for example #159730 for recent examples of fixed bugs. Also, I think that's a bad design to have a PySet_Add() function to modify an immutable (frozenset) object. We should avoid such API. So I propose deprecating calling PySet_Add() on a frozenset (replaced with this new Writer API). See issues: |
| success, or :c:func:`PyFrozenSetWriter_Discard` on error. | ||
|
|
||
|
|
||
| .. c:function:: PyFrozenSetWriter* PyFrozenSetWriter_Create(void) |
There was a problem hiding this comment.
PyFrozenSetWriter_Create(Py_ssize_t size_hint) perhaps (per the pep 839 draft that would build on this). Also, you reverence "size must be positive or zero" in the below but there is no size or size_hint parameter here or in the code yet.
|
When you're done making the requested changes, leave the comment: |
Use the new API in:
PyFrozenWriterC API to create afrozensetobject #160147