Skip to content

Commit 085c1d7

Browse files
Fix last few remaining problems
1 parent 9ac430d commit 085c1d7

File tree

10 files changed

+62
-80
lines changed

10 files changed

+62
-80
lines changed

Include/internal/pycore_ceval.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, Py
303303
PyAPI_FUNC(void) _PyEval_MonitorRaise(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
304304
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, _PyStackRef *sp);
305305
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
306-
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyStackRef *input, Py_ssize_t nargs, PyObject **scratch);
306+
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyStackRef *restrict input, Py_ssize_t nargs, PyObject **restrict scratch);
307307

308308
PyAPI_FUNC(void) _PyObjectArray_Free(PyObject **array, PyObject **scratch);
309309

@@ -391,6 +391,9 @@ _PyForIter_VirtualIteratorNext(PyThreadState* tstate, struct _PyInterpreterFrame
391391
#define SPECIAL___AEXIT__ 3
392392
#define SPECIAL_MAX 3
393393

394+
/* Special counterparts of ceval functions for performance reasons */
395+
PyAPI_FUNC(int) _PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result);
396+
394397
#ifdef __cplusplus
395398
}
396399
#endif

Include/internal/pycore_dict.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ _PyDict_NotifyEvent(PyInterpreterState *interp,
290290
extern PyDictObject *_PyObject_MaterializeManagedDict(PyObject *obj);
291291

292292
PyAPI_FUNC(PyObject *)_PyDict_FromItems(
293-
PyObject *const *keys, Py_ssize_t keys_offset,
294-
PyObject *const *values, Py_ssize_t values_offset,
293+
PyObject *const *restrict keys, Py_ssize_t keys_offset,
294+
PyObject *const *restrict values, Py_ssize_t values_offset,
295295
Py_ssize_t length);
296296

297297
static inline uint8_t *

Include/internal/pycore_unicodeobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ PyAPI_FUNC(PyObject*) _PyUnicode_TransformDecimalAndSpaceToASCII(
206206
/* --- Methods & Slots ---------------------------------------------------- */
207207

208208
PyAPI_FUNC(PyObject*) _PyUnicode_JoinArray(
209-
PyObject *separator,
210-
PyObject *const *items,
209+
PyObject *restrict separator,
210+
PyObject *const *restrict items,
211211
Py_ssize_t seqlen
212212
);
213213

Include/pyport.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,13 @@ extern "C" {
385385
# define Py_NO_INLINE
386386
#endif
387387

388-
// Any function annotated with this MUST not modify global state.
389-
// It can only modify state referenced by its parameters.
390-
// This is useful for optimizations on certain compilers.
391-
// Please see https://learn.microsoft.com/en-us/cpp/cpp/noalias
392-
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
393-
# define Py_NOALIAS
394-
#elif defined(_MSC_VER)
395-
# define Py_NOALIAS __declspec(noalias)
388+
#if defined(_MSC_VER) && Py_TAIL_CALL_INTERP
389+
# define Py_NO_INLINE_MSVC_TAILCALL Py_NO_INLINE
396390
#else
397-
# define Py_NOALIAS
391+
# define Py_NO_INLINE_MSVC_TAILCALL
398392
#endif
399393

400-
// A no-op at compile time. Hints to the programmer
394+
// Just a scope. Hints to the programmer
401395
// That any local variable defined within this block MUST
402396
// not escape from the current definition.
403397
# define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE() {

Objects/abstract.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
224224
return 0;
225225
}
226226

227+
Py_NO_INLINE_MSVC_TAILCALL int
228+
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **restrict result)
229+
{
230+
return PyMapping_GetOptionalItem(obj, key, result);
231+
}
232+
227233
int
228234
PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
229235
{

Objects/dictobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,9 +2225,9 @@ _PyDict_NewPresized(Py_ssize_t minused)
22252225
return dict_new_presized(minused, false);
22262226
}
22272227

2228-
PyObject *
2229-
_PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
2230-
PyObject *const *values, Py_ssize_t values_offset,
2228+
Py_NO_INLINE_MSVC_TAILCALL PyObject *
2229+
_PyDict_FromItems(PyObject *const *restrict keys, Py_ssize_t keys_offset,
2230+
PyObject *const *restrict values, Py_ssize_t values_offset,
22312231
Py_ssize_t length)
22322232
{
22332233
bool unicode = true;

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10234,7 +10234,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
1023410234
}
1023510235

1023610236
PyObject *
10237-
_PyUnicode_JoinArray(PyObject *separator, PyObject *const *items, Py_ssize_t seqlen)
10237+
_PyUnicode_JoinArray(PyObject *restrict separator, PyObject *const *restrict items, Py_ssize_t seqlen)
1023810238
{
1023910239
PyObject *res = NULL; /* the result */
1024010240
PyObject *sep = NULL;

Python/bytecodes.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,8 @@ dummy_func(
15341534
}
15351535

15361536
inst(LOAD_BUILD_CLASS, ( -- bc)) {
1537-
PyObject *bc_o;
1538-
int err = PyMapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
1537+
PyObject *restrict bc_o;
1538+
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
15391539
ERROR_IF(err < 0);
15401540
if (bc_o == NULL) {
15411541
_PyErr_SetString(tstate, PyExc_NameError,
@@ -1738,8 +1738,8 @@ dummy_func(
17381738

17391739
inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
17401740
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
1741-
PyObject *v_o;
1742-
int err = PyMapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
1741+
PyObject *restrict v_o;
1742+
int err = _PyEval_Mapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
17431743
PyStackRef_CLOSE(mod_or_class_dict);
17441744
ERROR_IF(err < 0);
17451745
if (v_o == NULL) {
@@ -1762,11 +1762,11 @@ dummy_func(
17621762
else {
17631763
/* Slow-path if globals or builtins is not a dict */
17641764
/* namespace 1: globals */
1765-
int err = PyMapping_GetOptionalItem(GLOBALS(), name, &v_o);
1765+
int err = _PyEval_Mapping_GetOptionalItem(GLOBALS(), name, &v_o);
17661766
ERROR_IF(err < 0);
17671767
if (v_o == NULL) {
17681768
/* namespace 2: builtins */
1769-
int err = PyMapping_GetOptionalItem(BUILTINS(), name, &v_o);
1769+
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), name, &v_o);
17701770
ERROR_IF(err < 0);
17711771
if (v_o == NULL) {
17721772
_PyEval_FormatExcCheckArg(
@@ -1925,14 +1925,14 @@ dummy_func(
19251925
}
19261926

19271927
inst(LOAD_FROM_DICT_OR_DEREF, (class_dict_st -- value)) {
1928-
PyObject *value_o;
1928+
PyObject *restrict value_o;
19291929
PyObject *name;
19301930
PyObject *class_dict = PyStackRef_AsPyObjectBorrow(class_dict_st);
19311931

19321932
assert(class_dict);
19331933
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
19341934
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
1935-
int err = PyMapping_GetOptionalItem(class_dict, name, &value_o);
1935+
int err = _PyEval_Mapping_GetOptionalItem(class_dict, name, &value_o);
19361936
if (err < 0) {
19371937
ERROR_NO_POP();
19381938
}
@@ -2115,14 +2115,14 @@ dummy_func(
21152115
}
21162116

21172117
inst(SETUP_ANNOTATIONS, (--)) {
2118-
PyObject *ann_dict;
2118+
PyObject *restrict ann_dict;
21192119
if (LOCALS() == NULL) {
21202120
_PyErr_Format(tstate, PyExc_SystemError,
21212121
"no locals found when setting up annotations");
21222122
ERROR_IF(true);
21232123
}
21242124
/* check if __annotations__ in locals()... */
2125-
int err = PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
2125+
int err = _PyEval_Mapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
21262126
ERROR_IF(err < 0);
21272127
if (ann_dict == NULL) {
21282128
ann_dict = PyDict_New();
@@ -2289,18 +2289,13 @@ dummy_func(
22892289
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
22902290
PyTypeObject *cls = (PyTypeObject *)class;
22912291
int method_found = 0;
2292-
PyObject *attr_o = _PySuper_Lookup(cls, self, name,
2293-
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? &method_found : NULL);
2292+
PyObject *attr_o = _PySuper_Lookup(cls, self, name, NULL);
22942293
if (attr_o == NULL) {
22952294
ERROR_NO_POP();
22962295
}
2297-
if (method_found) {
2298-
self_or_null = self_st; // transfer ownership
2299-
DEAD(self_st);
2300-
} else {
2301-
PyStackRef_CLOSE(self_st);
2302-
self_or_null = PyStackRef_NULL;
2303-
}
2296+
PyStackRef_CLOSE(self_st);
2297+
self_or_null = PyStackRef_NULL;
2298+
23042299
DECREF_INPUTS();
23052300

23062301
attr = PyStackRef_FromPyObjectSteal(attr_o);

Python/executor_cases.c.h

Lines changed: 11 additions & 19 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: 15 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)