]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118771: Ensure names defined in optimizer.h start with Py/_Py (GH-118825)
authorPetr Viktorin <encukou@gmail.com>
Fri, 10 May 2024 16:20:12 +0000 (18:20 +0200)
committerGitHub <noreply@github.com>
Fri, 10 May 2024 16:20:12 +0000 (18:20 +0200)
Include/cpython/optimizer.h
Include/internal/pycore_optimizer.h
Misc/NEWS.d/next/C API/2024-05-10-15-43-14.gh-issue-118771.5KVglT.rst [new file with mode: 0644]
Python/optimizer.c

index 5f218d75b346a02b5d29d77fb9d3df590745e353..f2093a1e5f6aa441014d617a8266b37fe21db417 100644 (file)
@@ -14,10 +14,10 @@ typedef struct _PyExecutorLinkListNode {
 
 /* Bloom filter with m = 256
  * https://en.wikipedia.org/wiki/Bloom_filter */
-#define BLOOM_FILTER_WORDS 8
+#define _Py_BLOOM_FILTER_WORDS 8
 
-typedef struct _bloom_filter {
-    uint32_t bits[BLOOM_FILTER_WORDS];
+typedef struct {
+    uint32_t bits[_Py_BLOOM_FILTER_WORDS];
 } _PyBloomFilter;
 
 typedef struct {
@@ -31,11 +31,6 @@ typedef struct {
     PyCodeObject *code;  // Weak (NULL if no corresponding ENTER_EXECUTOR).
 } _PyVMData;
 
-#define UOP_FORMAT_TARGET 0
-#define UOP_FORMAT_EXIT 1
-#define UOP_FORMAT_JUMP 2
-#define UOP_FORMAT_UNUSED 3
-
 /* Depending on the format,
  * the 32 bits between the oparg and operand are:
  * UOP_FORMAT_TARGET:
@@ -64,31 +59,7 @@ typedef struct {
     uint64_t operand;  // A cache entry
 } _PyUOpInstruction;
 
-static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
-{
-    assert(inst->format == UOP_FORMAT_TARGET);
-    return inst->target;
-}
-
-static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
-{
-    assert(inst->format == UOP_FORMAT_EXIT);
-    return inst->exit_index;
-}
-
-static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
-{
-    assert(inst->format == UOP_FORMAT_JUMP);
-    return inst->jump_target;
-}
-
-static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
-{
-    assert(inst->format != UOP_FORMAT_TARGET);
-    return inst->error_target;
-}
-
-typedef struct _exit_data {
+typedef struct {
     uint32_t target;
     _Py_BackoffCounter temperature;
     const struct _PyExecutorObject *executor;
@@ -109,14 +80,14 @@ typedef struct _PyExecutorObject {
 typedef struct _PyOptimizerObject _PyOptimizerObject;
 
 /* Should return > 0 if a new executor is created. O if no executor is produced and < 0 if an error occurred. */
-typedef int (*optimize_func)(
+typedef int (*_Py_optimize_func)(
     _PyOptimizerObject* self, struct _PyInterpreterFrame *frame,
     _Py_CODEUNIT *instr, _PyExecutorObject **exec_ptr,
     int curr_stackentries);
 
 struct _PyOptimizerObject {
     PyObject_HEAD
-    optimize_func optimize;
+    _Py_optimize_func optimize;
     /* Data needed by the optimizer goes here, but is opaque to the VM */
 };
 
index c0a76e85350541a551a8998f12951c939f13722a..c1148422c495b6fcd61734d32bf5e16c5742ceec 100644 (file)
@@ -35,6 +35,35 @@ struct _Py_UopsSymbol {
     PyObject *const_val;  // Owned reference (!)
 };
 
+#define UOP_FORMAT_TARGET 0
+#define UOP_FORMAT_EXIT 1
+#define UOP_FORMAT_JUMP 2
+#define UOP_FORMAT_UNUSED 3
+
+static inline uint32_t uop_get_target(const _PyUOpInstruction *inst)
+{
+    assert(inst->format == UOP_FORMAT_TARGET);
+    return inst->target;
+}
+
+static inline uint16_t uop_get_exit_index(const _PyUOpInstruction *inst)
+{
+    assert(inst->format == UOP_FORMAT_EXIT);
+    return inst->exit_index;
+}
+
+static inline uint16_t uop_get_jump_target(const _PyUOpInstruction *inst)
+{
+    assert(inst->format == UOP_FORMAT_JUMP);
+    return inst->jump_target;
+}
+
+static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
+{
+    assert(inst->format != UOP_FORMAT_TARGET);
+    return inst->error_target;
+}
+
 // Holds locals, stack, locals, stack ... co_consts (in that order)
 #define MAX_ABSTRACT_INTERP_SIZE 4096
 
diff --git a/Misc/NEWS.d/next/C API/2024-05-10-15-43-14.gh-issue-118771.5KVglT.rst b/Misc/NEWS.d/next/C API/2024-05-10-15-43-14.gh-issue-118771.5KVglT.rst
new file mode 100644 (file)
index 0000000..2ed8089
--- /dev/null
@@ -0,0 +1,3 @@
+Several C declarations with names that didn't start with the ``Py`` or ``_Py``
+prefixes, which were added by mistake in 3.13 alpha and beta releases, were
+moved to internal headers.
index 8be2c0ffbd78e91fe5c4385a0e0693f36d1c80f7..9ae99ccdaea2e7b2c9ec3f6b0b8935f97ef3d35c 100644 (file)
@@ -1237,7 +1237,7 @@ init_cold_exit_executor(_PyExecutorObject *executor, int oparg)
     inst->oparg = oparg;
     executor->vm_data.valid = true;
     executor->vm_data.linked = false;
-    for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
+    for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
         assert(executor->vm_data.bloom.bits[i] == 0);
     }
 #ifdef Py_DEBUG
@@ -1505,7 +1505,7 @@ address_to_hash(void *ptr) {
 void
 _Py_BloomFilter_Init(_PyBloomFilter *bloom)
 {
-    for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
+    for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
         bloom->bits[i] = 0;
     }
 }
@@ -1530,7 +1530,7 @@ _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *ptr)
 static bool
 bloom_filter_may_contain(_PyBloomFilter *bloom, _PyBloomFilter *hashes)
 {
-    for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
+    for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
         if ((bloom->bits[i] & hashes->bits[i]) != hashes->bits[i]) {
             return false;
         }
@@ -1591,7 +1591,7 @@ void
 _Py_ExecutorInit(_PyExecutorObject *executor, const _PyBloomFilter *dependency_set)
 {
     executor->vm_data.valid = true;
-    for (int i = 0; i < BLOOM_FILTER_WORDS; i++) {
+    for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
         executor->vm_data.bloom.bits[i] = dependency_set->bits[i];
     }
     link_executor(executor);