Skip to content

Commit 6eaa16a

Browse files
committed
PyTuple_GET_EMPTY
1 parent fecc89c commit 6eaa16a

File tree

6 files changed

+7
-25
lines changed

6 files changed

+7
-25
lines changed

mypyc/irbuild/ll_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@
187187
unicode_compare,
188188
)
189189
from mypyc.primitives.tuple_ops import (
190+
expand_empty_tuple_macro,
190191
list_tuple_op,
191-
load_empty_tuple_constant_op,
192192
new_tuple_op,
193193
new_tuple_with_length_op,
194194
sequence_tuple_op,
@@ -2364,7 +2364,7 @@ def new_tuple(self, items: list[Value], line: int) -> Value:
23642364
size: Value = Integer(len(items), c_pyssize_t_rprimitive)
23652365
return self.call_c(new_tuple_op, [size] + items, line)
23662366
else:
2367-
return self.call_c(load_empty_tuple_constant_op, [], line)
2367+
return self.call_c(expand_empty_tuple_macro, [], line)
23682368

23692369
def new_tuple_with_length(self, length: Value, line: int) -> Value:
23702370
"""This function returns an uninitialized tuple.

mypyc/lib-rt/CPy.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ typedef struct tuple_T4CIOO {
6464
} tuple_T4CIOO;
6565
#endif
6666

67-
// System-wide empty tuple constant
68-
extern PyObject * __mypyc_empty_tuple__;
69-
70-
static inline PyObject *_CPyTuple_LoadEmptyTupleConstant() {
71-
// do tests still pass if I comment this out? empty tuple singleton is not tracked by gc
72-
// Py_INCREF(__mypyc_empty_tuple__);
73-
return __mypyc_empty_tuple__;
74-
}
7567

7668
// Native object operations
7769

mypyc/lib-rt/init.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,4 @@ PyObject * __mypyc_empty_tuple__ = NULL;
1313
// things at load time.
1414
void CPy_Init(void) {
1515
_CPy_ExcDummyStruct.ob_base.ob_type = &PyBaseObject_Type;
16-
17-
// Initialize system-wide empty tuple constant
18-
if (__mypyc_empty_tuple__ == NULL) {
19-
__mypyc_empty_tuple__ = PyTuple_New(0);
20-
if (!__mypyc_empty_tuple__) {
21-
PyErr_SetString(PyExc_RuntimeError, "Failed to initialize __mypyc_empty_tuple__");
22-
return;
23-
}
24-
Py_INCREF(__mypyc_empty_tuple__);
25-
}
2616
}

mypyc/primitives/tuple_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
error_kind=ERR_MAGIC,
5656
)
5757

58-
load_empty_tuple_constant_op = custom_op(
58+
expand_empty_tuple_macro = custom_op(
5959
arg_types=[],
6060
return_type=tuple_rprimitive,
61-
c_function_name="_CPyTuple_LoadEmptyTupleConstant",
61+
c_function_name="PyTuple_GET_EMPTY",
6262
error_kind=ERR_NEVER,
6363
)
6464

mypyc/test-data/irbuild-basic.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ L0:
17581758
r10 = PyDict_New()
17591759
r11 = CPyDict_UpdateInDisplay(r10, r6)
17601760
r12 = r11 >= 0 :: signed
1761-
r13 = _CPyTuple_LoadEmptyTupleConstant()
1761+
r13 = PyTuple_GET_EMPTY()
17621762
r14 = PyObject_Call(r9, r13, r10)
17631763
r15 = unbox(tuple[int, int, int], r14)
17641764
return r15

mypyc/test-data/irbuild-classes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ L2:
297297
r27 = CPyType_FromTemplate(r26, r24, r25)
298298
r28 = C_trait_vtable_setup()
299299
r29 = '__mypyc_attrs__'
300-
r30 = _CPyTuple_LoadEmptyTupleConstant()
300+
r30 = PyTuple_GET_EMPTY()
301301
r31 = PyObject_SetAttr(r27, r29, r30)
302302
r32 = r31 >= 0 :: signed
303303
__main__.C = r27 :: type
@@ -310,7 +310,7 @@ L2:
310310
r39 = __main__.S_template :: type
311311
r40 = CPyType_FromTemplate(r39, r37, r38)
312312
r41 = '__mypyc_attrs__'
313-
r42 = _CPyTuple_LoadEmptyTupleConstant()
313+
r42 = PyTuple_GET_EMPTY()
314314
r43 = PyObject_SetAttr(r40, r41, r42)
315315
r44 = r43 >= 0 :: signed
316316
__main__.S = r40 :: type

0 commit comments

Comments
 (0)