Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
da378947564dbe32cc42e9e54613e5b413e00954ec4fba934ebaaecab09738c703727ca64057a0ff4466File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -156,16 +156,16 @@ validate_and_copy_tuple(PyObject *tup) | ||
| // This is also used in compile.c. | ||
| void | ||
| _Py_set_localsplus_info(int offset, PyObject *name, _PyLocalsPlusKind kind, | ||
| PyObject *names, _PyLocalsPlusKinds kinds) | ||
| _Py_set_localsplus_info(int offset, PyObject *name, _PyLocals_Kind kind, | ||
| PyObject *names, PyObject *kinds) | ||
| { | ||
| Py_INCREF(name); | ||
| PyTuple_SET_ITEM(names, offset, name); | ||
| kinds[offset] = kind; | ||
| _PyLocals_SetKind(kinds, offset, kind); | ||
| } | ||
| static void | ||
| get_localsplus_counts(PyObject *names, _PyLocalsPlusKinds kinds, | ||
| get_localsplus_counts(PyObject *names, PyObject *kinds, | ||
| int *pnlocals, int *pnplaincellvars, int *pncellvars, | ||
| int *pnfreevars) | ||
| { | ||
| @@ -175,17 +175,18 @@ get_localsplus_counts(PyObject *names, _PyLocalsPlusKinds kinds, | ||
| int nfreevars = 0; | ||
| Py_ssize_t nlocalsplus = PyTuple_GET_SIZE(names); | ||
| for (int i = 0; i < nlocalsplus; i++){ | ||
| if (kinds[i] & CO_FAST_LOCAL){ | ||
| _PyLocals_Kind kind = _PyLocals_GetKind(kinds, i); | ||
| if (kind & CO_FAST_LOCAL){ | ||
| nlocals += 1; | ||
| if (kinds[i] & CO_FAST_CELL){ | ||
| if (kind & CO_FAST_CELL){ | ||
| ncellvars += 1; | ||
| } | ||
| } | ||
| else if (kinds[i] & CO_FAST_CELL){ | ||
| else if (kind & CO_FAST_CELL){ | ||
| ncellvars += 1; | ||
| nplaincellvars += 1; | ||
| } | ||
| else if (kinds[i] & CO_FAST_FREE){ | ||
| else if (kind & CO_FAST_FREE){ | ||
| nfreevars += 1; | ||
| } | ||
| } | ||
| @@ -204,15 +205,16 @@ get_localsplus_counts(PyObject *names, _PyLocalsPlusKinds kinds, | ||
| } | ||
| static PyObject * | ||
| get_localsplus_names(PyCodeObject *co, _PyLocalsPlusKind kind, int num) | ||
| get_localsplus_names(PyCodeObject *co, _PyLocals_Kind kind, int num) | ||
| { | ||
| PyObject *names = PyTuple_New(num); | ||
| if (names == NULL){ | ||
| return NULL; | ||
| } | ||
| int index = 0; | ||
| for (int offset = 0; offset < co->co_nlocalsplus; offset++){ | ||
| if ((co->co_localspluskinds[offset] & kind) == 0){ | ||
| _PyLocals_Kind k = _PyLocals_GetKind(co->co_localspluskinds, offset); | ||
| if ((k & kind) == 0){ | ||
| continue; | ||
| } | ||
| assert(index < num); | ||
| @@ -236,8 +238,9 @@ _PyCode_Validate(struct _PyCodeConstructor *con) | ||
| con->consts == NULL || !PyTuple_Check(con->consts) || | ||
| con->names == NULL || !PyTuple_Check(con->names) || | ||
| con->localsplusnames == NULL || !PyTuple_Check(con->localsplusnames) || | ||
| (PyTuple_GET_SIZE(con->localsplusnames) && con->localspluskinds == NULL) || | ||
| (!PyTuple_GET_SIZE(con->localsplusnames) && con->localspluskinds != NULL) || | ||
| con->localspluskinds == NULL || !PyBytes_Check(con->localspluskinds) || | ||
ericsnowcurrently marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| PyTuple_GET_SIZE(con->localsplusnames) | ||
| != PyBytes_GET_SIZE(con->localspluskinds) || | ||
| con->name == NULL || !PyUnicode_Check(con->name) || | ||
| con->filename == NULL || !PyUnicode_Check(con->filename) || | ||
| con->linetable == NULL || !PyBytes_Check(con->linetable) || | ||
| @@ -309,7 +312,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con) | ||
| Py_INCREF(con->localsplusnames); | ||
| co->co_localsplusnames = con->localsplusnames; | ||
| // We take ownership of the kinds array. | ||
| Py_INCREF(con->localspluskinds); | ||
| co->co_localspluskinds = con->localspluskinds; | ||
| co->co_argcount = con->argcount; | ||
| @@ -394,7 +397,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||
| { | ||
| PyCodeObject *co = NULL; | ||
| PyObject *localsplusnames = NULL; | ||
| _PyLocalsPlusKinds localspluskinds = NULL; | ||
| PyObject *localspluskinds = NULL; | ||
| if (varnames == NULL || !PyTuple_Check(varnames) || | ||
| cellvars == NULL || !PyTuple_Check(cellvars) || | ||
| @@ -413,7 +416,8 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||
| if (localsplusnames == NULL){ | ||
| goto error; | ||
| } | ||
| if (_PyCode_InitLocalsPlusKinds(nlocalsplus, &localspluskinds) < 0){ | ||
| localspluskinds = PyBytes_FromStringAndSize(NULL, nlocalsplus); | ||
| if (localspluskinds == NULL){ | ||
| goto error; | ||
| } | ||
| int offset = 0; | ||
| @@ -438,7 +442,8 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||
| // Merge the localsplus indices. | ||
| nlocalsplus -= 1; | ||
| offset -= 1; | ||
| localspluskinds[argoffset] |= CO_FAST_CELL; | ||
| _PyLocals_Kind kind = _PyLocals_GetKind(localspluskinds, argoffset); | ||
| _PyLocals_SetKind(localspluskinds, argoffset, kind | CO_FAST_CELL); | ||
| continue; | ||
| } | ||
| _Py_set_localsplus_info(offset, name, CO_FAST_CELL, | ||
| @@ -495,7 +500,6 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||
| goto error; | ||
| } | ||
| localspluskinds = NULL; // This keeps it from getting freed below. | ||
| Py_INCREF(varnames); | ||
| co->co_varnames = varnames; | ||
| Py_INCREF(cellvars); | ||
| @@ -505,7 +509,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||
| error: | ||
| Py_XDECREF(localsplusnames); | ||
| _PyCode_ClearLocalsPlusKinds(localspluskinds); | ||
| Py_XDECREF(localspluskinds); | ||
| return co; | ||
| } | ||
| @@ -558,6 +562,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) | ||
| .consts = nulltuple, | ||
| .names = nulltuple, | ||
| .localsplusnames = nulltuple, | ||
| .localspluskinds = emptystring, | ||
| .exceptiontable = emptystring, | ||
| }; | ||
| result = _PyCode_New(&con); | ||
| @@ -1142,7 +1147,7 @@ code_dealloc(PyCodeObject *co) | ||
| Py_XDECREF(co->co_consts); | ||
| Py_XDECREF(co->co_names); | ||
| Py_XDECREF(co->co_localsplusnames); | ||
| _PyCode_ClearLocalsPlusKinds(co->co_localspluskinds); | ||
| Py_XDECREF(co->co_localspluskinds); | ||
| Py_XDECREF(co->co_varnames); | ||
| Py_XDECREF(co->co_freevars); | ||
| Py_XDECREF(co->co_cellvars); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7187,23 +7187,21 @@ 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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| PyObject *, PyObject *); | ||
| static void | ||
| compute_localsplus_info(struct compiler *c, int nlocalsplus, | ||
| PyObject *names, _PyLocalsPlusKinds kinds) | ||
| PyObject *names, PyObject *kinds) | ||
| { | ||
| assert(PyTuple_GET_SIZE(names) == nlocalsplus); | ||
| PyObject *k, *v; | ||
| Py_ssize_t pos = 0; | ||
| while (PyDict_Next(c->u->u_varnames, &pos, &k, &v)){ | ||
| int offset = (int)PyLong_AS_LONG(v); | ||
| 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; | ||
| } | ||
| @@ -7245,7 +7243,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); | ||
| @@ -7281,7 +7279,8 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist, | ||
| if (localsplusnames == NULL){ | ||
| goto error; | ||
| } | ||
| if (_PyCode_InitLocalsPlusKinds(nlocalsplus, &localspluskinds) < 0){ | ||
| localspluskinds = PyBytes_FromStringAndSize(NULL, nlocalsplus); | ||
| if (localspluskinds == NULL){ | ||
| goto error; | ||
| } | ||
| compute_localsplus_info(c, nlocalsplus, localsplusnames, localspluskinds); | ||
| @@ -7315,7 +7314,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; | ||
| @@ -7325,13 +7323,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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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.