Skip to content

Commit 941eea0

Browse files
authored
gh-118771: Ensure names defined in optimizer.h start with Py/_Py (GH-118825)
1 parent f772d0d commit 941eea0

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

Include/cpython/optimizer.h

+6-35
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ typedef struct _PyExecutorLinkListNode {
1414

1515
/* Bloom filter with m = 256
1616
* https://en.wikipedia.org/wiki/Bloom_filter */
17-
#define BLOOM_FILTER_WORDS 8
17+
#define _Py_BLOOM_FILTER_WORDS 8
1818

19-
typedef struct _bloom_filter {
20-
uint32_t bits[BLOOM_FILTER_WORDS];
19+
typedef struct {
20+
uint32_t bits[_Py_BLOOM_FILTER_WORDS];
2121
} _PyBloomFilter;
2222

2323
typedef struct {
@@ -31,11 +31,6 @@ typedef struct {
3131
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
3232
} _PyVMData;
3333

34-
#define UOP_FORMAT_TARGET 0
35-
#define UOP_FORMAT_EXIT 1
36-
#define UOP_FORMAT_JUMP 2
37-
#define UOP_FORMAT_UNUSED 3
38-
3934
/* Depending on the format,
4035
* the 32 bits between the oparg and operand are:
4136
* UOP_FORMAT_TARGET:
@@ -64,31 +59,7 @@ typedef struct {
6459
uint64_t operand; // A cache entry
6560
} _PyUOpInstruction;
6661

67-
static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
68-
{
69-
assert(inst->format == UOP_FORMAT_TARGET);
70-
return inst->target;
71-
}
72-
73-
static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
74-
{
75-
assert(inst->format == UOP_FORMAT_EXIT);
76-
return inst->exit_index;
77-
}
78-
79-
static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
80-
{
81-
assert(inst->format == UOP_FORMAT_JUMP);
82-
return inst->jump_target;
83-
}
84-
85-
static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
86-
{
87-
assert(inst->format != UOP_FORMAT_TARGET);
88-
return inst->error_target;
89-
}
90-
91-
typedef struct _exit_data {
62+
typedef struct {
9263
uint32_t target;
9364
_Py_BackoffCounter temperature;
9465
const struct _PyExecutorObject *executor;
@@ -109,14 +80,14 @@ typedef struct _PyExecutorObject {
10980
typedef struct _PyOptimizerObject _PyOptimizerObject;
11081

11182
/* Should return > 0 if a new executor is created. O if no executor is produced and < 0 if an error occurred. */
112-
typedef int (*optimize_func)(
83+
typedef int (*_Py_optimize_func)(
11384
_PyOptimizerObject* self, struct _PyInterpreterFrame *frame,
11485
_Py_CODEUNIT *instr, _PyExecutorObject **exec_ptr,
11586
int curr_stackentries);
11687

11788
struct _PyOptimizerObject {
11889
PyObject_HEAD
119-
optimize_func optimize;
90+
_Py_optimize_func optimize;
12091
/* Data needed by the optimizer goes here, but is opaque to the VM */
12192
};
12293

Include/internal/pycore_optimizer.h

+29
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ struct _Py_UopsSymbol {
3535
PyObject *const_val; // Owned reference (!)
3636
};
3737

38+
#define UOP_FORMAT_TARGET 0
39+
#define UOP_FORMAT_EXIT 1
40+
#define UOP_FORMAT_JUMP 2
41+
#define UOP_FORMAT_UNUSED 3
42+
43+
static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
44+
{
45+
assert(inst->format == UOP_FORMAT_TARGET);
46+
return inst->target;
47+
}
48+
49+
static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
50+
{
51+
assert(inst->format == UOP_FORMAT_EXIT);
52+
return inst->exit_index;
53+
}
54+
55+
static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
56+
{
57+
assert(inst->format == UOP_FORMAT_JUMP);
58+
return inst->jump_target;
59+
}
60+
61+
static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
62+
{
63+
assert(inst->format != UOP_FORMAT_TARGET);
64+
return inst->error_target;
65+
}
66+
3867
// Holds locals, stack, locals, stack ... co_consts (in that order)
3968
#define MAX_ABSTRACT_INTERP_SIZE 4096
4069

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Several C declarations with names that didn't start with the ``Py`` or ``_Py``
2+
prefixes, which were added by mistake in 3.13 alpha and beta releases, were
3+
moved to internal headers.

Python/optimizer.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ init_cold_exit_executor(_PyExecutorObject *executor, int oparg)
12371237
inst->oparg = oparg;
12381238
executor->vm_data.valid = true;
12391239
executor->vm_data.linked = false;
1240-
for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
1240+
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
12411241
assert(executor->vm_data.bloom.bits[i] == 0);
12421242
}
12431243
#ifdef Py_DEBUG
@@ -1505,7 +1505,7 @@ address_to_hash(void *ptr) {
15051505
void
15061506
_Py_BloomFilter_Init(_PyBloomFilter *bloom)
15071507
{
1508-
for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
1508+
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
15091509
bloom->bits[i] = 0;
15101510
}
15111511
}
@@ -1530,7 +1530,7 @@ _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *ptr)
15301530
static bool
15311531
bloom_filter_may_contain(_PyBloomFilter *bloom, _PyBloomFilter *hashes)
15321532
{
1533-
for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
1533+
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
15341534
if ((bloom->bits[i] & hashes->bits[i]) != hashes->bits[i]) {
15351535
return false;
15361536
}
@@ -1591,7 +1591,7 @@ void
15911591
_Py_ExecutorInit(_PyExecutorObject *executor, const _PyBloomFilter *dependency_set)
15921592
{
15931593
executor->vm_data.valid = true;
1594-
for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
1594+
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
15951595
executor->vm_data.bloom.bits[i] = dependency_set->bits[i];
15961596
}
15971597
link_executor(executor);

0 commit comments

Comments
 (0)