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
Show file tree
Hide file tree
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 8000
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
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
Switch back to allocated an unused PyGC_Head for the empty tuple.
  • Loading branch information
ericsnowcurrently committed Feb 15, 2022
commit 55b8eb05fb699efc36fb0e7ac3cb500cfd7c19fc
2 changes: 2 additions & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_gc.h" // PyGC_Head
#include "pycore_global_strings.h" // struct _Py_global_strings


Expand Down Expand Up @@ -41,6 +42,7 @@ struct _Py_global_objects {

struct _Py_global_strings strings;

PyGC_Head _tuple_empty_gc_not_used;
PyTupleObject tuple_empty;
} singletons;
};
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ extern "C" {
}, \
\
.tuple_empty = { \
_PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0) \
.ob_base = _PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0) \
}, \
}, \
}
Expand Down
11 changes: 0 additions & 11 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,16 +912,6 @@ static PyMappingMethods tuple_as_mapping = {

static PyObject *tuple_iter(PyObject *seq);

static int
tuple_is_gc(PyObject *op)
{
// Global objects are never GC.
if (op == tuple_get_empty()) {
return 0;
}
return 1;
}

PyTypeObject PyTuple_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"tuple",
Expand Down Expand Up @@ -965,7 +955,6 @@ PyTypeObject PyTuple_Type = {
tuple_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = tuple_vectorcall,
.tp_is_gc = tuple_is_gc,
};

/* The following function breaks the notion that tuples are immutable:
Expand Down
2 changes: 1 addition & 1 deletion Tools/scripts/generate_global_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def generate_runtime_init(identifiers, strings):
printer.write(f'INIT_ID({name}),')
printer.write('')
with printer.block('.tuple_empty =', ','):
printer.write('_PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0)')
printer.write('.ob_base = _PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0)')
printer.write(END)
printer.write(after)

Expand Down
0