-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-43693: Turn localspluskinds into an object #26749
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
Changes from 6 commits
da37894
7564dbe
32cc42e
9e54613
e5b413e
00954ec
4fba934
ebaaeca
b09738c
703727c
a64057a
0ff4466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,6 +359,7 @@ def _write_atomic(path, data, mode=0o666): | |
# Python 3.11a1 3454 (compute cell offsets relative to locals bpo-43693) | ||
# Python 3.11a1 3455 (add MAKE_CELL bpo-43693) | ||
# Python 3.11a1 3456 (interleave cell args bpo-43693) | ||
# Python 3.11a1 3457 (Change localsplus to a bytes object bpo-43693) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we're not using up too many magic numbers during pre-alpha... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are our options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Going back to the first magic number for 3.11a1. Everything is for the same bpo issue it seems. |
||
|
||
# | ||
# MAGIC must change whenever the bytecode emitted by the compiler may no | ||
|
@@ -368,7 +369,7 @@ def _write_atomic(path, data, mode=0o666): | |
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array | ||
# in PC/launcher.c must also be updated. | ||
|
||
MAGIC_NUMBER = (3456).to_bytes(2, 'little') + b'\r\n' | ||
MAGIC_NUMBER = (3457).to_bytes(2, 'little') + b'\r\n' | ||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c | ||
|
||
_PYCACHE = '__pycache__' | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7186,14 +7186,16 @@ merge_const_one(struct compiler *c, PyObject **obj) | |||||||||
} | ||||||||||
|
||||||||||
// This is in codeobject.c. | ||||||||||
extern void _Py_set_localsplus_info(int, PyObject *, _PyLocalsPlusKind, | ||||||||||
PyObject *, _PyLocalsPlusKinds); | ||||||||||
extern void _Py_set_localsplus_info(int, PyObject *, unsigned char, | ||||||||||
ericsnowcurrently marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
PyObject *, PyObject *); | ||||||||||
|
||||||||||
static void | ||||||||||
compute_localsplus_info(struct compiler *c, int nlocalsplus, | ||||||||||
PyObject *names, _PyLocalsPlusKinds kinds) | ||||||||||
static PyObject * | ||||||||||
compute_localsplus_info(struct compiler *c, PyObject *names) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems strange to pass one in and return the other. Perhaps create both in this function?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and something like "init_localsplus_info" is probably a better name with the shift in responsibility for this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I find the C idiom for returning multiple values pretty awkward, so I'll just allocate both before passing them into the function. |
||||||||||
{ | ||||||||||
assert(PyTuple_GET_SIZE(names) == nlocalsplus); | ||||||||||
Py_ssize_t nlocalsplus = PyTuple_GET_SIZE(names); | ||||||||||
PyObject *kinds = PyBytes_FromStringAndSize(NULL, nlocalsplus); | ||||||||||
if (kinds == NULL) | ||||||||||
return NULL; | ||||||||||
|
||||||||||
PyObject *k, *v; | ||||||||||
Py_ssize_t pos = 0; | ||||||||||
|
@@ -7202,7 +7204,7 @@ compute_localsplus_info(struct compiler *c, int nlocalsplus, | |||||||||
assert(offset >= 0); | ||||||||||
assert(offset < nlocalsplus); | ||||||||||
// For now we do not distinguish arg kinds. | ||||||||||
_PyLocalsPlusKind kind = CO_FAST_LOCAL; | ||||||||||
_PyLocals_Kind kind = CO_FAST_LOCAL; | ||||||||||
if (PyDict_GetItem(c->u->u_cellvars, k) != NULL) { | ||||||||||
kind |= CO_FAST_CELL; | ||||||||||
} | ||||||||||
|
@@ -7234,6 +7236,8 @@ compute_localsplus_info(struct compiler *c, int nlocalsplus, | |||||||||
assert(offset < nlocalsplus); | ||||||||||
_Py_set_localsplus_info(offset, k, CO_FAST_FREE, names, kinds); | ||||||||||
} | ||||||||||
|
||||||||||
return kinds; | ||||||||||
} | ||||||||||
|
||||||||||
static PyCodeObject * | ||||||||||
|
@@ -7244,7 +7248,7 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist, | |||||||||
PyObject *names = NULL; | ||||||||||
PyObject *consts = NULL; | ||||||||||
PyObject *localsplusnames = NULL; | ||||||||||
_PyLocalsPlusKinds localspluskinds = NULL; | ||||||||||
PyObject *localspluskinds = NULL; | ||||||||||
PyObject *name = NULL; | ||||||||||
|
||||||||||
names = dict_keys_inorder(c->u->u_names, 0); | ||||||||||
|
@@ -7280,10 +7284,10 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist, | |||||||||
if (localsplusnames == NULL) { | ||||||||||
goto error; | ||||||||||
} | ||||||||||
if (_PyCode_InitLocalsPlusKinds(nlocalsplus, &localspluskinds) < 0) { | ||||||||||
localspluskinds = compute_localsplus_info(c, localsplusnames); | ||||||||||
if (localspluskinds == NULL) { | ||||||||||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
goto error; | ||||||||||
} | ||||||||||
compute_localsplus_info(c, nlocalsplus, localsplusnames, localspluskinds); | ||||||||||
|
||||||||||
struct _PyCodeConstructor con = { | ||||||||||
.filename = c->c_filename, | ||||||||||
|
@@ -7314,7 +7318,6 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist, | |||||||||
} | ||||||||||
|
||||||||||
if (!merge_const_one(c, &localsplusnames)) { | ||||||||||
_PyCode_ClearLocalsPlusKinds(con.localspluskinds); | ||||||||||
goto error; | ||||||||||
} | ||||||||||
con.localsplusnames = localsplusnames; | ||||||||||
|
@@ -7324,13 +7327,11 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist, | |||||||||
goto error; | ||||||||||
} | ||||||||||
|
||||||||||
localspluskinds = NULL; // This keeps it from getting freed below. | ||||||||||
|
||||||||||
error: | ||||||||||
Py_XDECREF(names); | ||||||||||
Py_XDECREF(consts); | ||||||||||
Py_XDECREF(localsplusnames); | ||||||||||
_PyCode_ClearLocalsPlusKinds(localspluskinds); | ||||||||||
Py_XDECREF(localspluskinds); | ||||||||||
Py_XDECREF(name); | ||||||||||
return co; | ||||||||||
} | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.