|
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) {
|
|
0 commit comments