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

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, 3 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 #error "Computed gotos are not supported on this compiler." 879 #error "Computed gotos are not supported on this compiler."
880 #endif 880 #endif
881 #undef USE_COMPUTED_GOTOS 881 #undef USE_COMPUTED_GOTOS
882 #define USE_COMPUTED_GOTOS 0 882 #define USE_COMPUTED_GOTOS 0
883 #endif 883 #endif
884 884
885 #if USE_COMPUTED_GOTOS 885 #if USE_COMPUTED_GOTOS
886 /* Import the static jump table */ 886 /* Import the static jump table */
887 #include "opcode_targets.h" 887 #include "opcode_targets.h"
888 888
889 /* This macro is used when several opcodes defer to the same implementation
890 (e.g. SETUP_LOOP, SETUP_FINALLY) */
891 #define TARGET_WITH_IMPL(op, impl) \
892 TARGET_##op: \
893 opcode = op; \
894 if (HAS_ARG(op)) \
895 oparg = NEXTARG(); \
896 case op: \
897 goto impl; \
898
899 #define TARGET(op) \ 889 #define TARGET(op) \
900 TARGET_##op: \ 890 TARGET_##op: \
901 opcode = op; \
902 if (HAS_ARG(op)) \
903 oparg = NEXTARG(); \
904 case op: 891 case op:
905
906 892
907 #define DISPATCH() \ 893 #define DISPATCH() \
908 { \ 894 { \
909 if (!_Py_atomic_load_relaxed(&eval_breaker)) { \ 895 if (!_Py_atomic_load_relaxed(&eval_breaker)) { \
910 FAST_DISPATCH(); \ 896 FAST_DISPATCH(); \
911 } \ 897 } \
912 continue; \ 898 continue; \
913 } 899 }
914 900
915 #ifdef LLTRACE 901 #ifdef LLTRACE
916 #define FAST_DISPATCH() \ 902 #define FAST_DISPATCH() \
917 { \ 903 { \
918 if (!lltrace && !_Py_TracingPossible) { \ 904 if (!lltrace && !_Py_TracingPossible) { \
919 f->f_lasti = INSTR_OFFSET(); \ 905 f->f_lasti = INSTR_OFFSET(); \
920 goto *opcode_targets[*next_instr++]; \ 906 NEXTOPARG(); \
907 goto *opcode_targets[opcode]; \
921 } \ 908 } \
922 goto fast_next_opcode; \ 909 goto fast_next_opcode; \
923 } 910 }
924 #else 911 #else
925 #define FAST_DISPATCH() \ 912 #define FAST_DISPATCH() \
926 { \ 913 { \
927 if (!_Py_TracingPossible) { \ 914 if (!_Py_TracingPossible) { \
928 f->f_lasti = INSTR_OFFSET(); \ 915 f->f_lasti = INSTR_OFFSET(); \
929 goto *opcode_targets[*next_instr++]; \ 916 NEXTOPARG(); \
917 goto *opcode_targets[opcode]; \
930 } \ 918 } \
931 goto fast_next_opcode; \ 919 goto fast_next_opcode; \
932 } 920 }
933 #endif 921 #endif
934 922
935 #else 923 #else
936 #define TARGET(op) \ 924 #define TARGET(op) \
937 case op: 925 case op:
938 #define TARGET_WITH_IMPL(op, impl) \ 926
939 /* silence compiler warnings about `impl` unused */ \
940 if (0) goto impl; \
941 case op:
942 #define DISPATCH() continue 927 #define DISPATCH() continue
943 #define FAST_DISPATCH() goto fast_next_opcode 928 #define FAST_DISPATCH() goto fast_next_opcode
944 #endif 929 #endif
945 930
946 931
947 /* Tuple access macros */ 932 /* Tuple access macros */
948 933
949 #ifndef Py_DEBUG 934 #ifndef Py_DEBUG
950 #define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i)) 935 #define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
951 #else 936 #else
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 READ_TIMESTAMP(inst1); 972 READ_TIMESTAMP(inst1);
988 READ_TIMESTAMP(loop0); 973 READ_TIMESTAMP(loop0);
989 READ_TIMESTAMP(loop1); 974 READ_TIMESTAMP(loop1);
990 975
991 /* shut up the compiler */ 976 /* shut up the compiler */
992 opcode = 0; 977 opcode = 0;
993 #endif 978 #endif
994 979
995 /* Code access macros */ 980 /* Code access macros */
996 981
997 #define INSTR_OFFSET() ((int)(next_instr - first_instr)) 982 #ifdef WORDS_BIGENDIAN
998 #define NEXTOP() (*next_instr++) 983 #define OPCODE(word) ((word) >> 8)
999 #define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) 984 #define OPARG(word) ((word) & 255)
1000 #define PEEKARG() ((next_instr[2]<<8) + next_instr[1]) 985 #else
1001 #define JUMPTO(x) (next_instr = first_instr + (x)) 986 #define OPCODE(word) ((word) & 255)
1002 #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)
1003 999
1004 /* OpCode prediction macros 1000 /* OpCode prediction macros
1005 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
1006 predict the second code when the first is run. For example, 1002 predict the second code when the first is run. For example,
1007 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,
1008 those opcodes are often followed by a POP_TOP. 1004 those opcodes are often followed by a POP_TOP.
1009 1005
1010 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
1011 variable against a constant. If the pairing was good, then the 1007 variable against a constant. If the pairing was good, then the
1012 processor's own internal branch predication has a high likelihood of 1008 processor's own internal branch predication has a high likelihood of
1013 success, resulting in a nearly zero-overhead transition to the 1009 success, resulting in a nearly zero-overhead transition to the
1014 next opcode. A successful prediction saves a trip through the eval-loop 1010 next opcode. A successful prediction saves a trip through the eval-loop
1015 including its two unpredictable branches, the HAS_ARG test and the 1011 including its unpredictable switch-case branch. Combined with the
1016 switch-case. Combined with the processor's internal branch prediction, 1012 processor's internal branch prediction, a successful PREDICT has the
1017 a successful PREDICT has the effect of making the two opcodes run as if 1013 effect of making the two opcodes run as if they were a single new opcode
1018 they were a single new opcode with the bodies combined. 1014 with the bodies combined.
1019 1015
1020 If collecting opcode statistics, your choices are to either keep the 1016 If collecting opcode statistics, your choices are to either keep the
1021 predictions turned-on and interpret the results as if some opcodes 1017 predictions turned-on and interpret the results as if some opcodes
1022 had been combined or turn-off predictions so that the opcode frequency 1018 had been combined or turn-off predictions so that the opcode frequency
1023 counter updates for both opcodes. 1019 counter updates for both opcodes.
1024 1020
1025 Opcode prediction is disabled with threaded code, since the latter allows 1021 Opcode prediction is disabled with threaded code, since the latter allows
1026 the CPU to record separate branch prediction information for each 1022 the CPU to record separate branch prediction information for each
1027 opcode. 1023 opcode.
1028 1024
1029 */ 1025 */
1030 1026
1031 #if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS 1027 #if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS
1032 #define PREDICT(op) if (0) goto PRED_##op 1028 #define PREDICT(op) if (0) goto PRED_##op
1029 #else
1030 #define PREDICT(op) \
1031 do{ \
1032 unsigned short word = *next_instr; \
1033 opcode = OPCODE(word); \
1034 if (opcode == op){ \
1035 oparg = OPARG(word); \
1036 next_instr++; \
1037 goto PRED_##op; \
1038 } \
1039 } while(0)
1040 #endif
1033 #define PREDICTED(op) PRED_##op: 1041 #define PREDICTED(op) PRED_##op:
1034 #define PREDICTED_WITH_ARG(op) PRED_##op:
1035 #else
1036 #define PREDICT(op) if (*next_instr == op) goto PRED_##op
1037 #define PREDICTED(op) PRED_##op: next_instr++
1038 #define PREDICTED_WITH_ARG(op) PRED_##op: oparg = PEEKARG(); next_instr += 3
1039 #endif
1040 1042
1041 1043
1042 /* Stack manipulation macros */ 1044 /* Stack manipulation macros */
1043 1045
1044 /* 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
1045 co_stacksize are ints. */ 1047 co_stacksize are ints. */
1046 #define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack)) 1048 #define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack))
1047 #define EMPTY() (STACK_LEVEL() == 0) 1049 #define EMPTY() (STACK_LEVEL() == 0)
1048 #define TOP() (stack_pointer[-1]) 1050 #define TOP() (stack_pointer[-1])
1049 #define SECOND() (stack_pointer[-2]) 1051 #define SECOND() (stack_pointer[-2])
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 Py_XDECREF(tmp); } while (0) 1095 Py_XDECREF(tmp); } while (0)
1094 1096
1095 1097
1096 #define UNWIND_BLOCK(b) \ 1098 #define UNWIND_BLOCK(b) \
1097 while (STACK_LEVEL() > (b)->b_level) { \ 1099 while (STACK_LEVEL() > (b)->b_level) { \
1098 PyObject *v = POP(); \ 1100 PyObject *v = POP(); \
1099 Py_XDECREF(v); \ 1101 Py_XDECREF(v); \
1100 } 1102 }
1101 1103
1102 #define UNWIND_EXCEPT_HANDLER(b) \ 1104 #define UNWIND_EXCEPT_HANDLER(b) \
1103 { \ 1105 do { \
1104 PyObject *type, *value, *traceback; \ 1106 PyObject *type, *value, *traceback; \
1105 assert(STACK_LEVEL() >= (b)->b_level + 3); \ 1107 assert(STACK_LEVEL() >= (b)->b_level + 3); \
1106 while (STACK_LEVEL() > (b)->b_level + 3) { \ 1108 while (STACK_LEVEL() > (b)->b_level + 3) { \
1107 value = POP(); \ 1109 value = POP(); \
1108 Py_XDECREF(value); \ 1110 Py_XDECREF(value); \
1109 } \ 1111 } \
1110 type = tstate->exc_type; \ 1112 type = tstate->exc_type; \
1111 value = tstate->exc_value; \ 1113 value = tstate->exc_value; \
1112 traceback = tstate->exc_traceback; \ 1114 traceback = tstate->exc_traceback; \
1113 tstate->exc_type = POP(); \ 1115 tstate->exc_type = POP(); \
1114 tstate->exc_value = POP(); \ 1116 tstate->exc_value = POP(); \
1115 tstate->exc_traceback = POP(); \ 1117 tstate->exc_traceback = POP(); \
1116 Py_XDECREF(type); \ 1118 Py_XDECREF(type); \
1117 Py_XDECREF(value); \ 1119 Py_XDECREF(value); \
1118 Py_XDECREF(traceback); \ 1120 Py_XDECREF(traceback); \
1119 } 1121 } while(0)
1120 1122
1121 /* Start of code */ 1123 /* Start of code */
1122 1124
1123 /* push frame */ 1125 /* push frame */
1124 if (Py_EnterRecursiveCall("")) 1126 if (Py_EnterRecursiveCall(""))
1125 return NULL; 1127 return NULL;
1126 1128
1127 tstate->frame = f; 1129 tstate->frame = f;
1128 1130
1129 if (tstate->use_tracing) { 1131 if (tstate->use_tracing) {
(...skipping 28 matching lines...) Expand all
1158 goto exit_eval_frame; 1160 goto exit_eval_frame;
1159 } 1161 }
1160 } 1162 }
1161 } 1163 }
1162 1164
1163 co = f->f_code; 1165 co = f->f_code;
1164 names = co->co_names; 1166 names = co->co_names;
1165 consts = co->co_consts; 1167 consts = co->co_consts;
1166 fastlocals = f->f_localsplus; 1168 fastlocals = f->f_localsplus;
1167 freevars = f->f_localsplus + co->co_nlocals; 1169 freevars = f->f_localsplus + co->co_nlocals;
1168 first_instr = (unsigned char*) PyBytes_AS_STRING(co->co_code); 1170 assert(PyBytes_Check(co->co_code));
1169 /* An explanation is in order for the next line. 1171 assert(PyBytes_GET_SIZE(co->co_code) <= INT_MAX);
1170 1172 assert(PyBytes_GET_SIZE(co->co_code) % 2 == 0);
1171 f->f_lasti now refers to the index of the last instruction 1173 assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(co->co_code), 2));
1172 executed. You might think this was obvious from the name, but 1174 first_instr = (unsigned short*) PyBytes_AS_STRING(co->co_code);
1173 this wasn't always true before 2.3! PyFrame_New now sets 1175 /*
1174 f->f_lasti to -1 (i.e. the index *before* the first instruction) 1176 f->f_lasti refers to the index of the last instruction,
1175 and YIELD_VALUE doesn't fiddle with f_lasti any more. So this 1177 unless it's -1 in which case next_instr should be first_instr.
1176 does work. Promise. 1178
1177 YIELD_FROM sets f_lasti to itself, in order to repeated yield 1179 YIELD_FROM sets f_lasti to itself, in order to repeatedly yield
1178 multiple values. 1180 multiple values.
1179 1181
1180 When the PREDICT() macros are enabled, some opcode pairs follow in 1182 When the PREDICT() macros are enabled, some opcode pairs follow in
1181 direct succession without updating f->f_lasti. A successful 1183 direct succession without updating f->f_lasti. A successful
1182 prediction effectively links the two codes together as if they 1184 prediction effectively links the two codes together as if they
1183 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
1184 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
1185 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
1186 at to the beginning of the combined pair.) 1188 to the beginning of the combined pair.)
1187 */ 1189 */
1188 next_instr = first_instr + f->f_lasti + 1; 1190 next_instr = first_instr;
1191 if (f->f_lasti >= 0) {
1192 assert(f->f_lasti % 2 == 0);
1193 next_instr += f->f_lasti/2 + 1;
1194 }
1189 stack_pointer = f->f_stacktop; 1195 stack_pointer = f->f_stacktop;
1190 assert(stack_pointer != NULL); 1196 assert(stack_pointer != NULL);
1191 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */ 1197 f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
1192 f->f_executing = 1; 1198 f->f_executing = 1;
1193 1199
1194 if (co->co_flags & (CO_GENERATOR | CO_COROUTINE)) { 1200 if (co->co_flags & (CO_GENERATOR | CO_COROUTINE)) {
1195 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) {
1196 /* We were in an except handler when we left, 1202 /* We were in an except handler when we left,
1197 restore the exception state which was put aside 1203 restore the exception state which was put aside
1198 (see YIELD_VALUE). */ 1204 (see YIELD_VALUE). */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 1248
1243 /* Do periodic things. Doing this every time through 1249 /* Do periodic things. Doing this every time through
1244 the loop would add too much overhead, so we do it 1250 the loop would add too much overhead, so we do it
1245 only every Nth instruction. We also do it if 1251 only every Nth instruction. We also do it if
1246 ``pendingcalls_to_do'' is set, i.e. when an asynchronous 1252 ``pendingcalls_to_do'' is set, i.e. when an asynchronous
1247 event needs attention (e.g. a signal handler or 1253 event needs attention (e.g. a signal handler or
1248 async I/O handler); see Py_AddPendingCall() and 1254 async I/O handler); see Py_AddPendingCall() and
1249 Py_MakePendingCalls() above. */ 1255 Py_MakePendingCalls() above. */
1250 1256
1251 if (_Py_atomic_load_relaxed(&eval_breaker)) { 1257 if (_Py_atomic_load_relaxed(&eval_breaker)) {
1252 if (*next_instr == SETUP_FINALLY) { 1258 if (OPCODE(*next_instr) == SETUP_FINALLY) {
1253 /* Make the last opcode before 1259 /* Make the last opcode before
1254 a try: finally: block uninterruptible. */ 1260 a try: finally: block uninterruptible. */
1255 goto fast_next_opcode; 1261 goto fast_next_opcode;
1256 } 1262 }
1257 #ifdef WITH_TSC 1263 #ifdef WITH_TSC
1258 ticked = 1; 1264 ticked = 1;
1259 #endif 1265 #endif
1260 if (_Py_atomic_load_relaxed(&pendingcalls_to_do)) { 1266 if (_Py_atomic_load_relaxed(&pendingcalls_to_do)) {
1261 if (Py_MakePendingCalls() < 0) 1267 if (Py_MakePendingCalls() < 0)
1262 goto error; 1268 goto error;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 stack_pointer = f->f_stacktop; 1321 stack_pointer = f->f_stacktop;
1316 f->f_stacktop = NULL; 1322 f->f_stacktop = NULL;
1317 } 1323 }
1318 if (err) 1324 if (err)
1319 /* trace function raised an exception */ 1325 /* trace function raised an exception */
1320 goto error; 1326 goto error;
1321 } 1327 }
1322 1328
1323 /* Extract opcode and argument */ 1329 /* Extract opcode and argument */
1324 1330
1325 opcode = NEXTOP(); 1331 NEXTOPARG();
1326 oparg = 0; /* allows oparg to be stored in a register because
1327 it doesn't have to be remembered across a full loop */
1328 if (HAS_ARG(opcode))
1329 oparg = NEXTARG();
1330 dispatch_opcode: 1332 dispatch_opcode:
1331 #ifdef DYNAMIC_EXECUTION_PROFILE 1333 #ifdef DYNAMIC_EXECUTION_PROFILE
1332 #ifdef DXPAIRS 1334 #ifdef DXPAIRS
1333 dxpairs[lastopcode][opcode]++; 1335 dxpairs[lastopcode][opcode]++;
1334 lastopcode = opcode; 1336 lastopcode = opcode;
1335 #endif 1337 #endif
1336 dxp[opcode]++; 1338 dxp[opcode]++;
1337 #endif 1339 #endif
1338 1340
1339 #ifdef LLTRACE 1341 #ifdef LLTRACE
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 FAST_DISPATCH(); 1379 FAST_DISPATCH();
1378 } 1380 }
1379 1381
1380 TARGET(LOAD_CONST) { 1382 TARGET(LOAD_CONST) {
1381 PyObject *value = GETITEM(consts, oparg); 1383 PyObject *value = GETITEM(consts, oparg);
1382 Py_INCREF(value); 1384 Py_INCREF(value);
1383 PUSH(value); 1385 PUSH(value);
1384 FAST_DISPATCH(); 1386 FAST_DISPATCH();
1385 } 1387 }
1386 1388
1387 PREDICTED_WITH_ARG(STORE_FAST); 1389 PREDICTED(STORE_FAST);
1388 TARGET(STORE_FAST) { 1390 TARGET(STORE_FAST) {
1389 PyObject *value = POP(); 1391 PyObject *value = POP();
1390 SETLOCAL(oparg, value); 1392 SETLOCAL(oparg, value);
1391 FAST_DISPATCH(); 1393 FAST_DISPATCH();
1392 } 1394 }
1393 1395
1394 TARGET(POP_TOP) { 1396 TARGET(POP_TOP) {
1395 PyObject *value = POP(); 1397 PyObject *value = POP();
1396 Py_DECREF(value); 1398 Py_DECREF(value);
1397 FAST_DISPATCH(); 1399 FAST_DISPATCH();
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 goto fast_block_end; 1928 goto fast_block_end;
1927 } 1929 }
1928 1930
1929 TARGET(GET_AITER) { 1931 TARGET(GET_AITER) {
1930 unaryfunc getter = NULL; 1932 unaryfunc getter = NULL;
1931 PyObject *iter = NULL; 1933 PyObject *iter = NULL;
1932 PyObject *awaitable = NULL; 1934 PyObject *awaitable = NULL;
1933 PyObject *obj = TOP(); 1935 PyObject *obj = TOP();
1934 PyTypeObject *type = Py_TYPE(obj); 1936 PyTypeObject *type = Py_TYPE(obj);
1935 1937
1936 if (type->tp_as_async != NULL) 1938 if (type->tp_as_async != NULL) {
1937 getter = type->tp_as_async->am_aiter; 1939 getter = type->tp_as_async->am_aiter;
1940 }
1938 1941
1939 if (getter != NULL) { 1942 if (getter != NULL) {
1940 iter = (*getter)(obj); 1943 iter = (*getter)(obj);
1941 Py_DECREF(obj); 1944 Py_DECREF(obj);
1942 if (iter == NULL) { 1945 if (iter == NULL) {
1943 SET_TOP(NULL); 1946 SET_TOP(NULL);
1944 goto error; 1947 goto error;
1945 } 1948 }
1946 } 1949 }
1947 else { 1950 else {
1948 SET_TOP(NULL); 1951 SET_TOP(NULL);
1949 PyErr_Format( 1952 PyErr_Format(
1950 PyExc_TypeError, 1953 PyExc_TypeError,
1951 "'async for' requires an object with " 1954 "'async for' requires an object with "
1952 "__aiter__ method, got %.100s", 1955 "__aiter__ method, got %.100s",
1953 type->tp_name); 1956 type->tp_name);
1954 Py_DECREF(obj); 1957 Py_DECREF(obj);
1955 goto error; 1958 goto error;
1956 } 1959 }
1957 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
1958 awaitable = _PyCoro_GetAwaitableIter(iter); 1982 awaitable = _PyCoro_GetAwaitableIter(iter);
1959 if (awaitable == NULL) { 1983 if (awaitable == NULL) {
1960 SET_TOP(NULL); 1984 SET_TOP(NULL);
1961 PyErr_Format( 1985 PyErr_Format(
1962 PyExc_TypeError, 1986 PyExc_TypeError,
1963 "'async for' received an invalid object " 1987 "'async for' received an invalid object "
1964 "from __aiter__: %.100s", 1988 "from __aiter__: %.100s",
1965 Py_TYPE(iter)->tp_name); 1989 Py_TYPE(iter)->tp_name);
1966 1990
1967 Py_DECREF(iter); 1991 Py_DECREF(iter);
1968 goto error; 1992 goto error;
1969 } else 1993 } else {
1970 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 }
1971 2009
1972 SET_TOP(awaitable); 2010 SET_TOP(awaitable);
1973 DISPATCH(); 2011 DISPATCH();
1974 } 2012 }
1975 2013
1976 TARGET(GET_ANEXT) { 2014 TARGET(GET_ANEXT) {
1977 unaryfunc getter = NULL; 2015 unaryfunc getter = NULL;
1978 PyObject *next_iter = NULL; 2016 PyObject *next_iter = NULL;
1979 PyObject *awaitable = NULL; 2017 PyObject *awaitable = NULL;
1980 PyObject *aiter = TOP(); 2018 PyObject *aiter = TOP();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 if (err < 0) 2106 if (err < 0)
2069 goto error; 2107 goto error;
2070 Py_DECREF(reciever); 2108 Py_DECREF(reciever);
2071 SET_TOP(val); 2109 SET_TOP(val);
2072 DISPATCH(); 2110 DISPATCH();
2073 } 2111 }
2074 /* x remains on stack, retval is value to be yielded */ 2112 /* x remains on stack, retval is value to be yielded */
2075 f->f_stacktop = stack_pointer; 2113 f->f_stacktop = stack_pointer;
2076 why = WHY_YIELD; 2114 why = WHY_YIELD;
2077 /* and repeat... */ 2115 /* and repeat... */
2078 f->f_lasti--; 2116 f->f_lasti -= 2;
2079 goto fast_yield; 2117 goto fast_yield;
2080 } 2118 }
2081 2119
2082 TARGET(YIELD_VALUE) { 2120 TARGET(YIELD_VALUE) {
2083 retval = POP(); 2121 retval = POP();
2084 f->f_stacktop = stack_pointer; 2122 f->f_stacktop = stack_pointer;
2085 why = WHY_YIELD; 2123 why = WHY_YIELD;
2086 goto fast_yield; 2124 goto fast_yield;
2087 } 2125 }
2088 2126
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 err = PyObject_DelItem(ns, name); 2244 err = PyObject_DelItem(ns, name);
2207 if (err != 0) { 2245 if (err != 0) {
2208 format_exc_check_arg(PyExc_NameError, 2246 format_exc_check_arg(PyExc_NameError,
2209 NAME_ERROR_MSG, 2247 NAME_ERROR_MSG,
2210 name); 2248 name);
2211 goto error; 2249 goto error;
2212 } 2250 }
2213 DISPATCH(); 2251 DISPATCH();
2214 } 2252 }
2215 2253
2216 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); 2254 PREDICTED(UNPACK_SEQUENCE);
2217 TARGET(UNPACK_SEQUENCE) { 2255 TARGET(UNPACK_SEQUENCE) {
2218 PyObject *seq = POP(), *item, **items; 2256 PyObject *seq = POP(), *item, **items;
2219 if (PyTuple_CheckExact(seq) && 2257 if (PyTuple_CheckExact(seq) &&
2220 PyTuple_GET_SIZE(seq) == oparg) { 2258 PyTuple_GET_SIZE(seq) == oparg) {
2221 items = ((PyTupleObject *)seq)->ob_item; 2259 items = ((PyTupleObject *)seq)->ob_item;
2222 while (oparg--) { 2260 while (oparg--) {
2223 item = items[oparg]; 2261 item = items[oparg];
2224 Py_INCREF(item); 2262 Py_INCREF(item);
2225 PUSH(item); 2263 PUSH(item);
2226 } 2264 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 if (list == NULL) 2542 if (list == NULL)
2505 goto error; 2543 goto error;
2506 while (--oparg >= 0) { 2544 while (--oparg >= 0) {
2507 PyObject *item = POP(); 2545 PyObject *item = POP();
2508 PyList_SET_ITEM(list, oparg, item); 2546 PyList_SET_ITEM(list, oparg, item);
2509 } 2547 }
2510 PUSH(list); 2548 PUSH(list);
2511 DISPATCH(); 2549 DISPATCH();
2512 } 2550 }
2513 2551
2514 TARGET_WITH_IMPL(BUILD_TUPLE_UNPACK, _build_list_unpack) 2552 TARGET(BUILD_TUPLE_UNPACK)
2515 TARGET(BUILD_LIST_UNPACK) 2553 TARGET(BUILD_LIST_UNPACK) {
2516 _build_list_unpack: {
2517 int convert_to_tuple = opcode == BUILD_TUPLE_UNPACK; 2554 int convert_to_tuple = opcode == BUILD_TUPLE_UNPACK;
2518 int i; 2555 int i;
2519 PyObject *sum = PyList_New(0); 2556 PyObject *sum = PyList_New(0);
2520 PyObject *return_value; 2557 PyObject *return_value;
2521 if (sum == NULL) 2558 if (sum == NULL)
2522 goto error; 2559 goto error;
2523 2560
2524 for (i = oparg; i > 0; i--) { 2561 for (i = oparg; i > 0; i--) {
2525 PyObject *none_val; 2562 PyObject *none_val;
2526 2563
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 } 2640 }
2604 2641
2605 while (oparg--) { 2642 while (oparg--) {
2606 Py_DECREF(POP()); 2643 Py_DECREF(POP());
2607 Py_DECREF(POP()); 2644 Py_DECREF(POP());
2608 } 2645 }
2609 PUSH(map); 2646 PUSH(map);
2610 DISPATCH(); 2647 DISPATCH();
2611 } 2648 }
2612 2649
2613 TARGET_WITH_IMPL(BUILD_MAP_UNPACK_WITH_CALL, _build_map_unpack) 2650 TARGET(BUILD_CONST_KEY_MAP) {
2614 TARGET(BUILD_MAP_UNPACK) 2651 int i;
2615 _build_map_unpack: { 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
2683 TARGET(BUILD_MAP_UNPACK_WITH_CALL)
2684 TARGET(BUILD_MAP_UNPACK) {
2616 int with_call = opcode == BUILD_MAP_UNPACK_WITH_CALL; 2685 int with_call = opcode == BUILD_MAP_UNPACK_WITH_CALL;
2617 int num_maps; 2686 int num_maps;
2618 int function_location; 2687 int function_location;
2619 int i; 2688 int i;
2620 PyObject *sum = PyDict_New(); 2689 PyObject *sum = PyDict_New();
2621 if (sum == NULL) 2690 if (sum == NULL)
2622 goto error; 2691 goto error;
2623 if (with_call) { 2692 if (with_call) {
2624 num_maps = oparg & 0xff; 2693 num_maps = oparg & 0xff;
2625 function_location = (oparg>>8) & 0xff; 2694 function_location = (oparg>>8) & 0xff;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 if (res == NULL) 2881 if (res == NULL)
2813 goto error; 2882 goto error;
2814 DISPATCH(); 2883 DISPATCH();
2815 } 2884 }
2816 2885
2817 TARGET(JUMP_FORWARD) { 2886 TARGET(JUMP_FORWARD) {
2818 JUMPBY(oparg); 2887 JUMPBY(oparg);
2819 FAST_DISPATCH(); 2888 FAST_DISPATCH();
2820 } 2889 }
2821 2890
2822 PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE); 2891 PREDICTED(POP_JUMP_IF_FALSE);
2823 TARGET(POP_JUMP_IF_FALSE) { 2892 TARGET(POP_JUMP_IF_FALSE) {
2824 PyObject *cond = POP(); 2893 PyObject *cond = POP();
2825 int err; 2894 int err;
2826 if (cond == Py_True) { 2895 if (cond == Py_True) {
2827 Py_DECREF(cond); 2896 Py_DECREF(cond);
2828 FAST_DISPATCH(); 2897 FAST_DISPATCH();
2829 } 2898 }
2830 if (cond == Py_False) { 2899 if (cond == Py_False) {
2831 Py_DECREF(cond); 2900 Py_DECREF(cond);
2832 JUMPTO(oparg); 2901 JUMPTO(oparg);
2833 FAST_DISPATCH(); 2902 FAST_DISPATCH();
2834 } 2903 }
2835 err = PyObject_IsTrue(cond); 2904 err = PyObject_IsTrue(cond);
2836 Py_DECREF(cond); 2905 Py_DECREF(cond);
2837 if (err > 0) 2906 if (err > 0)
2838 err = 0; 2907 err = 0;
2839 else if (err == 0) 2908 else if (err == 0)
2840 JUMPTO(oparg); 2909 JUMPTO(oparg);
2841 else 2910 else
2842 goto error; 2911 goto error;
2843 DISPATCH(); 2912 DISPATCH();
2844 } 2913 }
2845 2914
2846 PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE); 2915 PREDICTED(POP_JUMP_IF_TRUE);
2847 TARGET(POP_JUMP_IF_TRUE) { 2916 TARGET(POP_JUMP_IF_TRUE) {
2848 PyObject *cond = POP(); 2917 PyObject *cond = POP();
2849 int err; 2918 int err;
2850 if (cond == Py_False) { 2919 if (cond == Py_False) {
2851 Py_DECREF(cond); 2920 Py_DECREF(cond);
2852 FAST_DISPATCH(); 2921 FAST_DISPATCH();
2853 } 2922 }
2854 if (cond == Py_True) { 2923 if (cond == Py_True) {
2855 Py_DECREF(cond); 2924 Py_DECREF(cond);
2856 JUMPTO(oparg); 2925 JUMPTO(oparg);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 } 2982 }
2914 else if (err == 0) { 2983 else if (err == 0) {
2915 STACKADJ(-1); 2984 STACKADJ(-1);
2916 Py_DECREF(cond); 2985 Py_DECREF(cond);
2917 } 2986 }
2918 else 2987 else
2919 goto error; 2988 goto error;
2920 DISPATCH(); 2989 DISPATCH();
2921 } 2990 }
2922 2991
2923 PREDICTED_WITH_ARG(JUMP_ABSOLUTE); 2992 PREDICTED(JUMP_ABSOLUTE);
2924 TARGET(JUMP_ABSOLUTE) { 2993 TARGET(JUMP_ABSOLUTE) {
2925 JUMPTO(oparg); 2994 JUMPTO(oparg);
2926 #if FAST_LOOPS 2995 #if FAST_LOOPS
2927 /* Enabling this path speeds-up all while and for-loops by bypassing 2996 /* Enabling this path speeds-up all while and for-loops by bypassing
2928 the per-loop checks for signals. By default, this should be turn ed-off 2997 the per-loop checks for signals. By default, this should be turn ed-off
2929 because it prevents detection of a control-break in tight loops l ike 2998 because it prevents detection of a control-break in tight loops l ike
2930 "while 1: pass". Compile with this option turned-on when you nee d 2999 "while 1: pass". Compile with this option turned-on when you nee d
2931 the speed-up and do not need break checking inside tight loops (o nes 3000 the speed-up and do not need break checking inside tight loops (o nes
2932 that contain only instructions ending with FAST_DISPATCH). 3001 that contain only instructions ending with FAST_DISPATCH).
2933 */ 3002 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 /* `iterable` is not a generator. */ 3039 /* `iterable` is not a generator. */
2971 iter = PyObject_GetIter(iterable); 3040 iter = PyObject_GetIter(iterable);
2972 Py_DECREF(iterable); 3041 Py_DECREF(iterable);
2973 SET_TOP(iter); 3042 SET_TOP(iter);
2974 if (iter == NULL) 3043 if (iter == NULL)
2975 goto error; 3044 goto error;
2976 } 3045 }
2977 DISPATCH(); 3046 DISPATCH();
2978 } 3047 }
2979 3048
2980 PREDICTED_WITH_ARG(FOR_ITER); 3049 PREDICTED(FOR_ITER);
2981 TARGET(FOR_ITER) { 3050 TARGET(FOR_ITER) {
2982 /* before: [iter]; after: [iter, iter()] *or* [] */ 3051 /* before: [iter]; after: [iter, iter()] *or* [] */
2983 PyObject *iter = TOP(); 3052 PyObject *iter = TOP();
2984 PyObject *next = (*iter->ob_type->tp_iternext)(iter); 3053 PyObject *next = (*iter->ob_type->tp_iternext)(iter);
2985 if (next != NULL) { 3054 if (next != NULL) {
2986 PUSH(next); 3055 PUSH(next);
2987 PREDICT(STORE_FAST); 3056 PREDICT(STORE_FAST);
2988 PREDICT(UNPACK_SEQUENCE); 3057 PREDICT(UNPACK_SEQUENCE);
2989 DISPATCH(); 3058 DISPATCH();
2990 } 3059 }
(...skipping 17 matching lines...) Expand all
3008 } 3077 }
3009 3078
3010 TARGET(CONTINUE_LOOP) { 3079 TARGET(CONTINUE_LOOP) {
3011 retval = PyLong_FromLong(oparg); 3080 retval = PyLong_FromLong(oparg);
3012 if (retval == NULL) 3081 if (retval == NULL)
3013 goto error; 3082 goto error;
3014 why = WHY_CONTINUE; 3083 why = WHY_CONTINUE;
3015 goto fast_block_end; 3084 goto fast_block_end;
3016 } 3085 }
3017 3086
3018 TARGET_WITH_IMPL(SETUP_LOOP, _setup_finally) 3087 TARGET(SETUP_LOOP)
3019 TARGET_WITH_IMPL(SETUP_EXCEPT, _setup_finally) 3088 TARGET(SETUP_EXCEPT)
3020 TARGET(SETUP_FINALLY) 3089 TARGET(SETUP_FINALLY) {
3021 _setup_finally: {
3022 /* NOTE: If you add any new block-setup opcodes that 3090 /* NOTE: If you add any new block-setup opcodes that
3023 are not try/except/finally handlers, you may need 3091 are not try/except/finally handlers, you may need
3024 to update the PyGen_NeedsFinalizing() function. 3092 to update the PyGen_NeedsFinalizing() function.
3025 */ 3093 */
3026 3094
3027 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, 3095 PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
3028 STACK_LEVEL()); 3096 STACK_LEVEL());
3029 DISPATCH(); 3097 DISPATCH();
3030 } 3098 }
3031 3099
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 #else 3274 #else
3207 res = call_function(&sp, oparg); 3275 res = call_function(&sp, oparg);
3208 #endif 3276 #endif
3209 stack_pointer = sp; 3277 stack_pointer = sp;
3210 PUSH(res); 3278 PUSH(res);
3211 if (res == NULL) 3279 if (res == NULL)
3212 goto error; 3280 goto error;
3213 DISPATCH(); 3281 DISPATCH();
3214 } 3282 }
3215 3283
3216 TARGET_WITH_IMPL(CALL_FUNCTION_VAR, _call_function_var_kw) 3284 TARGET(CALL_FUNCTION_VAR)
3217 TARGET_WITH_IMPL(CALL_FUNCTION_KW, _call_function_var_kw) 3285 TARGET(CALL_FUNCTION_KW)
3218 TARGET(CALL_FUNCTION_VAR_KW) 3286 TARGET(CALL_FUNCTION_VAR_KW) {
3219 _call_function_var_kw: {
3220 int na = oparg & 0xff; 3287 int na = oparg & 0xff;
3221 int nk = (oparg>>8) & 0xff; 3288 int nk = (oparg>>8) & 0xff;
3222 int flags = (opcode - CALL_FUNCTION) & 3; 3289 int flags = (opcode - CALL_FUNCTION) & 3;
3223 int n = na + 2 * nk; 3290 int n = na + 2 * nk;
3224 PyObject **pfunc, *func, **sp, *res; 3291 PyObject **pfunc, *func, **sp, *res;
3225 PCALL(PCALL_ALL); 3292 PCALL(PCALL_ALL);
3226 if (flags & CALL_FLAG_VAR) 3293 if (flags & CALL_FLAG_VAR)
3227 n++; 3294 n++;
3228 if (flags & CALL_FLAG_KW) 3295 if (flags & CALL_FLAG_KW)
3229 n++; 3296 n++;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 PyObject *codeobj = POP(); 3330 PyObject *codeobj = POP();
3264 PyFunctionObject *func = (PyFunctionObject *) 3331 PyFunctionObject *func = (PyFunctionObject *)
3265 PyFunction_NewWithQualName(codeobj, f->f_globals, qualname); 3332 PyFunction_NewWithQualName(codeobj, f->f_globals, qualname);
3266 3333
3267 Py_DECREF(codeobj); 3334 Py_DECREF(codeobj);
3268 Py_DECREF(qualname); 3335 Py_DECREF(qualname);
3269 if (func == NULL) { 3336 if (func == NULL) {
3270 goto error; 3337 goto error;
3271 } 3338 }
3272 3339
3273 /* NB: Py_None is not an acceptable value for these. */
3274 if (oparg & 0x08) { 3340 if (oparg & 0x08) {
3341 assert(PyTuple_CheckExact(TOP()));
3275 func ->func_closure = POP(); 3342 func ->func_closure = POP();
3276 } 3343 }
3277 if (oparg & 0x04) { 3344 if (oparg & 0x04) {
3345 assert(PyDict_CheckExact(TOP()));
3278 func->func_annotations = POP(); 3346 func->func_annotations = POP();
3279 } 3347 }
3280 if (oparg & 0x02) { 3348 if (oparg & 0x02) {
3349 assert(PyDict_CheckExact(TOP()));
3281 func->func_kwdefaults = POP(); 3350 func->func_kwdefaults = POP();
3282 } 3351 }
3283 if (oparg & 0x01) { 3352 if (oparg & 0x01) {
3353 assert(PyTuple_CheckExact(TOP()));
3284 func->func_defaults = POP(); 3354 func->func_defaults = POP();
3285 } 3355 }
3286 3356
3287 PUSH((PyObject *)func); 3357 PUSH((PyObject *)func);
3288 DISPATCH(); 3358 DISPATCH();
3289 } 3359 }
3290 3360
3291 TARGET(BUILD_SLICE) { 3361 TARGET(BUILD_SLICE) {
3292 PyObject *start, *stop, *step, *slice; 3362 PyObject *start, *stop, *step, *slice;
3293 if (oparg == 3) 3363 if (oparg == 3)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3358 if (result == NULL) { 3428 if (result == NULL) {
3359 goto error; 3429 goto error;
3360 } 3430 }
3361 } 3431 }
3362 3432
3363 PUSH(result); 3433 PUSH(result);
3364 DISPATCH(); 3434 DISPATCH();
3365 } 3435 }
3366 3436
3367 TARGET(EXTENDED_ARG) { 3437 TARGET(EXTENDED_ARG) {
3368 opcode = NEXTOP(); 3438 int oldoparg = oparg;
3369 oparg = oparg<<16 | NEXTARG(); 3439 NEXTOPARG();
3440 oparg |= oldoparg << 8;
3370 goto dispatch_opcode; 3441 goto dispatch_opcode;
3371 } 3442 }
3372 3443
3373 3444
3374 #if USE_COMPUTED_GOTOS 3445 #if USE_COMPUTED_GOTOS
3375 _unknown_opcode: 3446 _unknown_opcode:
3376 #endif 3447 #endif
3377 default: 3448 default:
3378 fprintf(stderr, 3449 fprintf(stderr,
3379 "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
5214 } else { 5285 } else {
5215 name = PyTuple_GET_ITEM(co->co_freevars, oparg - 5286 name = PyTuple_GET_ITEM(co->co_freevars, oparg -
5216 PyTuple_GET_SIZE(co->co_cellvars)); 5287 PyTuple_GET_SIZE(co->co_cellvars));
5217 format_exc_check_arg(PyExc_NameError, 5288 format_exc_check_arg(PyExc_NameError,
5218 UNBOUNDFREE_ERROR_MSG, name); 5289 UNBOUNDFREE_ERROR_MSG, name);
5219 } 5290 }
5220 } 5291 }
5221 5292
5222 static PyObject * 5293 static PyObject *
5223 unicode_concatenate(PyObject *v, PyObject *w, 5294 unicode_concatenate(PyObject *v, PyObject *w,
5224 PyFrameObject *f, unsigned char *next_instr) 5295 PyFrameObject *f, const unsigned short *next_instr)
5225 { 5296 {
5226 PyObject *res; 5297 PyObject *res;
5227 if (Py_REFCNT(v) == 2) { 5298 if (Py_REFCNT(v) == 2) {
5228 /* In the common case, there are 2 references to the value 5299 /* In the common case, there are 2 references to the value
5229 * stored in 'variable' when the += is performed: one on the 5300 * stored in 'variable' when the += is performed: one on the
5230 * value stack (in 'v') and one still stored in the 5301 * value stack (in 'v') and one still stored in the
5231 * 'variable'. We try to delete the variable now to reduce 5302 * 'variable'. We try to delete the variable now to reduce
5232 * the refcnt to 1. 5303 * the refcnt to 1.
5233 */ 5304 */
5234 switch (*next_instr) { 5305 int opcode, oparg;
5306 NEXTOPARG();
5307 switch (opcode) {
5235 case STORE_FAST: 5308 case STORE_FAST:
5236 { 5309 {
5237 int oparg = PEEKARG();
5238 PyObject **fastlocals = f->f_localsplus; 5310 PyObject **fastlocals = f->f_localsplus;
5239 if (GETLOCAL(oparg) == v) 5311 if (GETLOCAL(oparg) == v)
5240 SETLOCAL(oparg, NULL); 5312 SETLOCAL(oparg, NULL);
5241 break; 5313 break;
5242 } 5314 }
5243 case STORE_DEREF: 5315 case STORE_DEREF:
5244 { 5316 {
5245 PyObject **freevars = (f->f_localsplus + 5317 PyObject **freevars = (f->f_localsplus +
5246 f->f_code->co_nlocals); 5318 f->f_code->co_nlocals);
5247 PyObject *c = freevars[PEEKARG()]; 5319 PyObject *c = freevars[oparg];
5248 if (PyCell_GET(c) == v) 5320 if (PyCell_GET(c) == v)
5249 PyCell_Set(c, NULL); 5321 PyCell_Set(c, NULL);
5250 break; 5322 break;
5251 } 5323 }
5252 case STORE_NAME: 5324 case STORE_NAME:
5253 { 5325 {
5254 PyObject *names = f->f_code->co_names; 5326 PyObject *names = f->f_code->co_names;
5255 PyObject *name = GETITEM(names, PEEKARG()); 5327 PyObject *name = GETITEM(names, oparg);
5256 PyObject *locals = f->f_locals; 5328 PyObject *locals = f->f_locals;
5257 if (PyDict_CheckExact(locals) && 5329 if (PyDict_CheckExact(locals) &&
5258 PyDict_GetItem(locals, name) == v) { 5330 PyDict_GetItem(locals, name) == v) {
5259 if (PyDict_DelItem(locals, name) != 0) { 5331 if (PyDict_DelItem(locals, name) != 0) {
5260 PyErr_Clear(); 5332 PyErr_Clear();
5261 } 5333 }
5262 } 5334 }
5263 break; 5335 break;
5264 } 5336 }
5265 } 5337 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5305 Py_DECREF(l); 5377 Py_DECREF(l);
5306 return NULL; 5378 return NULL;
5307 } 5379 }
5308 PyList_SetItem(l, i, x); 5380 PyList_SetItem(l, i, x);
5309 } 5381 }
5310 return l; 5382 return l;
5311 #endif 5383 #endif
5312 } 5384 }
5313 5385
5314 #endif 5386 #endif
LEFTRIGHT

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