@@ -332,6 +332,7 @@ list2dict(PyObject *list)
332332 Py_DECREF (dict );
333333 return NULL ;
334334 }
335+ Py_DECREF (k );
335336 Py_DECREF (v );
336337 }
337338 return dict ;
@@ -511,7 +512,9 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
511512 break ;
512513 default :
513514 /* Called with an unknown opcode */
514- assert (0 );
515+ PyErr_Format (PyExc_SystemError ,
516+ "unexpected binary operation %d on a constant" ,
517+ opcode );
515518 return 0 ;
516519 }
517520 if (newconst == NULL ) {
@@ -568,7 +571,9 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
568571 break ;
569572 default :
570573 /* Called with an unknown opcode */
571- assert (0 );
574+ PyErr_Format (PyExc_SystemError ,
575+ "unexpected unary operation %d on a constant" ,
576+ opcode );
572577 return 0 ;
573578 }
574579 if (newconst == NULL ) {
@@ -1746,11 +1751,14 @@ compiler_mod(struct compiler *c, mod_ty mod)
17461751 addNone = 0 ;
17471752 break ;
17481753 case Suite_kind :
1749- assert ( 0 ); /* XXX: what should we do here? */
1750- VISIT_SEQ_IN_SCOPE ( c , stmt , mod -> v . Suite . body );
1751- break ;
1754+ PyErr_SetString ( PyExc_SystemError ,
1755+ "suite should not be possible" );
1756+ return 0 ;
17521757 default :
1753- assert (0 );
1758+ PyErr_Format (PyExc_SystemError ,
1759+ "module kind %d should not be possible" ,
1760+ mod -> kind );
1761+ return 0 ;
17541762 }
17551763 co = assemble (c , addNone );
17561764 compiler_exit_scope (c );
@@ -1929,6 +1937,7 @@ compiler_function(struct compiler *c, stmt_ty s)
19291937 return 0 ;
19301938
19311939 compiler_make_closure (c , co , asdl_seq_LEN (args -> defaults ));
1940+ Py_DECREF (co );
19321941
19331942 for (i = 0 ; i < asdl_seq_LEN (decos ); i ++ ) {
19341943 ADDOP_I (c , CALL_FUNCTION , 1 );
@@ -1984,6 +1993,8 @@ compiler_class(struct compiler *c, stmt_ty s)
19841993 return 0 ;
19851994
19861995 compiler_make_closure (c , co , 0 );
1996+ Py_DECREF (co );
1997+
19871998 ADDOP_I (c , CALL_FUNCTION , 0 );
19881999 ADDOP (c , BUILD_CLASS );
19892000 if (!compiler_nameop (c , s -> v .ClassDef .name , Store ))
@@ -2009,7 +2020,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
20092020 VISIT_SEQ (c , expr , args -> defaults );
20102021 if (!compiler_enter_scope (c , name , (void * )e , e -> lineno ))
20112022 return 0 ;
2012-
2023+
20132024 /* unpack nested arguments */
20142025 compiler_arguments (c , args );
20152026
@@ -2022,6 +2033,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
20222033 return 0 ;
20232034
20242035 compiler_make_closure (c , co , asdl_seq_LEN (args -> defaults ));
2036+ Py_DECREF (co );
20252037
20262038 return 1 ;
20272039}
@@ -2734,7 +2746,9 @@ inplace_binop(struct compiler *c, operator_ty op)
27342746 case FloorDiv :
27352747 return INPLACE_FLOOR_DIVIDE ;
27362748 }
2737- assert (0 );
2749+ PyErr_Format (PyExc_SystemError ,
2750+ "inplace binary op %d should not be possible" ,
2751+ op );
27382752 return 0 ;
27392753}
27402754
@@ -2802,9 +2816,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28022816 PyString_AS_STRING (name ));
28032817 Py_DECREF (mangled );
28042818 return 0 ;
2805- break ;
28062819 case Param :
2807- assert (0 ); /* impossible */
2820+ PyErr_SetString (PyExc_SystemError ,
2821+ "param invalid for deref variable" );
2822+ return 0 ;
28082823 }
28092824 break ;
28102825 case OP_FAST :
@@ -2816,7 +2831,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28162831 case AugStore :
28172832 break ;
28182833 case Param :
2819- assert (0 ); /* impossible */
2834+ PyErr_SetString (PyExc_SystemError ,
2835+ "param invalid for local variable" );
2836+ return 0 ;
28202837 }
28212838 ADDOP_O (c , op , mangled , varnames );
28222839 Py_DECREF (mangled );
@@ -2830,7 +2847,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28302847 case AugStore :
28312848 break ;
28322849 case Param :
2833- assert (0 ); /* impossible */
2850+ PyErr_SetString (PyExc_SystemError ,
2851+ "param invalid for global variable" );
2852+ return 0 ;
28342853 }
28352854 break ;
28362855 case OP_NAME :
@@ -2842,16 +2861,18 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28422861 case AugStore :
28432862 break ;
28442863 case Param :
2845- assert (0 ); /* impossible */
2864+ PyErr_SetString (PyExc_SystemError ,
2865+ "param invalid for name variable" );
2866+ return 0 ;
28462867 }
28472868 break ;
28482869 }
28492870
28502871 assert (op );
28512872 arg = compiler_add_o (c , dict , mangled );
2873+ Py_DECREF (mangled );
28522874 if (arg < 0 )
28532875 return 0 ;
2854- Py_DECREF (mangled );
28552876 return compiler_addop_i (c , op , arg );
28562877}
28572878
@@ -3196,6 +3217,8 @@ compiler_genexp(struct compiler *c, expr_ty e)
31963217 return 0 ;
31973218
31983219 compiler_make_closure (c , co , 0 );
3220+ Py_DECREF (co );
3221+
31993222 VISIT (c , expr , outermost_iter );
32003223 ADDOP (c , GET_ITER );
32013224 ADDOP_I (c , CALL_FUNCTION , 1 );
@@ -3325,8 +3348,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
33253348 ADDOP_NAME (c , DELETE_ATTR , e -> v .Attribute .attr , names );
33263349 break ;
33273350 case Param :
3328- assert (0 );
3329- break ;
3351+ PyErr_SetString (PyExc_SystemError ,
3352+ "param invalid in attribute expression" );
3353+ return 0 ;
33303354 }
33313355 break ;
33323356 case Subscript_kind :
@@ -3351,8 +3375,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
33513375 VISIT_SLICE (c , e -> v .Subscript .slice , Del );
33523376 break ;
33533377 case Param :
3354- assert (0 );
3355- break ;
3378+ PyErr_SetString (PyExc_SystemError ,
3379+ "param invalid in subscript expression" );
3380+ return 0 ;
33563381 }
33573382 break ;
33583383 case Name_kind :
@@ -3562,9 +3587,10 @@ compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
35623587 case AugStore :/* fall through to Store */
35633588 case Store : op = STORE_SLICE ; break ;
35643589 case Del : op = DELETE_SLICE ; break ;
3565- case Param : /* XXX impossible? */
3566- fprintf (stderr , "param invalid\n" );
3567- assert (0 );
3590+ case Param :
3591+ PyErr_SetString (PyExc_SystemError ,
3592+ "param invalid in simple slice" );
3593+ return 0 ;
35683594 }
35693595
35703596 ADDOP (c , op + slice_offset );
@@ -3586,8 +3612,9 @@ compiler_visit_nested_slice(struct compiler *c, slice_ty s,
35863612 VISIT (c , expr , s -> v .Index .value );
35873613 break ;
35883614 case ExtSlice_kind :
3589- assert (0 );
3590- break ;
3615+ PyErr_SetString (PyExc_SystemError ,
3616+ "extended slice invalid in nested slice" );
3617+ return 0 ;
35913618 }
35923619 return 1 ;
35933620}
@@ -3612,7 +3639,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
36123639 ADDOP (c , ROT_THREE );
36133640 }
36143641 return compiler_handle_subscr (c , "slice" , ctx );
3615- break ;
36163642 case ExtSlice_kind : {
36173643 int i , n = asdl_seq_LEN (s -> v .ExtSlice .dims );
36183644 for (i = 0 ; i < n ; i ++ ) {
@@ -3622,7 +3648,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
36223648 }
36233649 ADDOP_I (c , BUILD_TUPLE , n );
36243650 return compiler_handle_subscr (c , "extended slice" , ctx );
3625- break ;
36263651 }
36273652 case Index_kind :
36283653 if (ctx != AugStore )
0 commit comments