Skip to content

Commit e699d40

Browse files
Reduce number of restricts
Co-Authored-By: Chris Eibl <[email protected]>
1 parent 50f8ff7 commit e699d40

File tree

8 files changed

+38
-40
lines changed

8 files changed

+38
-40
lines changed

Include/pyport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ extern "C" {
400400
// Just a scope. Hints to the programmer
401401
// That any local variable defined within this block MUST
402402
// not escape from the current definition.
403-
# define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE() {
404-
# define Py_END_LOCALS_MUST_NOT_ESCAPE() }
403+
# define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE {
404+
# define Py_END_LOCALS_MUST_NOT_ESCAPE }
405405

406406
#include "exports.h"
407407

Objects/dictobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,8 @@ _PyDict_NewPresized(Py_ssize_t minused)
22262226
}
22272227

22282228
Py_NO_INLINE_MSVC_TAILCALL PyObject *
2229-
_PyDict_FromItems(PyObject *const *Py_MSVC_RESTRICT keys, Py_ssize_t keys_offset,
2230-
PyObject *const *Py_MSVC_RESTRICT values, Py_ssize_t values_offset,
2229+
_PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
2230+
PyObject *const *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
@@ -10068,7 +10068,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
1006810068
}
1006910069

1007010070
PyObject *
10071-
_PyUnicode_JoinArray(PyObject *Py_MSVC_RESTRICT separator, PyObject *const *Py_MSVC_RESTRICT items, Py_ssize_t seqlen)
10071+
_PyUnicode_JoinArray(PyObject *separator, PyObject *const *items, Py_ssize_t seqlen)
1007210072
{
1007310073
PyObject *res = NULL; /* the result */
1007410074
PyObject *sep = NULL;

Python/bytecodes.c

Lines changed: 13 additions & 13 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 *Py_MSVC_RESTRICT bc_o;
1537+
PyObject *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 *Py_MSVC_RESTRICT v_o;
1741+
PyObject *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 *Py_MSVC_RESTRICT value_o;
1928+
PyObject *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 *Py_MSVC_RESTRICT ann_dict;
2118+
PyObject *ann_dict;
21192119
if (LOCALS() == NULL) {
21202120
_PyErr_Format(tstate, PyExc_SystemError,
21212121
"no locals found when setting up annotations");
@@ -2227,10 +2227,10 @@ dummy_func(
22272227
// we make no attempt to optimize here; specializations should
22282228
// handle any case whose performance we care about
22292229
PyObject *super;
2230-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
2231-
PyObject *Py_MSVC_RESTRICT stack[] = {class, self};
2232-
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
2233-
Py_END_LOCALS_MUST_NOT_ESCAPE();
2230+
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
2231+
PyObject *Py_MSVC_RESTRICT stack[] = {class, self};
2232+
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
2233+
Py_END_LOCALS_MUST_NOT_ESCAPE;
22342234
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
22352235
PyObject *arg = oparg & 2 ? class : &_PyInstrumentation_MISSING;
22362236
if (super == NULL) {
@@ -2290,11 +2290,11 @@ dummy_func(
22902290
PyTypeObject *cls = (PyTypeObject *)class;
22912291
int method_found = 0;
22922292
PyObject *attr_o;
2293-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
2293+
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
22942294
int *Py_MSVC_RESTRICT method_found_ptr = &method_found;
22952295
attr_o = _PySuper_Lookup(cls, self, name,
2296-
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
2297-
Py_END_LOCALS_MUST_NOT_ESCAPE();
2296+
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
2297+
Py_END_LOCALS_MUST_NOT_ESCAPE;
22982298
if (attr_o == NULL) {
22992299
ERROR_NO_POP();
23002300
}
@@ -3518,12 +3518,12 @@ dummy_func(
35183518
assert(PyStackRef_IsTaggedInt(lasti));
35193519
(void)lasti; // Shut up compiler warning if asserts are off
35203520
PyObject* res_o;
3521-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
3521+
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
35223522
PyObject *Py_MSVC_RESTRICT stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
35233523
int has_self = !PyStackRef_IsNull(exit_self);
35243524
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
35253525
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
3526-
Py_END_LOCALS_MUST_NOT_ESCAPE();
3526+
Py_END_LOCALS_MUST_NOT_ESCAPE;
35273527
Py_XDECREF(original_tb);
35283528
ERROR_IF(res_o == NULL);
35293529
res = PyStackRef_FromPyObjectSteal(res_o);

Python/ceval.c

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

957957

958958
PyObject **
959-
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *Py_MSVC_RESTRICT input, Py_ssize_t nargs)
959+
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *restrict input, Py_ssize_t nargs)
960960
{
961961
PyObject **result;
962962
/* +1 because vectorcall might use -1 to write self */

Python/executor_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.

Python/generated_cases.c.h

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

Tools/cases_generator/analyzer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
692692
"PyStackRef_Wrap",
693693
"PyStackRef_Unwrap",
694694
"_PyLong_CheckExactAndCompact",
695-
"Py_BEGIN_LOCALS_MUST_NOT_ESCAPE",
696-
"Py_END_LOCALS_MUST_NOT_ESCAPE",
697695
)
698696

699697

0 commit comments

Comments
 (0)