| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,13 +8,20 @@ extern "C" { | |||
| 8 | 8 | # error "this header requires Py_BUILD_CORE define" | |
| 9 | 9 | #endif | |
| 10 | 10 | ||
| 11 | - // Export for '_pickle' shared extension | ||
| 11 | + // Export for '_abc' shared extension | ||
| 12 | 12 | PyAPI_FUNC(int) _PySet_NextEntry( | |
| 13 | 13 | PyObject *set, | |
| 14 | 14 | Py_ssize_t *pos, | |
| 15 | 15 | PyObject **key, | |
| 16 | 16 | Py_hash_t *hash); | |
| 17 | 17 | ||
| 18 | + // Export for '_pickle' shared extension | ||
| 19 | + PyAPI_FUNC(int) _PySet_NextEntryRef( | ||
| 20 | + PyObject *set, | ||
| 21 | + Py_ssize_t *pos, | ||
| 22 | + PyObject **key, | ||
| 23 | + Py_hash_t *hash); | ||
| 24 | + | ||
| 18 | 25 | // Export for '_pickle' shared extension | |
| 19 | 26 | PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); | |
| 20 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -862,7 +862,7 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass, | |||
| 862 | 862 | ||
| 863 | 863 | // Make a local copy of the registry to protect against concurrent | |
| 864 | 864 | // modifications of _abc_registry. | |
| 865 | - PyObject *registry = PySet_New(registry_shared); | ||
| 865 | + PyObject *registry = PyFrozenSet_New(registry_shared); | ||
| 866 | 866 | if (registry == NULL) { | |
| 867 | 867 | return -1; | |
| 868 | 868 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,15 +9,16 @@ | |||
| 9 | 9 | #endif | |
| 10 | 10 | ||
| 11 | 11 | #include "Python.h" | |
| 12 | - #include "pycore_bytesobject.h" // _PyBytesWriter | ||
| 13 | - #include "pycore_ceval.h" // _Py_EnterRecursiveCall() | ||
| 14 | - #include "pycore_long.h" // _PyLong_AsByteArray() | ||
| 15 | - #include "pycore_moduleobject.h" // _PyModule_GetState() | ||
| 16 | - #include "pycore_object.h" // _PyNone_Type | ||
| 17 | - #include "pycore_pystate.h" // _PyThreadState_GET() | ||
| 18 | - #include "pycore_runtime.h" // _Py_ID() | ||
| 19 | - #include "pycore_setobject.h" // _PySet_NextEntry() | ||
| 20 | - #include "pycore_sysmodule.h" // _PySys_GetAttr() | ||
| 12 | + #include "pycore_bytesobject.h" // _PyBytesWriter | ||
| 13 | + #include "pycore_ceval.h" // _Py_EnterRecursiveCall() | ||
| 14 | + #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION() | ||
| 15 | + #include "pycore_long.h" // _PyLong_AsByteArray() | ||
| 16 | + #include "pycore_moduleobject.h" // _PyModule_GetState() | ||
| 17 | + #include "pycore_object.h" // _PyNone_Type | ||
| 18 | + #include "pycore_pystate.h" // _PyThreadState_GET() | ||
| 19 | + #include "pycore_runtime.h" // _Py_ID() | ||
| 20 | + #include "pycore_setobject.h" // _PySet_NextEntry() | ||
| 21 | + #include "pycore_sysmodule.h" // _PySys_GetAttr() | ||
| 21 | 22 | ||
| 22 | 23 | #include <stdlib.h> // strtol() | |
| 23 | 24 | ||
@@ -3413,15 +3414,21 @@ save_set(PickleState *state, PicklerObject *self, PyObject *obj) | |||
| 3413 | 3414 | i = 0; | |
| 3414 | 3415 | if (_Pickler_Write(self, &mark_op, 1) < 0) | |
| 3415 | 3416 | return -1; | |
| 3416 | - while (_PySet_NextEntry(obj, &ppos, &item, &hash)) { | ||
| 3417 | - Py_INCREF(item); | ||
| 3418 | - int err = save(state, self, item, 0); | ||
| 3417 | + | ||
| 3418 | + int err = 0; | ||
| 3419 | + Py_BEGIN_CRITICAL_SECTION(obj); | ||
| 3420 | + while (_PySet_NextEntryRef(obj, &ppos, &item, &hash)) { | ||
| 3421 | + err = save(state, self, item, 0); | ||
| 3419 | 3422 | Py_CLEAR(item); | |
| 3420 | 3423 | if (err < 0) | |
| 3421 | - return -1; | ||
| 3424 | + break; | ||
| 3422 | 3425 | if (++i == BATCHSIZE) | |
| 3423 | 3426 | break; | |
| 3424 | 3427 | } | |
| 3428 | + Py_END_CRITICAL_SECTION(); | ||
| 3429 | + if (err < 0) { | ||
| 3430 | + return -1; | ||
| 3431 | + } | ||
| 3425 | 3432 | if (_Pickler_Write(self, &additems_op, 1) < 0) | |
| 3426 | 3433 | return -1; | |
| 3427 | 3434 | if (PySet_GET_SIZE(obj) != set_size) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "parts.h" | |
| 2 | 2 | #include "../_testcapi/util.h" // NULLABLE, RETURN_INT | |
| 3 | 3 | ||
| 4 | + #include "pycore_critical_section.h" | ||
| 4 | 5 | #include "pycore_setobject.h" | |
| 5 | 6 | ||
| 6 | 7 | ||
@@ -27,10 +28,13 @@ set_next_entry(PyObject *self, PyObject *args) | |||
| 27 | 28 | return NULL; | |
| 28 | 29 | } | |
| 29 | 30 | NULLABLE(set); | |
| 30 | - | ||
| 31 | - rc = _PySet_NextEntry(set, &pos, &item, &hash); | ||
| 31 | + Py_BEGIN_CRITICAL_SECTION(set); | ||
| 32 | + rc = _PySet_NextEntryRef(set, &pos, &item, &hash); | ||
| 33 | + Py_END_CRITICAL_SECTION(); | ||
| 32 | 34 | if (rc == 1) { | |
| 33 | - return Py_BuildValue("innO", rc, pos, hash, item); | ||
| 35 | + PyObject *ret = Py_BuildValue("innO", rc, pos, hash, item); | ||
| 36 | + Py_DECREF(item); | ||
| 37 | + return ret; | ||
| 34 | 38 | } | |
| 35 | 39 | assert(item == UNINITIALIZED_PTR); | |
| 36 | 40 | assert(hash == (Py_hash_t)UNINITIALIZED_SIZE); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2979,8 +2979,9 @@ dict_set_fromkeys(PyInterpreterState *interp, PyDictObject *mp, | |||
| 2979 | 2979 | return NULL; | |
| 2980 | 2980 | } | |
| 2981 | 2981 | ||
| 2982 | - while (_PySet_NextEntry(iterable, &pos, &key, &hash)) { | ||
| 2983 | - if (insertdict(interp, mp, Py_NewRef(key), hash, Py_NewRef(value))) { | ||
| 2982 | + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(iterable); | ||
| 2983 | + while (_PySet_NextEntryRef(iterable, &pos, &key, &hash)) { | ||
| 2984 | + if (insertdict(interp, mp, key, hash, Py_NewRef(value))) { | ||
| 2984 | 2985 | Py_DECREF(mp); | |
| 2985 | 2986 | return NULL; | |
| 2986 | 2987 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1287,8 +1287,7 @@ list_extend_set(PyListObject *self, PySetObject *other) | |||
| 1287 | 1287 | Py_hash_t hash; | |
| 1288 | 1288 | PyObject *key; | |
| 1289 | 1289 | PyObject **dest = self->ob_item + m; | |
| 1290 | - while (_PySet_NextEntry((PyObject *)other, &setpos, &key, &hash)) { | ||
| 1291 | - Py_INCREF(key); | ||
| 1290 | + while (_PySet_NextEntryRef((PyObject *)other, &setpos, &key, &hash)) { | ||
| 1292 | 1291 | FT_ATOMIC_STORE_PTR_RELEASE(*dest, key); | |
| 1293 | 1292 | dest++; | |
| 1294 | 1293 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2661,7 +2661,6 @@ PySet_Add(PyObject *anyset, PyObject *key) | |||
| 2661 | 2661 | return rv; | |
| 2662 | 2662 | } | |
| 2663 | 2663 | ||
| 2664 | - // TODO: Make thread-safe in free-threaded builds | ||
| 2665 | 2664 | int | |
| 2666 | 2665 | _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash) | |
| 2667 | 2666 | { | |
@@ -2678,6 +2677,23 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash | |||
| 2678 | 2677 | return 1; | |
| 2679 | 2678 | } | |
| 2680 | 2679 | ||
| 2680 | + int | ||
| 2681 | + _PySet_NextEntryRef(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash) | ||
| 2682 | + { | ||
| 2683 | + setentry *entry; | ||
| 2684 | + | ||
| 2685 | + if (!PyAnySet_Check(set)) { | ||
| 2686 | + PyErr_BadInternalCall(); | ||
| 2687 | + return -1; | ||
| 2688 | + } | ||
| 2689 | + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(set); | ||
| 2690 | + if (set_next((PySetObject *)set, pos, &entry) == 0) | ||
| 2691 | + return 0; | ||
| 2692 | + *key = Py_NewRef(entry->key); | ||
| 2693 | + *hash = entry->hash; | ||
| 2694 | + return 1; | ||
| 2695 | + } | ||
| 2696 | + | ||
| 2681 | 2697 | PyObject * | |
| 2682 | 2698 | PySet_Pop(PyObject *set) | |
| 2683 | 2699 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,13 @@ | |||
| 7 | 7 | and sharing. */ | |
| 8 | 8 | ||
| 9 | 9 | #include "Python.h" | |
| 10 | - #include "pycore_call.h" // _PyObject_CallNoArgs() | ||
| 11 | - #include "pycore_code.h" // _PyCode_New() | ||
| 12 | - #include "pycore_hashtable.h" // _Py_hashtable_t | ||
| 13 | - #include "pycore_long.h" // _PyLong_DigitCount | ||
| 14 | - #include "pycore_setobject.h" // _PySet_NextEntry() | ||
| 15 | - #include "marshal.h" // Py_MARSHAL_VERSION | ||
| 10 | + #include "pycore_call.h" // _PyObject_CallNoArgs() | ||
| 11 | + #include "pycore_code.h" // _PyCode_New() | ||
| 12 | + #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION() | ||
| 13 | + #include "pycore_hashtable.h" // _Py_hashtable_t | ||
| 14 | + #include "pycore_long.h" // _PyLong_DigitCount | ||
| 15 | + #include "pycore_setobject.h" // _PySet_NextEntry() | ||
| 16 | + #include "marshal.h" // Py_MARSHAL_VERSION | ||
| 16 | 17 | ||
| 17 | 18 | #ifdef __APPLE__ | |
| 18 | 19 | # include "TargetConditionals.h" | |
@@ -531,23 +532,29 @@ w_complex_object(PyObject *v, char flag, WFILE *p) | |||
| 531 | 532 | return; | |
| 532 | 533 | } | |
| 533 | 534 | Py_ssize_t i = 0; | |
| 534 | - while (_PySet_NextEntry(v, &pos, &value, &hash)) { | ||
| 535 | + Py_BEGIN_CRITICAL_SECTION(v); | ||
| 536 | + while (_PySet_NextEntryRef(v, &pos, &value, &hash)) { | ||
| 535 | 537 | PyObject *dump = _PyMarshal_WriteObjectToString(value, | |
| 536 | 538 | p->version, p->allow_code); | |
| 537 | 539 | if (dump == NULL) { | |
| 538 | 540 | p->error = WFERR_UNMARSHALLABLE; | |
| 539 | - Py_DECREF(pairs); | ||
| 540 | - return; | ||
| 541 | + Py_DECREF(value); | ||
| 542 | + break; | ||
| 541 | 543 | } | |
| 542 | 544 | PyObject *pair = PyTuple_Pack(2, dump, value); | |
| 543 | 545 | Py_DECREF(dump); | |
| 546 | + Py_DECREF(value); | ||
| 544 | 547 | if (pair == NULL) { | |
| 545 | 548 | p->error = WFERR_NOMEMORY; | |
| 546 | - Py_DECREF(pairs); | ||
| 547 | - return; | ||
| 549 | + break; | ||
| 548 | 550 | } | |
| 549 | 551 | PyList_SET_ITEM(pairs, i++, pair); | |
| 550 | 552 | } | |
| 553 | + Py_END_CRITICAL_SECTION(); | ||
| 554 | + if (p->error == WFERR_UNMARSHALLABLE || p->error == WFERR_NOMEMORY) { | ||
| 555 | + Py_DECREF(pairs); | ||
| 556 | + return; | ||
| 557 | + } | ||
| 551 | 558 | assert(i == n); | |
| 552 | 559 | if (PyList_Sort(pairs)) { | |
| 553 | 560 | p->error = WFERR_NOMEMORY; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2910,6 +2910,7 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp) | |||
| 2910 | 2910 | Py_ssize_t i = 0; | |
| 2911 | 2911 | PyObject *item; | |
| 2912 | 2912 | Py_hash_t hash; | |
| 2913 | + // if stdlib_module_names is not NULL, it is always a frozenset. | ||
| 2913 | 2914 | while (_PySet_NextEntry(stdlib_module_names, &i, &item, &hash)) { | |
| 2914 | 2915 | if (PyUnicode_Check(item) | |
| 2915 | 2916 | && PyUnicode_Compare(key, item) == 0) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments