Skip to content

Commit 35e96c1

Browse files
Make the restrict MSVC only for now
1 parent acf48f5 commit 35e96c1

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 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(_PyThreadStateImpl *_tstate, _PyStackRef *restrict input, Py_ssize_t nargs);
306+
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *input, Py_ssize_t nargs);
307307

308308
PyAPI_FUNC(void) _PyObjectArray_Free(_PyThreadStateImpl *_tstate, PyObject **array, Py_ssize_t nargs, PyObject **temp_arr);
309309

Include/pyport.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,18 @@ extern "C" {
385385
# define Py_NO_INLINE
386386
#endif
387387

388-
#if defined(_MSC_VER) && Py_TAIL_CALL_INTERP
388+
#if defined(_MSC_VER) && !defined(__clang__) && Py_TAIL_CALL_INTERP
389389
# define Py_NO_INLINE_MSVC_TAILCALL Py_NO_INLINE
390390
#else
391391
# define Py_NO_INLINE_MSVC_TAILCALL
392392
#endif
393393

394+
#if defined(_MSC_VER) && !defined(__clang__)
395+
# define Py_MSVC_RESTRICT restrict
396+
#else
397+
# define Py_MSVC_RESTRICT
398+
#endif
399+
394400
// Just a scope. Hints to the programmer
395401
// That any local variable defined within this block MUST
396402
// not escape from the current definition.

Objects/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
225225
}
226226

227227
Py_NO_INLINE_MSVC_TAILCALL int
228-
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **restrict result)
228+
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **Py_MSVC_RESTRICT result)
229229
{
230230
return PyMapping_GetOptionalItem(obj, key, result);
231231
}

Python/bytecodes.c

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

15361536
inst(LOAD_BUILD_CLASS, ( -- bc)) {
1537-
PyObject *restrict bc_o;
1537+
PyObject *Py_MSVC_RESTRICT bc_o;
15381538
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
15391539
ERROR_IF(err < 0);
15401540
if (bc_o == NULL) {
@@ -1738,7 +1738,7 @@ 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 *restrict v_o;
1741+
PyObject *Py_MSVC_RESTRICT v_o;
17421742
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);
@@ -1925,7 +1925,7 @@ dummy_func(
19251925
}
19261926

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

@@ -2115,7 +2115,7 @@ dummy_func(
21152115
}
21162116

21172117
inst(SETUP_ANNOTATIONS, (--)) {
2118-
PyObject *restrict ann_dict;
2118+
PyObject *Py_MSVC_RESTRICT ann_dict;
21192119
if (LOCALS() == NULL) {
21202120
_PyErr_Format(tstate, PyExc_SystemError,
21212121
"no locals found when setting up annotations");
@@ -2228,7 +2228,7 @@ dummy_func(
22282228
// handle any case whose performance we care about
22292229
PyObject *super;
22302230
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
2231-
PyObject *restrict stack[] = {class, self};
2231+
PyObject *Py_MSVC_RESTRICT stack[] = {class, self};
22322232
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
22332233
Py_END_LOCALS_MUST_NOT_ESCAPE();
22342234
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
@@ -2295,7 +2295,7 @@ dummy_func(
22952295
}
22962296
PyStackRef_CLOSE(self_st);
22972297
self_or_null = PyStackRef_NULL;
2298-
2298+
22992299
DECREF_INPUTS();
23002300

23012301
attr = PyStackRef_FromPyObjectSteal(attr_o);
@@ -3509,7 +3509,7 @@ dummy_func(
35093509
(void)lasti; // Shut up compiler warning if asserts are off
35103510
PyObject* res_o;
35113511
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
3512-
PyObject *restrict stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
3512+
PyObject *Py_MSVC_RESTRICT stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
35133513
int has_self = !PyStackRef_IsNull(exit_self);
35143514
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
35153515
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ extern void _PyUOpPrint(const _PyUOpInstruction *uop);
945945

946946

947947
PyObject **
948-
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *input, Py_ssize_t nargs)
948+
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *Py_MSVC_RESTRICT input, Py_ssize_t nargs)
949949
{
950950
PyObject **result;
951951
/* +1 because vectorcall might use -1 to write self */

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)