Skip to content

Commit

Permalink
pythongh-110319: Assert type_version != 0 before using it (python#112226
Browse files Browse the repository at this point in the history
)

- Ensure that `assert(type_version != 0);` always comes *before* using `type_version`

Also:
- In cases_generator, rename `-v` to from `--verbose` to `--viable`
  • Loading branch information
gvanrossum authored Nov 18, 2023
1 parent 43b1c33 commit eb3c94e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,8 +2026,8 @@ dummy_func(
DEOPT_IF(tstate->interp->eval_frame);

PyTypeObject *cls = Py_TYPE(owner);
DEOPT_IF(cls->tp_version_tag != type_version);
assert(type_version != 0);
DEOPT_IF(cls->tp_version_tag != type_version);
assert(Py_IS_TYPE(fget, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)fget;
assert(func_version != 0);
Expand All @@ -2049,8 +2049,8 @@ dummy_func(
assert((oparg & 1) == 0);
DEOPT_IF(tstate->interp->eval_frame);
PyTypeObject *cls = Py_TYPE(owner);
DEOPT_IF(cls->tp_version_tag != type_version);
assert(type_version != 0);
DEOPT_IF(cls->tp_version_tag != type_version);
assert(Py_IS_TYPE(getattribute, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)getattribute;
assert(func_version != 0);
Expand Down
4 changes: 2 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

arg_parser.add_argument(
"-v",
"--verbose",
"--viable",
help="Print list of non-viable uops and exit",
action="store_true",
)
Expand Down Expand Up @@ -871,7 +871,7 @@ def main() -> None:
a.analyze() # Prints messages and sets a.errors on failure
if a.errors:
sys.exit(f"Found {a.errors} errors")
if args.verbose:
if args.viable:
# Load execution counts from bmraw.json, if it exists
a.report_non_viable_uops("bmraw.json")
return
Expand Down

0 comments on commit eb3c94e

Please sign in to comment.