8000 remove unsafe ptr conversions · python/cpython@bca14a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit bca14a8

Browse files
remove unsafe ptr conversions
1 parent d86652f commit bca14a8

File tree

6 files changed

+34
-54
lines changed

6 files changed

+34
-54
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_stackref.h

Lines changed: 0 additions 8000 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ PyStackRef_To_PyObject_Borrow(_PyStackRef tagged)
4646
return cleared;
4747
}
4848

49-
// Gets a void * from a _PyStackRef
50-
// Functionally same as PyStackRef_To_PyObject_Borrow, but distinguishes
51-
// when something is a real PyObject or arbitrary pointer.
52-
static inline void *
53-
PyStackRef_To_PyPtr_Borrow(_PyStackRef tagged)
54-
{
55-
PyObject *cleared = ((PyObject *)((tagged).bits & (~Py_TAG)));
56-
return cleared;
57-
}
58-
5949

6050
// Converts a PyObject * to a PyStackRef, borrowing the reference.
6151
static inline _PyStackRef
@@ -78,16 +68,6 @@ _PyObject_To_StackRef_Steal(PyObject *obj)
7868
}
7969
#define PyObject_To_StackRef_Steal(obj) _PyObject_To_StackRef_Steal(_PyObject_CAST(obj))
8070

81-
// Same as _PyObject_To_StackRef_Steal but safe for arbitrary pointers as well.
82-
static inline _PyStackRef
83-
_PyPtr_To_StackRef_Steal(void *obj)
84-
{
85-
assert(((uintptr_t)obj & Py_TAG) == 0);
86-
return ((_PyStackRef){.bits = ((uintptr_t)(obj)) | Py_TAG_PTR});
87-
}
88-
#define PyPtr_To_StackRef_Steal(obj) _PyPtr_To_StackRef_Steal(obj)
89-
90-
9171
// Converts a PyObject * to a PyStackRef, with a new reference
9272
static inline _PyStackRef
9373
PyObject_To_StackRef_New(PyObject *obj)

Include/internal/pycore_uop_metadata.h

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,7 +3044,7 @@ dummy_func(
30443044
tstate->exc_info = &gen->gi_exc_state;
30453045
// oparg is the return offset from the next instruction.
30463046
frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
3047-
gen_frame = PyPtr_To_StackRef_Steal(gen_frame_o);
3047+
gen_frame = (_PyStackRef) { .bits = (uintptr_t)gen_frame_o };
30483048
}
30493049

30503050
macro(FOR_ITER_GEN) =
@@ -3445,7 +3445,7 @@ dummy_func(
34453445
if (new_frame_o == NULL) {
34463446
ERROR_NO_POP();
34473447
}
3448-
new_frame = PyPtr_To_StackRef_Steal(new_frame_o);
3448+
new_frame = (_PyStackRef) { .bits = (uintptr_t)new_frame_o };
34493449
}
34503450

34513451
op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
@@ -3581,13 +3581,13 @@ dummy_func(
35813581
for (int i = 0; i < oparg; i++) {
35823582
first_non_self_local[i] = args[i];
35833583
}
3584-
new_frame = PyPtr_To_StackRef_Steal(new_frame_o);
3584+
new_frame = (_PyStackRef) { .bits = (uintptr_t)new_frame_o };
35853585
}
35863586

35873587
op(_PUSH_FRAME, (new_frame -- )) {
35883588
// Write it out explicitly because it's subtly different.
35893589
// Eventually this should be the only occurrence of this code.
3590-
_PyInterpreterFrame *new_frame_o = (_PyInterpreterFrame *)PyStackRef_To_PyPtr_Borrow(new_frame);
3590+
_PyInterpreterFrame *new_frame_o = (_PyInterpreterFrame *)new_frame.bits;
35913591
assert(tstate->interp->eval_frame == NULL);
35923592
SYNC_SP();
35933593
_PyFrame_SetStackPointer(frame, stack_pointer);

Python/executor_cases.c.h

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 10 additions & 10 deletions
Some generated files ar 33E4 e not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0