@@ -258,7 +258,7 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
258258/* Data structure used internally */
259259
260260struct compiling {
261- PyObject * c_code ; /* string */
261+ PyObject * c_code ; /* string */
262262 PyObject * c_consts ; /* list of objects */
263263 PyObject * c_const_dict ; /* inverse of c_consts */
264264 PyObject * c_names ; /* list of strings (names) */
@@ -2933,7 +2933,28 @@ com_continue_stmt(struct compiling *c, node *n)
29332933 if (i -- > 0 && c -> c_block [i ] == SETUP_LOOP ) {
29342934 com_addoparg (c , JUMP_ABSOLUTE , c -> c_begin );
29352935 }
2936+ else if (i <= 0 ) {
2937+ /* at the outer level */
2938+ com_error (c , PyExc_SyntaxError ,
2939+ "'continue' not properly in loop" );
2940+ }
29362941 else {
2942+ int j ;
2943+ for (j = 0 ; j <= i ; ++ j ) {
2944+ if (c -> c_block [j ] == SETUP_LOOP )
2945+ break ;
2946+ }
2947+ if (j < i + 1 ) {
2948+ /* there is a loop, but something interferes */
2949+ for (++ j ; j <= i ; ++ j ) {
2950+ if (c -> c_block [i ] == SETUP_EXCEPT
2951+ || c -> c_block [i ] == SETUP_FINALLY ) {
2952+ com_error (c , PyExc_SyntaxError ,
2953+ "'continue' not supported inside 'try' clause" );
2954+ return ;
2955+ }
2956+ }
2957+ }
29372958 com_error (c , PyExc_SyntaxError ,
29382959 "'continue' not properly in loop" );
29392960 }
0 commit comments