7
7
#include "pycore_initconfig.h" // _PyStatus_OK()
8
8
#include "pycore_object.h" // _PyObject_GC_TRACK()
9
9
#include "pycore_pyerrors.h" // _Py_FatalRefcountError()
10
- #include "pycore_tuple.h" // struct _Py_tuple_state()
11
10
12
11
/*[clinic input]
13
12
class tuple "PyTupleObject *" "&PyTuple_Type"
@@ -17,27 +16,20 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
17
16
#include "clinic/tupleobject.c.h"
18
17
19
18
20
- #if PyTuple_MAXSAVESIZE > 0
21
- static struct _Py_tuple_state *
22
- get_tuple_state (void )
23
- {
24
- PyInterpreterState * interp = _PyInterpreterState_GET ();
25
- return & interp -> tuple ;
26
- }
27
- #endif
19
+ #define STATE (interp->tuple)
28
20
29
21
30
22
/* Print summary info about the state of the optimized allocator */
31
23
void
32
24
_PyTuple_DebugMallocStats (FILE * out )
33
25
{
34
26
#if PyTuple_MAXSAVESIZE > 0
35
- struct _Py_tuple_state * state = get_tuple_state ();
27
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
36
28
for (int i = 1 ; i < PyTuple_MAXSAVESIZE ; i ++ ) {
37
29
char buf [128 ];
38
30
PyOS_snprintf (buf , sizeof (buf ),
39
31
"free %d-sized PyTupleObject" , i );
40
- _PyDebugAllocatorStats (out , buf , state -> numfree [i - 1 ],
32
+ _PyDebugAllocatorStats (out , buf , STATE . numfree [i - 1 ],
41
33
_PyObject_VAR_SIZE (& PyTuple_Type , i ));
42
34
}
43
35
#endif
@@ -65,14 +57,14 @@ tuple_alloc(Py_ssize_t size)
65
57
66
58
// Check for max save size > 1.
67
59
#if PyTuple_MAXSAVESIZE > 1
68
- struct _Py_tuple_state * state = get_tuple_state ();
60
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
69
61
#ifdef Py_DEBUG
70
62
// tuple_alloc() must not be called after _PyTuple_Fini()
71
- assert (state -> numfree [0 ] >= 0 );
63
+ assert (STATE . numfree [0 ] >= 0 );
72
64
#endif
73
- if (size < PyTuple_MAXSAVESIZE && (op = state -> free_list [size - 1 ]) != NULL ) {
74
- state -> free_list [size - 1 ] = (PyTupleObject * ) op -> ob_item [0 ];
75
- state -> numfree [size - 1 ]-- ;
65
+ if (size < PyTuple_MAXSAVESIZE && (op = STATE . free_list [size - 1 ]) != NULL ) {
66
+ STATE . free_list [size - 1 ] = (PyTupleObject * ) op -> ob_item [0 ];
67
+ STATE . numfree [size - 1 ]-- ;
76
68
/* Inlined _PyObject_InitVar() without _PyType_HasFeature() test */
77
69
#ifdef Py_TRACE_REFS
78
70
Py_SET_SIZE (op , size );
@@ -240,18 +232,18 @@ tupledealloc(PyTupleObject *op)
240
232
Py_XDECREF (op -> ob_item [i ]);
241
233
}
242
234
#if PyTuple_MAXSAVESIZE > 0
243
- struct _Py_tuple_state * state = get_tuple_state ();
235
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
244
236
#ifdef Py_DEBUG
245
237
// tupledealloc() must not be called after _PyTuple_Fini()
246
- assert (state -> numfree [0 ] >= 0 );
238
+ assert (STATE . numfree [0 ] >= 0 );
247
239
#endif
248
240
if (len < (PyTuple_MAXSAVESIZE - 1 )
249
- && state -> numfree [len - 1 ] < PyTuple_MAXFREELIST
241
+ && STATE . numfree [len - 1 ] < PyTuple_MAXFREELIST
250
242
&& Py_IS_TYPE (op , & PyTuple_Type ))
251
243
{
252
- op -> ob_item [0 ] = (PyObject * ) state -> free_list [len - 1 ];
253
- state -> numfree [len - 1 ]++ ;
254
- state -> free_list [len - 1 ] = op ;
244
+ op -> ob_item [0 ] = (PyObject * ) STATE . free_list [len - 1 ];
245
+ STATE . numfree [len - 1 ]++ ;
246
+ STATE . free_list [len - 1 ] = op ;
255
247
goto done ; /* return */
256
248
}
257
249
#endif
@@ -1026,11 +1018,10 @@ void
1026
1018
_PyTuple_ClearFreeList (PyInterpreterState * interp )
1027
1019
{
1028
1020
#if PyTuple_MAXSAVESIZE > 0
1029
- struct _Py_tuple_state * state = & interp -> tuple ;
1030
1021
for (Py_ssize_t i = 1 ; i < PyTuple_MAXSAVESIZE ; i ++ ) {
1031
- PyTupleObject * p = state -> free_list [i - 1 ];
1032
- state -> free_list [i - 1 ] = NULL ;
1033
- state -> numfree [i - 1 ] = 0 ;
1022
+ PyTupleObject * p = STATE . free_list [i - 1 ];
1023
+ STATE . free_list [i - 1 ] = NULL ;
1024
+ STATE . numfree [i - 1 ] = 0 ;
1034
1025
while (p ) {
1035
1026
PyTupleObject * q = p ;
1036
1027
p = (PyTupleObject * )(p -> ob_item [0 ]);
0 commit comments