8000 bpo-46753: Add the empty tuple to the _PyRuntimeState.global_objects. by ericsnowcurrently · Pull Request #31345 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46753: Add the empty tuple to the _PyRuntimeState.global_objects. #31345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7fef0be
Add the empty tuple to the _PyRuntimeState.global_objects.
ericsnowcurrently Feb 14, 2022
9f0aa44
Use the global empty tuple.
ericsnowcurrently Feb 14, 2022
21ce6aa
Merge branch 'main' into global-objects-empty-tuple
ericsnowcurrently Feb 15, 2022
ba1b4cc
Leave space for the empty GC head.
ericsnowcurrently Feb 15, 2022
67ebfd6
Revert "Leave space for the empty GC head."
ericsnowcurrently Feb 15, 2022
df35d70
Add PyTuple_Type.tp_is_gc().
ericsnowcurrently Feb 15, 2022
24ca51c
Inline tuple_get_empty().
ericsnowcurrently Feb 15, 2022
55b8eb0
Switch back to allocated an unused PyGC_Head for the empty tuple.
ericsnowcurrently Feb 15, 2022
ab721be
Skip tupledealloc() if it's the empty tuple.
ericsnowcurrently Feb 15, 2022
7b89727
Return the empty tuple when resizing to 0.
ericsnowcurrently Feb 16, 2022
2fedc9c
Use the empty tuple when appropriate in deepfreeze.c.
ericsnowcurrently Feb 16, 2022
dd0a1a2
Disassociate the empty tuple from the freelist logic.
ericsnowcurrently Feb 16, 2022
5e729d8
Merge branch 'main' into global-objects-empty-tuple
ericsnowcurrently Feb 23, 2022
deddeb5
Allow deallocating an empty tuple if a subclass.
ericsnowcurrently Feb 23, 2022
efed1d1
Return a new reference from tuple_get_empty().
ericsnowcurrently Feb 23, 2022
923c8cc
Add _PyGC_Head_UNUSED.
ericsnowcurrently Feb 24, 2022
631d12b
Clean up tupledealloc() a little.
ericsnowcurrently Feb 24, 2022
3264e8d
Drop get_tuple_state().
ericsnowcurrently Feb 24, 2022
9dfee07
Consolidate the freelist code.
ericsnowcurrently Feb 24, 2022
e272804
Merge branch 'main' into global-objects-empty-tuple
ericsnowcurrently Feb 25, 2022
597f1bd
Do not use _Py_NewRef().
ericsnowcurrently Feb 25, 2022
fa2edad
Calling tupledealloc() on the empty singleton is an error.
ericsnowcurrently Feb 25, 2022
f4acc36 8000
Tweak _PyTuple_Resize().
ericsnowcurrently Feb 25, 2022
460ae61
Roll back the global singleton part.
ericsnowcurrently Feb 25, 2022
c163aca
Re-apply the global singleton part.
ericsnowcurrently Feb 25, 2022
4ac3d66
Make sure struct _Py_tuple_state is never empty.
ericsnowcurrently Feb 28, 2022
11a9311
Clarify about freelists a little.
ericsnowcurrently Feb 28, 2022
fdc82d2
Fix a preprocessor condition.
ericsnowcurrently Feb 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak _PyTuple_Resize().
  • Loading branch information
ericsnowcurrently committed Feb 25, 2022
commit f4acc36b9ffd23f5ef40138ee21f28ec7a5f4140
22 changes: 13 additions & 9 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,14 +920,22 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
PyErr_BadInternalCall();
return -1;
}

oldsize = Py_SIZE(v);
if (oldsize == newsize)
if (oldsize == newsize) {
return 0;

}
if (newsize == 0) {
Py_DECREF(v);
*pv = tuple_get_empty();
return 0;
}
if (oldsize == 0) {
/* Empty tuples are often shared, so we should never
resize them in-place even if we do own the only
(current) reference */
#ifdef Py_DEBUG
assert(v == &_Py_SINGLETON(tuple_empty));
#endif
/* The empty tuple is statically allocated so we never
resize it in-place. */
Py_DECREF(v);
*pv = PyTuple_New(newsize);
return *pv == NULL ? -1 : 0;
Expand All @@ -947,10 +955,6 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
for (i = newsize; i < oldsize; i++) {
Py_CLEAR(v->ob_item[i]);
}
if (newsize == 0) {
*pv = tuple_get_empty();
return 0;
}
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
if (sv == NULL) {
*pv = NULL;
Expand Down
0