diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-11 21:39:41 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-11 21:39:41 (GMT) |
commit | 6a7506a77f11235b2f1f0e97a2f2eb57e6953d88 (patch) | |
tree | 49509696dbf91f8e26ee18309678d0f3d4daee56 /Python/ceval.c | |
parent | d611f4cf10e63814ad0d2e51b215d13dc097d355 (diff) | |
download | cpython-6a7506a77f11235b2f1f0e97a2f2eb57e6953d88.zip cpython-6a7506a77f11235b2f1f0e97a2f2eb57e6953d88.tar.gz cpython-6a7506a77f11235b2f1f0e97a2f2eb57e6953d88.tar.bz2 |
Issue #27140: Added BUILD_CONST_KEY_MAP opcode.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index b6ce67c..1d3bc90 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2647,6 +2647,39 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) DISPATCH(); } + TARGET(BUILD_CONST_KEY_MAP) { + int i; + PyObject *map; + PyObject *keys = TOP(); + if (!PyTuple_CheckExact(keys) || + PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) { + PyErr_SetString(PyExc_SystemError, + "bad BUILD_CONST_KEY_MAP keys argument"); + goto error; + } + map = _PyDict_NewPresized((Py_ssize_t)oparg); + if (map == NULL) { + goto error; + } + for (i = oparg; i > 0; i--) { + int err; + PyObject *key = PyTuple_GET_ITEM(keys, oparg - i); + PyObject *value = PEEK(i + 1); + err = PyDict_SetItem(map, key, value); + if (err != 0) { + Py_DECREF(map); + goto error; + } + } + + Py_DECREF(POP()); + while (oparg--) { + Py_DECREF(POP()); + } + PUSH(map); + DISPATCH(); + } + TARGET(BUILD_MAP_UNPACK_WITH_CALL) TARGET(BUILD_MAP_UNPACK) { int with_call = opcode == BUILD_MAP_UNPACK_WITH_CALL; |