diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-23 15:54:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 15:54:35 +0200 |
commit | c41eed1a874e2f22bde45c3c89418414b7a37f46 (patch) | |
tree | e90ff0bf1c5349169f3f04c914695b3c4b476f37 /Objects/stringlib/partition.h | |
parent | 32f2eda85957365d208f499b730d30b7eb419741 (diff) | |
download | cpython-git-c41eed1a874e2f22bde45c3c89418414b7a37f46.tar.gz |
bpo-40521: Make bytes singletons per interpreter (GH-21074)
Each interpreter now has its own empty bytes string and single byte
character singletons.
Replace STRINGLIB_EMPTY macro with STRINGLIB_GET_EMPTY() macro.
Diffstat (limited to 'Objects/stringlib/partition.h')
-rw-r--r-- | Objects/stringlib/partition.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h index ed32a6f2b3..3731df5698 100644 --- a/Objects/stringlib/partition.h +++ b/Objects/stringlib/partition.h @@ -37,10 +37,12 @@ STRINGLIB(partition)(PyObject* str_obj, #else Py_INCREF(str_obj); PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY); + PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); + assert(empty != NULL); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 1, empty); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 2, empty); #endif return out; } @@ -90,10 +92,12 @@ STRINGLIB(rpartition)(PyObject* str_obj, return NULL; } #else - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); + PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); + assert(empty != NULL); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 0, empty); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 1, empty); Py_INCREF(str_obj); PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); #endif |