8000 address all of Mark's review · python/cpython@64b237c · GitHub
[go: up one dir, main page]

Skip to content

Commit 64b237c

Browse files
address all of Mark's review
1 parent 88e0ea8 commit 64b237c

16 files changed

+4646
-4708
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ PyAPI_FUNC(void) _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *c
254254
PyAPI_FUNC(void) _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
255255
PyAPI_FUNC(PyObject *)_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
256256
PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
257-
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, _PyStackRef *sp);
257+
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v, int argcnt, int argcntafter, _PyStackRef *sp);
258258
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
259259

260260

Include/internal/pycore_code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ extern void _PyCode_Clear_Executors(PyCodeObject *code);
274274

275275
/* Specialization functions */
276276

277-
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
277+
extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef cls,
278278
_Py_CODEUNIT *instr, int load_method);
279279
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
280280
PyObject *name);
@@ -294,9 +294,9 @@ extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
294294
_Py_CODEUNIT *instr, int oparg);
295295
extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
296296
int oparg);
297-
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg);
297+
extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int oparg);
298298
extern void _Py_Specialize_Send(PyObject *receiver, _Py_CODEUNIT *instr);
299-
extern void _Py_Specialize_ToBool(PyObject *value, _Py_CODEUNIT *instr);
299+
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
300300
extern void _Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr);
301301

302302
#ifdef Py_STATS

Include/internal/pycore_opcode_metadata.h

Lines changed: 45 additions & 45 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: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@ 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+
}
4958

50-
// Converts a PyObject * to a PyStackRef, stealing the reference.
59+
60+
// Converts a PyObject * to a PyStackRef, borrowing the reference.
5161
static inline _PyStackRef
5262
_PyObject_To_StackRef_Borrow(PyObject *obj)
5363
{
@@ -58,6 +68,26 @@ _PyObject_To_StackRef_Borrow(PyObject *obj)
5868
}
5969
#define PyObject_To_StackRef_Borrow(obj) _PyObject_To_StackRef_Borrow(_PyObject_CAST(obj))
6070

71+
// Steals the reference, invalidating the old one.
72+
// For now, behaves the same as borrow, but will be changed in a future PR.
73+
// TODO in gh-117139.
74+
static inline _PyStackRef
75+
_PyObject_To_StackRef_Steal(PyObject *obj)
76+
{
77+
return PyObject_To_StackRef_Borrow(obj);
78+
}
79+
#define PyObject_To_StackRef_Steal(obj) _PyObject_To_StackRef_Steal(_PyObject_CAST(obj))
80+
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+
6191
// Converts a PyObject * to a PyStackRef, with a new reference
6292
static inline _PyStackRef
6393
PyObject_To_StackRef_New(PyObject *obj)
@@ -76,7 +106,8 @@ PyObject_To_StackRef_New(PyObject *obj)
76106
#define PyObject_To_StackRef_New(obj) PyObject_To_StackRef_New(_PyObject_CAST(obj))
77107

78108

79-
// Converts a PyStackRef back to a PyObject *.
109+
// Converts a PyStackRef back to a PyObject *, converting deferred references
110+
// to new references.
80111
static inline PyObject *
81112
PyStackRef_To_PyObject_New(_PyStackRef tagged)
82113
{
@@ -125,7 +156,7 @@ _Py_untag_stack_steal(PyObject **dst, const _PyStackRef *src, size_t length)
125156
do { \
126157
_PyStackRef *_tmp_op_ptr = &(op); \
127158
_PyStackRef _tmp_old_op = (*_tmp_op_ptr); \
128-
if (_tmp_old_op.bits != Py_STACKREF_NULL.bits) { \
159+
if (!PyStackRef_IsNull(_tmp_old_op)) { \
129160
*_tmp_op_ptr = Py_STACKREF_NULL; \
130161
PyStackRef_DECREF(_tmp_old_op); \
131162
} \
5169

Include/internal/pycore_uop_metadata.h

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

0 commit comments

Comments
 (0)
0