Skip to content

Commit 50c92d0

Browse files
Merge remote-tracking branch 'upstream/main' into stackref_all
2 parents 4074bc3 + c878767 commit 50c92d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+439
-326
lines changed

Include/Python.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,5 @@
132132
#include "fileutils.h"
133133
#include "cpython/pyfpe.h"
134134
#include "cpython/tracemalloc.h"
135-
#include "cpython/optimizer.h"
136135

137136
#endif /* !Py_PYTHON_H */

Include/cpython/code.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,6 @@ typedef struct _Py_GlobalMonitors {
2424
uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
2525
} _Py_GlobalMonitors;
2626

27-
typedef struct {
28-
union {
29-
struct {
30-
uint16_t backoff : 4;
31-
uint16_t value : 12;
32-
};
33-
uint16_t as_counter; // For printf("%#x", ...)
34-
};
35-
} _Py_BackoffCounter;
36-
37-
/* Each instruction in a code object is a fixed-width value,
38-
* currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG
39-
* opcode allows for larger values but the current limit is 3 uses
40-
* of EXTENDED_ARG (see Python/compile.c), for a maximum
41-
* 32-bit value. This aligns with the note in Python/compile.c
42-
* (compiler_addop_i_line) indicating that the max oparg value is
43-
* 2**32 - 1, rather than INT_MAX.
44-
*/
45-
46-
typedef union {
47-
uint16_t cache;
48-
struct {
49-
uint8_t code;
50-
uint8_t arg;
51-
} op;
52-
_Py_BackoffCounter counter; // First cache entry of specializable op
53-
} _Py_CODEUNIT;
54-
55-
56-
/* These macros only remain defined for compatibility. */
57-
#define _Py_OPCODE(word) ((word).op.code)
58-
#define _Py_OPARG(word) ((word).op.arg)
59-
60-
static inline _Py_CODEUNIT
61-
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
62-
{
63-
// No designated initialisers because of C++ compat
64-
_Py_CODEUNIT word;
65-
word.op.code = opcode;
66-
word.op.arg = oparg;
67-
return word;
68-
}
69-
70-
static inline void
71-
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
72-
{
73-
word->op.code = opcode;
74-
}
75-
76-
#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
77-
#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
78-
7927

8028
typedef struct {
8129
PyObject *_co_code;

Include/cpython/optimizer.h

Lines changed: 0 additions & 135 deletions
This file was deleted.

Include/cpython/pystate.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ struct _ts {
9797
#ifdef Py_BUILD_CORE
9898
# define _PyThreadState_WHENCE_NOTSET -1
9999
# define _PyThreadState_WHENCE_UNKNOWN 0
100-
# define _PyThreadState_WHENCE_INTERP 1
101-
# define _PyThreadState_WHENCE_THREADING 2
102-
# define _PyThreadState_WHENCE_GILSTATE 3
103-
# define _PyThreadState_WHENCE_EXEC 4
100+
# define _PyThreadState_WHENCE_INIT 1
101+
# define _PyThreadState_WHENCE_FINI 2
102+
# define _PyThreadState_WHENCE_THREADING 3
103+
# define _PyThreadState_WHENCE_GILSTATE 4
104+
# define _PyThreadState_WHENCE_EXEC 5
104105
#endif
105106
int _whence;
106107

Include/internal/pycore_backoff.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ extern "C" {
1313
#include <stdbool.h>
1414
#include <stdint.h>
1515

16+
17+
typedef struct {
18+
union {
19+
struct {
20+
uint16_t backoff : 4;
21+
uint16_t value : 12;
22+
};
23+
uint16_t as_counter; // For printf("%#x", ...)
24+
};
25+
} _Py_BackoffCounter;
26+
27+
1628
/* 16-bit countdown counters using exponential backoff.
1729
1830
These are used by the adaptive specializer to count down until

Include/internal/pycore_code.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@ extern "C" {
1010

1111
#include "pycore_stackref.h" // _PyStackRef
1212
#include "pycore_lock.h" // PyMutex
13+
#include "pycore_backoff.h" // _Py_BackoffCounter
14+
15+
16+
/* Each instruction in a code object is a fixed-width value,
17+
* currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG
18+
* opcode allows for larger values but the current limit is 3 uses
19+
* of EXTENDED_ARG (see Python/compile.c), for a maximum
20+
* 32-bit value. This aligns with the note in Python/compile.c
21+
* (compiler_addop_i_line) indicating that the max oparg value is
22+
* 2**32 - 1, rather than INT_MAX.
23+
*/
24+
25+
typedef union {
26+
uint16_t cache;
27+
struct {
28+
uint8_t code;
29+
uint8_t arg;
30+
} op;
31+
_Py_BackoffCounter counter; // First cache entry of specializable op
32+
} _Py_CODEUNIT;
33+
34+
35+
/* These macros only remain defined for compatibility. */
36+
#define _Py_OPCODE(word) ((word).op.code)
37+
#define _Py_OPARG(word) ((word).op.arg)
38+
39+
static inline _Py_CODEUNIT
40+
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
41+
{
42+
// No designated initialisers because of C++ compat
43+
_Py_CODEUNIT word;
44+
word.op.code = opcode;
45+
word.op.arg = oparg;
46+
return word;
47+
}
48+
49+
static inline void
50+
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
51+
{
52+
word->op.code = opcode;
53+
}
54+
55+
#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
56+
#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
1357

1458

1559
// We hide some of the newer PyCodeObject fields behind macros.

Include/internal/pycore_interp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#include "pycore_list.h" // struct _Py_list_state
3131
#include "pycore_mimalloc.h" // struct _mimalloc_interp_state
3232
#include "pycore_object_state.h" // struct _py_object_state
33+
#include "pycore_optimizer.h" // _PyOptimizerObject
3334
#include "pycore_obmalloc.h" // struct _obmalloc_state
3435
#include "pycore_qsbr.h" // struct _qsbr_state
3536
#include "pycore_tstate.h" // _PyThreadStateImpl

Include/internal/pycore_object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
126126
}
127127
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
128128

129-
extern void _Py_SetImmortal(PyObject *op);
130-
extern void _Py_SetImmortalUntracked(PyObject *op);
129+
PyAPI_FUNC(void) _Py_SetImmortal(PyObject *op);
130+
PyAPI_FUNC(void) _Py_SetImmortalUntracked(PyObject *op);
131131

132132
// Makes an immortal object mortal again with the specified refcnt. Should only
133133
// be used during runtime finalization.

0 commit comments

Comments
 (0)