diff options
author | Guido van Rossum <guido@python.org> | 2021-06-21 20:53:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-21 20:53:04 (GMT) |
commit | 355f5dd36a0f53175517f35798aa874564d1113a (patch) | |
tree | cfc6c7e4f009afc772d4a9e0c909d6e3499cf2e9 /Python/compile.c | |
parent | c5d700f0e2e2921c6b54c72ffb0fca3c3d1ef06b (diff) | |
download | cpython-355f5dd36a0f53175517f35798aa874564d1113a.zip cpython-355f5dd36a0f53175517f35798aa874564d1113a.tar.gz cpython-355f5dd36a0f53175517f35798aa874564d1113a.tar.bz2 |
bpo-43693: Turn localspluskinds into an object (GH-26749)
Managing it as a bare pointer to malloc'ed bytes is just too awkward in a few places.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Python/compile.c b/Python/compile.c index 0a18148..9118d12 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -7187,15 +7187,13 @@ 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, + 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)) { @@ -7203,7 +7201,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; } @@ -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; } |