Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(61956)

Delta Between Two Patch Sets: Python/ceval.c

Issue 27095: Simplify MAKE_FUNCTION
Left Patch Set: Created 3 years, 4 months ago
Right Patch Set: Created 3 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 1
2 /* Execute compiled code */ 2 /* Execute compiled code */
3 3
4 /* XXX TO DO: 4 /* XXX TO DO:
5 XXX speed up searching for keywords by using a dictionary 5 XXX speed up searching for keywords by using a dictionary
6 XXX document it! 6 XXX document it!
7 */ 7 */
8 8
9 /* enable more aggressive intra-module optimizations, where available */ 9 /* enable more aggressive intra-module optimizations, where available */
10 #define PY_LOCAL_AGGRESSIVE 10 #define PY_LOCAL_AGGRESSIVE
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 PyThreadState *, PyFrameObject *); 137 PyThreadState *, PyFrameObject *);
138 static int maybe_call_line_trace(Py_tracefunc, PyObject *, 138 static int maybe_call_line_trace(Py_tracefunc, PyObject *,
139 PyThreadState *, PyFrameObject *, int *, int *, int *); 139 PyThreadState *, PyFrameObject *, int *, int *, int *);
140 140
141 static PyObject * cmp_outcome(int, PyObject *, PyObject *); 141 static PyObject * cmp_outcome(int, PyObject *, PyObject *);
142 static PyObject * import_from(PyObject *, PyObject *); 142 static PyObject * import_from(PyObject *, PyObject *);
143 static int import_all_from(PyObject *, PyObject *); 143 static int import_all_from(PyObject *, PyObject *);
144 static void format_exc_check_arg(PyObject *, const char *, PyObject *); 144 static void format_exc_check_arg(PyObject *, const char *, PyObject *);
145 static void format_exc_unbound(PyCodeObject *co, int oparg); 145 static void format_exc_unbound(PyCodeObject *co, int oparg);
146 static PyObject * unicode_concatenate(PyObject *, PyObject *, 146 static PyObject * unicode_concatenate(PyObject *, PyObject *,
147 PyFrameObject *, unsigned char *); 147 PyFrameObject *, const unsigned short *);
148 static PyObject * special_lookup(PyObject *, _Py_Identifier *); 148 static PyObject * special_lookup(PyObject *, _Py_Identifier *);
149 149
150 #define NAME_ERROR_MSG \ 150 #define NAME_ERROR_MSG \
151 "name '%.200s' is not defined" 151 "name '%.200s' is not defined"
152 #define UNBOUNDLOCAL_ERROR_MSG \ 152 #define UNBOUNDLOCAL_ERROR_MSG \
153 "local variable '%.200s' referenced before assignment" 153 "local variable '%.200s' referenced before assignment"
154 #define UNBOUNDFREE_ERROR_MSG \ 154 #define UNBOUNDFREE_ERROR_MSG \
155 "free variable '%.200s' referenced before assignment" \ 155 "free variable '%.200s' referenced before assignment" \
156 " in enclosing scope" 156 " in enclosing scope"
157 157
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 return PyEval_EvalFrameEx(f, 0); 793 return PyEval_EvalFrameEx(f, 0);
794 } 794 }
795 795
796 PyObject * 796 PyObject *
797 PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) 797 PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
798 { 798 {
799 #ifdef DXPAIRS 799 #ifdef DXPAIRS
800 int lastopcode = 0; 800 int lastopcode = 0;
801 #endif 801 #endif
802 PyObject **stack_pointer; /* Next free slot in value stack */ 802 PyObject **stack_pointer; /* Next free slot in value stack */
803 unsigned char *next_instr; 803 const unsigned short *next_instr;
804 int opcode; /* Current opcode */ 804 int opcode; /* Current opcode */
805 int oparg; /* Current opcode argument, if any */ 805 int oparg; /* Current opcode argument, if any */
806 enum why_code why; /* Reason for block stack unwind */ 806 enum why_code why; /* Reason for block stack unwind */
807 PyObject **fastlocals, **freevars; 807 PyObject **fastlocals, **freevars;
808 PyObject *retval = NULL; /* Return value */ 808 PyObject *retval = NULL; /* Return value */
809 PyThreadState *tstate = PyThreadState_GET(); 809 PyThreadState *tstate = PyThreadState_GET();
810 PyCodeObject *co; 810 PyCodeObject *co;
811 811
812 /* when tracing we set things up so that 812 /* when tracing we set things up so that
813 813
814 not (instr_lb <= current_bytecode_offset < instr_ub) 814 not (instr_lb <= current_bytecode_offset < instr_ub)
815 815
816 is true when the line being executed has changed. The 816 is true when the line being executed has changed. The
817 initial values are such as to make this false the first 817 initial values are such as to make this false the first
818 time it is tested. */ 818 time it is tested. */
819 int instr_ub = -1, instr_lb = 0, instr_prev = -1; 819 int instr_ub = -1, instr_lb = 0, instr_prev = -1;
820 820
821 unsigned char *first_instr; 821 const unsigned short *first_instr;
822 PyObject *names; 822 PyObject *names;
823 PyObject *consts; 823 PyObject *consts;
824 824
825 #ifdef LLTRACE 825 #ifdef LLTRACE
826 _Py_IDENTIFIER(__ltrace__); 826 _Py_IDENTIFIER(__ltrace__);
827 #endif 827 #endif
828 828
829 /* Computed GOTOs, or 829 /* Computed GOTOs, or
830 the-optimization-commonly-but-improperly-known-as-"threaded code" 830 the-optimization-commonly-but-improperly-known-as-"threaded code"
831 using gcc's labels-as-values extension 831 using gcc's labels-as-values extension
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 FAST_DISPATCH(); \ 896 FAST_DISPATCH(); \
897 } \ 897 } \
898 continue; \ 898 continue; \
899 } 899 }
900 900
901 #ifdef LLTRACE 901 #ifdef LLTRACE
902 #define FAST_DISPATCH() \ 902 #define FAST_DISPATCH() \
903 { \ 903 { \
904 if (!lltrace && !_Py_TracingPossible) { \ 904 if (!lltrace && !_Py_TracingPossible) { \
905 f->f_lasti = INSTR_OFFSET(); \ 905 f->f_lasti = INSTR_OFFSET(); \
906 opcode = NEXTOP(); \ 906 NEXTOPARG(); \
907 oparg = NEXTARG(); \
908 goto *opcode_targets[opcode]; \ 907 goto *opcode_targets[opcode]; \
909 } \ 908 } \
910 goto fast_next_opcode; \ 909 goto fast_next_opcode; \
911 } 910 }
912 #else 911 #else
913 #define FAST_DISPATCH() \ 912 #define FAST_DISPATCH() \
914 { \ 913 { \
915 if (!_Py_TracingPossible) { \ 914 if (!_Py_TracingPossible) { \
916 f->f_lasti = INSTR_OFFSET(); \ 915 f->f_lasti = INSTR_OFFSET(); \
917 opcode = NEXTOP(); \ 916 NEXTOPARG(); \
918 oparg = NEXTARG(); \
919 goto *opcode_targets[opcode]; \ 917 goto *opcode_targets[opcode]; \
920 } \ 918 } \
921 goto fast_next_opcode; \ 919 goto fast_next_opcode; \
922 } 920 }
923 #endif 921 #endif
924 922
925 #else 923 #else
926 #define TARGET(op) \ 924 #define TARGET(op) \
927 case op: 925 case op:
928 926
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 READ_TIMESTAMP(inst1); 972 READ_TIMESTAMP(inst1);
975 READ_TIMESTAMP(loop0); 973 READ_TIMESTAMP(loop0);
976 READ_TIMESTAMP(loop1); 974 READ_TIMESTAMP(loop1);
977 975
978 /* shut up the compiler */ 976 /* shut up the compiler */
979 opcode = 0; 977 opcode = 0;
980 #endif 978 #endif
981 979
982 /* Code access macros */ 980 /* Code access macros */
983 981
984 #define INSTR_OFFSET() ((int)(next_instr - first_instr)) 982 #ifdef WORDS_BIGENDIAN
985 #define NEXTOP() (next_instr+=2, next_instr[-2]) 983 #define OPCODE(word) ((word) >> 8)
986 #define NEXTARG() (next_instr[-1]) 984 #define OPARG(word) ((word) & 255)
987 #define PEEKARG() (next_instr[1]) 985 #else
988 #define JUMPTO(x) (next_instr = first_instr + (x)) 986 #define OPCODE(word) ((word) & 255)
989 #define JUMPBY(x) (next_instr += (x)) 987 #define OPARG(word) ((word) >> 8)
988 #endif
989 /* The integer overflow is checked by an assertion below. */
990 #define INSTR_OFFSET() (2*(int)(next_instr - first_instr))
991 #define NEXTOPARG() do { \
992 unsigned short word = *next_instr; \
993 opcode = OPCODE(word); \
994 oparg = OPARG(word); \
995 next_instr++; \
996 } while (0)
997 #define JUMPTO(x) (next_instr = first_instr + (x)/2)
998 #define JUMPBY(x) (next_instr += (x)/2)
990 999
991 /* OpCode prediction macros 1000 /* OpCode prediction macros
992 Some opcodes tend to come in pairs thus making it possible to 1001 Some opcodes tend to come in pairs thus making it possible to
993 predict the second code when the first is run. For example, 1002 predict the second code when the first is run. For example,
994 COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, 1003 COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And,
995 those opcodes are often followed by a POP_TOP. 1004 those opcodes are often followed by a POP_TOP.
996 1005
997 Verifying the prediction costs a single high-speed test of a register 1006 Verifying the prediction costs a single high-speed test of a register
998 variable against a constant. If the pairing was good, then the 1007 variable against a constant. If the pairing was good, then the
999 processor's own internal branch predication has a high likelihood of 1008 processor's own internal branch predication has a high likelihood of
(...skipping 13 matching lines...) Expand all
1013 the CPU to record separate branch prediction information for each 1022 the CPU to record separate branch prediction information for each
1014 opcode. 1023 opcode.
1015 1024
1016 */ 1025 */
1017 1026
1018 #if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS 1027 #if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS
1019 #define PREDICT(op) if (0) goto PRED_##op 1028 #define PREDICT(op) if (0) goto PRED_##op
1020 #else 1029 #else
1021 #define PREDICT(op) \ 1030 #define PREDICT(op) \
1022 do{ \ 1031 do{ \
1023 if (*next_instr == op){ \ 1032 unsigned short word = *next_instr; \
1024 opcode = op; \ 1033 opcode = OPCODE(word); \
1025 oparg = PEEKARG(); \ 1034 if (opcode == op){ \
1026 next_instr += 2; \ 1035 oparg = OPARG(word); \
1036 next_instr++; \
1027 goto PRED_##op; \ 1037 goto PRED_##op; \
1028 } \ 1038 } \
1029 } while(0) 1039 } while(0)
1030 #endif 1040 #endif
1031 #define PREDICTED(op) PRED_##op: 1041 #define PREDICTED(op) PRED_##op:
1032 1042
1033 1043
1034 /* Stack manipulation macros */ 1044 /* Stack manipulation macros */
1035 1045
1036 /* The stack can grow at most MAXINT deep, as co_nlocals and 1046 /* The stack can grow at most MAXINT deep, as co_nlocals and
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 goto exit_eval_frame; 1160 goto exit_eval_frame;
1151 } 1161 }
1152 } 1162 }
1153 } 1163 }
1154 1164
1155 co = f->f_code; 1165 co = f->f_code;
1156 names = co->co_names; 1166 names = co->co_names;
1157 consts = co->co_consts; 1167 consts = co->co_consts;
1158 fastlocals = f->f_localsplus; 1168 fastlocals = f->f_localsplus;
1159 freevars = f->f_localsplus + co->co_nlocals; 1169 freevars = f->f_localsplus + co->co_nlocals;
1160 first_instr = (unsigned char*) PyBytes_AS_STRING(co->co_code); 1170 assert(PyBytes_Check(co->co_code));
1171 assert(PyBytes_GET_SIZE(co->co_code) <= INT_MAX);
1172 assert(PyBytes_GET_SIZE(co->co_code) % 2 == 0);
1173 assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(co->co_code), 2));
1174 first_instr = (unsigned short*) PyBytes_AS_STRING(co->co_code);
1161 /* 1175 /*
1162 f->f_lasti refers to the index of the last instruction, 1176 f->f_lasti refers to the index of the last instruction,
1163 unless it's -1 in which case next_instr should be first_instr. 1177 unless it's -1 in which case next_instr should be first_instr.
1164 1178
1165 YIELD_FROM sets f_lasti to itself, in order to repeatedly yield 1179 YIELD_FROM sets f_lasti to itself, in order to repeatedly yield
1166 multiple values. 1180 multiple values.
1167 1181
1168 When the PREDICT() macros are enabled, some opcode pairs follow in 1182 When the PREDICT() macros are enabled, some opcode pairs follow in
1169 direct succession without updating f->f_lasti. A successful 1183 direct succession without updating f->f_lasti. A successful
1170 prediction effectively links the two codes together as if they 1184 prediction effectively links the two codes together as if they
1171 were a single new opcode; accordingly,f->f_lasti will point to 1185 were a single new opcode; accordingly,f->f_lasti will point to
1172 the first code in the pair (for instance, GET_ITER followed by 1186 the first code in the pair (for instance, GET_ITER followed by
1173 FOR_ITER is effectively a single opcode and f->f_lasti will point 1187 FOR_ITER is effectively a single opcode and f->f_lasti will point
1174 to the beginning of the combined pair.) 1188 to the beginning of the combined pair.)
1175 */ 1189 */
1176 next_instr = first_instr; 1190 next_instr = first_instr;
1177 if (f->f_lasti >= 0) { 1191 if (f->f_lasti >= 0) {
1178 next_instr += f->f_lasti + 2; 1192 assert(f->f_lasti % 2 == 0);
1193 next_instr += f->f_lasti/2 + 1;
1179 } 1194 }
1180 stack_pointer = f->f_stacktop; 1195 stack_pointer = f->f_stacktop;
1181 assert(stack_pointer != NULL); 1196 assert(stack_pointer != NULL);
1182 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ 1197 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
1183 f->f_executing = 1; 1198 f->f_executing = 1;
1184 1199
1185 if (co->co_flags & (CO_GENERATOR | CO_COROUTINE)) { 1200 if (co->co_flags & (CO_GENERATOR | CO_COROUTINE)) {
1186 if (!throwflag && f->f_exc_type != NULL && f->f_exc_type != Py_None) { 1201 if (!throwflag && f->f_exc_type != NULL && f->f_exc_type != Py_None) {
1187 /* We were in an except handler when we left, 1202 /* We were in an except handler when we left,
1188 restore the exception state which was put aside 1203 restore the exception state which was put aside
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 1248
1234 /* Do periodic things. Doing this every time through 1249 /* Do periodic things. Doing this every time through
1235 the loop would add too much overhead, so we do it 1250 the loop would add too much overhead, so we do it
1236 only every Nth instruction. We also do it if 1251 only every Nth instruction. We also do it if
1237 ``pendingcalls_to_do'' is set, i.e. when an asynchronous 1252 ``pendingcalls_to_do'' is set, i.e. when an asynchronous
1238 event needs attention (e.g. a signal handler or 1253 event needs attention (e.g. a signal handler or
1239 async I/O handler); see Py_AddPendingCall() and 1254 async I/O handler); see Py_AddPendingCall() and
1240 Py_MakePendingCalls() above. */ 1255 Py_MakePendingCalls() above. */
1241 1256
1242 if (_Py_atomic_load_relaxed(&eval_breaker)) { 1257 if (_Py_atomic_load_relaxed(&eval_breaker)) {
1243 if (*next_instr == SETUP_FINALLY) { 1258 if (OPCODE(*next_instr) == SETUP_FINALLY) {
1244 /* Make the last opcode before 1259 /* Make the last opcode before
1245 a try: finally: block uninterruptible. */ 1260 a try: finally: block uninterruptible. */
1246 goto fast_next_opcode; 1261 goto fast_next_opcode;
1247 } 1262 }
1248 #ifdef WITH_TSC 1263 #ifdef WITH_TSC
1249 ticked = 1; 1264 ticked = 1;
1250 #endif 1265 #endif
1251 if (_Py_atomic_load_relaxed(&pendingcalls_to_do)) { 1266 if (_Py_atomic_load_relaxed(&pendingcalls_to_do)) {
1252 if (Py_MakePendingCalls() < 0) 1267 if (Py_MakePendingCalls() < 0)
1253 goto error; 1268 goto error;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 stack_pointer = f->f_stacktop; 1321 stack_pointer = f->f_stacktop;
1307 f->f_stacktop = NULL; 1322 f->f_stacktop = NULL;
1308 } 1323 }
1309 if (err) 1324 if (err)
1310 /* trace function raised an exception */ 1325 /* trace function raised an exception */
1311 goto error; 1326 goto error;
1312 } 1327 }
1313 1328
1314 /* Extract opcode and argument */ 1329 /* Extract opcode and argument */
1315 1330
1316 opcode = NEXTOP(); 1331 NEXTOPARG();
1317 oparg = NEXTARG();
1318 dispatch_opcode: 1332 dispatch_opcode:
1319 #ifdef DYNAMIC_EXECUTION_PROFILE 1333 #ifdef DYNAMIC_EXECUTION_PROFILE
1320 #ifdef DXPAIRS 1334 #ifdef DXPAIRS
1321 dxpairs[lastopcode][opcode]++; 1335 dxpairs[lastopcode][opcode]++;
1322 lastopcode = opcode; 1336 lastopcode = opcode;
1323 #endif 1337 #endif
1324 dxp[opcode]++; 1338 dxp[opcode]++;
1325 #endif 1339 #endif
1326 1340
1327 #ifdef LLTRACE 1341 #ifdef LLTRACE
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 goto fast_block_end; 1928 goto fast_block_end;
1915 } 1929 }
1916 1930
1917 TARGET(GET_AITER) { 1931 TARGET(GET_AITER) {
1918 unaryfunc getter = NULL; 1932 unaryfunc getter = NULL;
1919 PyObject *iter = NULL; 1933 PyObject *iter = NULL;
1920 PyObject *awaitable = NULL; 1934 PyObject *awaitable = NULL;
1921 PyObject *obj = TOP(); 1935 PyObject *obj = TOP();
1922 PyTypeObject *type = Py_TYPE(obj); 1936 PyTypeObject *type = Py_TYPE(obj);
1923 1937
1924 if (type->tp_as_async != NULL) 1938 if (type->tp_as_async != NULL) {
1925 getter = type->tp_as_async->am_aiter; 1939 getter = type->tp_as_async->am_aiter;
1940 }
1926 1941
1927 if (getter != NULL) { 1942 if (getter != NULL) {
1928 iter = (*getter)(obj); 1943 iter = (*getter)(obj);
1929 Py_DECREF(obj); 1944 Py_DECREF(obj);
1930 if (iter == NULL) { 1945 if (iter == NULL) {
1931 SET_TOP(NULL); 1946 SET_TOP(NULL);
1932 goto error; 1947 goto error;
1933 } 1948 }
1934 } 1949 }
1935 else { 1950 else {
1936 SET_TOP(NULL); 1951 SET_TOP(NULL);
1937 PyErr_Format( 1952 PyErr_Format(
1938 PyExc_TypeError, 1953 PyExc_TypeError,
1939 "'async for' requires an object with " 1954 "'async for' requires an object with "
1940 "__aiter__ method, got %.100s", 1955 "__aiter__ method, got %.100s",
1941 type->tp_name); 1956 type->tp_name);
1942 Py_DECREF(obj); 1957 Py_DECREF(obj);
1943 goto error; 1958 goto error;
1944 } 1959 }
1945 1960
1961 if (Py_TYPE(iter)->tp_as_async != NULL &&
1962 Py_TYPE(iter)->tp_as_async->am_anext != NULL) {
1963
1964 /* Starting with CPython 3.5.2 __aiter__ should return
1965 asynchronous iterators directly (not awaitables that
1966 resolve to asynchronous iterators.)
1967
1968 Therefore, we check if the object that was returned
1969 from __aiter__ has an __anext__ method. If it does,
1970 we wrap it in an awaitable that resolves to `iter`.
1971
1972 See http://bugs.python.org/issue27243 for more
1973 details.
1974 */
1975
1976 PyObject *wrapper = _PyAIterWrapper_New(iter);
1977 Py_DECREF(iter);
1978 SET_TOP(wrapper);
1979 DISPATCH();
1980 }
1981
1946 awaitable = _PyCoro_GetAwaitableIter(iter); 1982 awaitable = _PyCoro_GetAwaitableIter(iter);
1947 if (awaitable == NULL) { 1983 if (awaitable == NULL) {
1948 SET_TOP(NULL); 1984 SET_TOP(NULL);
1949 PyErr_Format( 1985 PyErr_Format(
1950 PyExc_TypeError, 1986 PyExc_TypeError,
1951 "'async for' received an invalid object " 1987 "'async for' received an invalid object "
1952 "from __aiter__: %.100s", 1988 "from __aiter__: %.100s",
1953 Py_TYPE(iter)->tp_name); 1989 Py_TYPE(iter)->tp_name);
1954 1990
1955 Py_DECREF(iter); 1991 Py_DECREF(iter);
1956 goto error; 1992 goto error;
1957 } else 1993 } else {
1958 Py_DECREF(iter); 1994 Py_DECREF(iter);
1995
1996 if (PyErr_WarnFormat(
1997 PyExc_PendingDeprecationWarning, 1,
1998 "'%.100s' implements legacy __aiter__ protocol; "
1999 "__aiter__ should return an asynchronous "
2000 "iterator, not awaitable",
2001 type->tp_name))
2002 {
2003 /* Warning was converted to an error. */
2004 Py_DECREF(awaitable);
2005 SET_TOP(NULL);
2006 goto error;
2007 }
2008 }
1959 2009
1960 SET_TOP(awaitable); 2010 SET_TOP(awaitable);
1961 DISPATCH(); 2011 DISPATCH();
1962 } 2012 }
1963 2013
1964 TARGET(GET_ANEXT) { 2014 TARGET(GET_ANEXT) {
1965 unaryfunc getter = NULL; 2015 unaryfunc getter = NULL;
1966 PyObject *next_iter = NULL; 2016 PyObject *next_iter = NULL;
1967 PyObject *awaitable = NULL; 2017 PyObject *awaitable = NULL;
1968 PyObject *aiter = TOP(); 2018 PyObject *aiter = TOP();
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 } 2640 }
2591 2641
2592 while (oparg--) { 2642 while (oparg--) {
2593 Py_DECREF(POP()); 2643 Py_DECREF(POP());
2594 Py_DECREF(POP()); 2644 Py_DECREF(POP());
2595 } 2645 }
2596 PUSH(map); 2646 PUSH(map);
2597 DISPATCH(); 2647 DISPATCH();
2598 } 2648 }
2599 2649
2650 TARGET(BUILD_CONST_KEY_MAP) {
2651 int i;
2652 PyObject *map;
2653 PyObject *keys = TOP();
2654 if (!PyTuple_CheckExact(keys) ||
2655 PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) {
2656 PyErr_SetString(PyExc_SystemError,
2657 "bad BUILD_CONST_KEY_MAP keys argument");
2658 goto error;
2659 }
2660 map = _PyDict_NewPresized((Py_ssize_t)oparg);
2661 if (map == NULL) {
2662 goto error;
2663 }
2664 for (i = oparg; i > 0; i--) {
2665 int err;
2666 PyObject *key = PyTuple_GET_ITEM(keys, oparg - i);
2667 PyObject *value = PEEK(i + 1);
2668 err = PyDict_SetItem(map, key, value);
2669 if (err != 0) {
2670 Py_DECREF(map);
2671 goto error;
2672 }
2673 }
2674
2675 Py_DECREF(POP());
2676 while (oparg--) {
2677 Py_DECREF(POP());
2678 }
2679 PUSH(map);
2680 DISPATCH();
2681 }
2682
2600 TARGET(BUILD_MAP_UNPACK_WITH_CALL) 2683 TARGET(BUILD_MAP_UNPACK_WITH_CALL)
2601 TARGET(BUILD_MAP_UNPACK) { 2684 TARGET(BUILD_MAP_UNPACK) {
2602 int with_call = opcode == BUILD_MAP_UNPACK_WITH_CALL; 2685 int with_call = opcode == BUILD_MAP_UNPACK_WITH_CALL;
2603 int num_maps; 2686 int num_maps;
2604 int function_location; 2687 int function_location;
2605 int i; 2688 int i;
2606 PyObject *sum = PyDict_New(); 2689 PyObject *sum = PyDict_New();
2607 if (sum == NULL) 2690 if (sum == NULL)
2608 goto error; 2691 goto error;
2609 if (with_call) { 2692 if (with_call) {
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
3247 PyObject *codeobj = POP(); 3330 PyObject *codeobj = POP();
3248 PyFunctionObject *func = (PyFunctionObject *) 3331 PyFunctionObject *func = (PyFunctionObject *)
3249 PyFunction_NewWithQualName(codeobj, f->f_globals, qualname); 3332 PyFunction_NewWithQualName(codeobj, f->f_globals, qualname);
3250 3333
3251 Py_DECREF(codeobj); 3334 Py_DECREF(codeobj);
3252 Py_DECREF(qualname); 3335 Py_DECREF(qualname);
3253 if (func == NULL) { 3336 if (func == NULL) {
3254 goto error; 3337 goto error;
3255 } 3338 }
3256 3339
3257 /* NB: Py_None is not an acceptable value for these. */
3258 if (oparg & 0x08) { 3340 if (oparg & 0x08) {
3341 assert(PyTuple_CheckExact(TOP()));
3259 func ->func_closure = POP(); 3342 func ->func_closure = POP();
storchaka 2016/05/27 22:13:11 Py_None was acceptable. In any case you should che
3260 } 3343 }
3261 if (oparg & 0x04) { 3344 if (oparg & 0x04) {
3345 assert(PyDict_CheckExact(TOP()));
3262 func->func_annotations = POP(); 3346 func->func_annotations = POP();
storchaka 2016/05/27 22:13:11 Needed check that the value is a dict (maybe exact
3263 } 3347 }
3264 if (oparg & 0x02) { 3348 if (oparg & 0x02) {
3349 assert(PyDict_CheckExact(TOP()));
3265 func->func_kwdefaults = POP(); 3350 func->func_kwdefaults = POP();
3266 } 3351 }
3267 if (oparg & 0x01) { 3352 if (oparg & 0x01) {
3353 assert(PyTuple_CheckExact(TOP()));
3268 func->func_defaults = POP(); 3354 func->func_defaults = POP();
3269 } 3355 }
3270 3356
3271 PUSH((PyObject *)func); 3357 PUSH((PyObject *)func);
3272 DISPATCH(); 3358 DISPATCH();
3273 } 3359 }
3274 3360
3275 TARGET(BUILD_SLICE) { 3361 TARGET(BUILD_SLICE) {
3276 PyObject *start, *stop, *step, *slice; 3362 PyObject *start, *stop, *step, *slice;
3277 if (oparg == 3) 3363 if (oparg == 3)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 if (result == NULL) { 3428 if (result == NULL) {
3343 goto error; 3429 goto error;
3344 } 3430 }
3345 } 3431 }
3346 3432
3347 PUSH(result); 3433 PUSH(result);
3348 DISPATCH(); 3434 DISPATCH();
3349 } 3435 }
3350 3436
3351 TARGET(EXTENDED_ARG) { 3437 TARGET(EXTENDED_ARG) {
3352 opcode = NEXTOP(); 3438 int oldoparg = oparg;
3353 oparg = oparg<<8 | NEXTARG(); 3439 NEXTOPARG();
3440 oparg |= oldoparg << 8;
3354 goto dispatch_opcode; 3441 goto dispatch_opcode;
3355 } 3442 }
3356 3443
3357 3444
3358 #if USE_COMPUTED_GOTOS 3445 #if USE_COMPUTED_GOTOS
3359 _unknown_opcode: 3446 _unknown_opcode:
3360 #endif 3447 #endif
3361 default: 3448 default:
3362 fprintf(stderr, 3449 fprintf(stderr,
3363 "XXX lineno: %d, opcode: %d\n", 3450 "XXX lineno: %d, opcode: %d\n",
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after
5198 } else { 5285 } else {
5199 name = PyTuple_GET_ITEM(co->co_freevars, oparg - 5286 name = PyTuple_GET_ITEM(co->co_freevars, oparg -
5200 PyTuple_GET_SIZE(co->co_cellvars)); 5287 PyTuple_GET_SIZE(co->co_cellvars));
5201 format_exc_check_arg(PyExc_NameError, 5288 format_exc_check_arg(PyExc_NameError,
5202 UNBOUNDFREE_ERROR_MSG, name); 5289 UNBOUNDFREE_ERROR_MSG, name);
5203 } 5290 }
5204 } 5291 }
5205 5292
5206 static PyObject * 5293 static PyObject *
5207 unicode_concatenate(PyObject *v, PyObject *w, 5294 unicode_concatenate(PyObject *v, PyObject *w,
5208 PyFrameObject *f, unsigned char *next_instr) 5295 PyFrameObject *f, const unsigned short *next_instr)
5209 { 5296 {
5210 PyObject *res; 5297 PyObject *res;
5211 if (Py_REFCNT(v) == 2) { 5298 if (Py_REFCNT(v) == 2) {
5212 /* In the common case, there are 2 references to the value 5299 /* In the common case, there are 2 references to the value
5213 * stored in 'variable' when the += is performed: one on the 5300 * stored in 'variable' when the += is performed: one on the
5214 * value stack (in 'v') and one still stored in the 5301 * value stack (in 'v') and one still stored in the
5215 * 'variable'. We try to delete the variable now to reduce 5302 * 'variable'. We try to delete the variable now to reduce
5216 * the refcnt to 1. 5303 * the refcnt to 1.
5217 */ 5304 */
5218 switch (*next_instr) { 5305 int opcode, oparg;
5306 NEXTOPARG();
5307 switch (opcode) {
5219 case STORE_FAST: 5308 case STORE_FAST:
5220 { 5309 {
5221 int oparg = PEEKARG();
5222 PyObject **fastlocals = f->f_localsplus; 5310 PyObject **fastlocals = f->f_localsplus;
5223 if (GETLOCAL(oparg) == v) 5311 if (GETLOCAL(oparg) == v)
5224 SETLOCAL(oparg, NULL); 5312 SETLOCAL(oparg, NULL);
5225 break; 5313 break;
5226 } 5314 }
5227 case STORE_DEREF: 5315 case STORE_DEREF:
5228 { 5316 {
5229 PyObject **freevars = (f->f_localsplus + 5317 PyObject **freevars = (f->f_localsplus +
5230 f->f_code->co_nlocals); 5318 f->f_code->co_nlocals);
5231 PyObject *c = freevars[PEEKARG()]; 5319 PyObject *c = freevars[oparg];
5232 if (PyCell_GET(c) == v) 5320 if (PyCell_GET(c) == v)
5233 PyCell_Set(c, NULL); 5321 PyCell_Set(c, NULL);
5234 break; 5322 break;
5235 } 5323 }
5236 case STORE_NAME: 5324 case STORE_NAME:
5237 { 5325 {
5238 PyObject *names = f->f_code->co_names; 5326 PyObject *names = f->f_code->co_names;
5239 PyObject *name = GETITEM(names, PEEKARG()); 5327 PyObject *name = GETITEM(names, oparg);
5240 PyObject *locals = f->f_locals; 5328 PyObject *locals = f->f_locals;
5241 if (PyDict_CheckExact(locals) && 5329 if (PyDict_CheckExact(locals) &&
5242 PyDict_GetItem(locals, name) == v) { 5330 PyDict_GetItem(locals, name) == v) {
5243 if (PyDict_DelItem(locals, name) != 0) { 5331 if (PyDict_DelItem(locals, name) != 0) {
5244 PyErr_Clear(); 5332 PyErr_Clear();
5245 } 5333 }
5246 } 5334 }
5247 break; 5335 break;
5248 } 5336 }
5249 } 5337 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5289 Py_DECREF(l); 5377 Py_DECREF(l);
5290 return NULL; 5378 return NULL;
5291 } 5379 }
5292 PyList_SetItem(l, i, x); 5380 PyList_SetItem(l, i, x);
5293 } 5381 }
5294 return l; 5382 return l;
5295 #endif 5383 #endif
5296 } 5384 }
5297 5385
5298 #endif 5386 #endif
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+