8000 gh-99955: standardize return values of functions in assembler and optimizer. by iritkatriel · Pull Request #99956 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99955: standardize return values of functions in assembler and optimizer. #99956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge_const_one returns -1/0
  • Loading branch information
iritkatriel committed Dec 2, 2022
commit 3056e230f402b69356ada734f7723b670df9312e
22 changes: 11 additions & 11 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8282,17 +8282,17 @@ merge_const_one(PyObject *const_cache, PyObject **obj)
PyDict_CheckExact(const_cache);
PyObject *key = _PyCode_ConstantKey(*obj);
if (key == NULL) {
return 0;
return -1;
}

// t is borrowed reference
PyObject *t = PyDict_SetDefault(const_cache, key, key);
Py_DECREF(key);
if (t == NULL) {
return 0;
return -1;
}
if (t == key) { // obj is new constant.
return 1;
return 0;
}

if (PyTuple_CheckExact(t)) {
Expand All @@ -8301,7 +8301,7 @@ merge_const_one(PyObject *const_cache, PyObject **obj)
}

Py_SETREF(*obj, Py_NewRef(t));
return 1;
return 0;
}

// This is in codeobject.c.
Expand Down Expand Up @@ -8367,15 +8367,15 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
if (!names) {
goto error;
}
if (!merge_const_one(c->c_const_cache, &names)) {
if (merge_const_one(c->c_const_cache, &names) < 0) {
goto error;
}

consts = PyList_AsTuple(constslist); /* PyCode_New requires a tuple */
if (consts == NULL) {
goto error;
}
if (!merge_const_one(c->c_const_cache, &consts)) {
if (merge_const_one(c->c_const_cache, &consts) < 0) {
goto error;
}

Expand Down Expand Up @@ -8426,7 +8426,7 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
goto error;
}

if (!merge_const_one(c->c_const_cache, &localsplusnames)) {
if (merge_const_one(c->c_const_cache, &localsplusnames) < 0) {
goto error;
}
con.localsplusnames = localsplusnames;
Expand Down Expand Up @@ -8916,21 +8916,21 @@ assemble(struct compiler *c, int addNone)
if (_PyBytes_Resize(&a.a_except_table, a.a_except_table_off) < 0) {
goto error;
}
if (!merge_const_one(c->c_const_cache, &a.a_except_table)) {
if (merge_const_one(c->c_const_cache, &a.a_except_table) < 0) {
goto error;
}

if (_PyBytes_Resize(&a.a_linetable, a.a_location_off) < 0) {
goto error;
}
if (!merge_const_one(c->c_const_cache, &a.a_linetable)) {
if (merge_const_one(c->c_const_cache, &a.a_linetable) < 0) {
goto error;
}

if (_PyBytes_Resize(&a.a_bytecode, a.a_offset * sizeof(_Py_CODEUNIT)) < 0) {
goto error;
}
if (!merge_const_one(c->c_const_cache, &a.a_bytecode)) {
if 6ACB (merge_const_one(c->c_const_cache, &a.a_bytecode) < 0) {
goto error;
}

Expand Down Expand Up @@ -8995,7 +8995,7 @@ fold_tuple_on_constants(PyObject *const_cache,
}
PyTuple_SET_ITEM(newconst, i, constant);
}
if (merge_const_one(const_cache, &newconst) == 0) {
if (merge_const_one(const_cache, &newconst) < 0) {
Py_DECREF(newconst);
return -1;
}
Expand Down
0