Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e6bf49

Browse files
committed
Handle more error conditions with SystemError
1 parent db83eb3 commit 4e6bf49

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

Python/compile.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,8 +2760,7 @@ inplace_binop(struct compiler *c, operator_ty op)
27602760
return INPLACE_FLOOR_DIVIDE;
27612761
}
27622762
PyErr_Format(PyExc_SystemError,
2763-
"inplace binary op %d should not be possible",
2764-
op);
2763+
"inplace binary op %d should not be possible", op);
27652764
return 0;
27662765
}
27672766

@@ -2809,6 +2808,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28092808
case GLOBAL_EXPLICIT:
28102809
optype = OP_GLOBAL;
28112810
break;
2811+
default:
2812+
/* scope can be 0 */
2813+
break;
28122814
}
28132815

28142816
/* XXX Leave assert here, but handle __doc__ and the like better */
@@ -2830,6 +2832,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28302832
Py_DECREF(mangled);
28312833
return 0;
28322834
case Param:
2835+
default:
28332836
PyErr_SetString(PyExc_SystemError,
28342837
"param invalid for deref variable");
28352838
return 0;
@@ -2844,6 +2847,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28442847
case AugStore:
28452848
break;
28462849
case Param:
2850+
default:
28472851
PyErr_SetString(PyExc_SystemError,
28482852
"param invalid for local variable");
28492853
return 0;
@@ -2860,6 +2864,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28602864
case AugStore:
28612865
break;
28622866
case Param:
2867+
default:
28632868
PyErr_SetString(PyExc_SystemError,
28642869
"param invalid for global variable");
28652870
return 0;
@@ -2874,6 +2879,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
28742879
case AugStore:
28752880
break;
28762881
case Param:
2882+
default:
28772883
PyErr_SetString(PyExc_SystemError,
28782884
"param invalid for name variable");
28792885
return 0;
@@ -3361,6 +3367,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
33613367
ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
33623368
break;
33633369
case Param:
3370+
default:
33643371
PyErr_SetString(PyExc_SystemError,
33653372
"param invalid in attribute expression");
33663373
return 0;
@@ -3388,6 +3395,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
33883395
VISIT_SLICE(c, e->v.Subscript.slice, Del);
33893396
break;
33903397
case Param:
3398+
default:
33913399
PyErr_SetString(PyExc_SystemError,
33923400
"param invalid in subscript expression");
33933401
return 0;
@@ -3441,8 +3449,9 @@ compiler_augassign(struct compiler *c, stmt_ty s)
34413449
ADDOP(c, inplace_binop(c, s->v.AugAssign.op));
34423450
return compiler_nameop(c, e->v.Name.id, Store);
34433451
default:
3444-
fprintf(stderr,
3445-
"invalid node type for augmented assignment\n");
3452+
PyErr_Format(PyExc_SystemError,
3453+
"invalid node type (%d) for augmented assignment",
3454+
e->kind);
34463455
return 0;
34473456
}
34483457
return 1;
@@ -3514,9 +3523,9 @@ compiler_handle_subscr(struct compiler *c, const char *kind,
35143523
case Store: op = STORE_SUBSCR; break;
35153524
case Del: op = DELETE_SUBSCR; break;
35163525
case Param:
3517-
fprintf(stderr,
3518-
"invalid %s kind %d in subscript\n",
3519-
kind, ctx);
3526+
PyErr_Format(PyExc_SystemError,
3527+
"invalid %s kind %d in subscript\n",
3528+
kind, ctx);
35203529
return 0;
35213530
}
35223531
if (ctx == AugLoad) {
@@ -3599,6 +3608,7 @@ compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
35993608
case Store: op = STORE_SLICE; break;
36003609
case Del: op = DELETE_SLICE; break;
36013610
case Param:
3611+
default:
36023612
PyErr_SetString(PyExc_SystemError,
36033613
"param invalid in simple slice");
36043614
return 0;
@@ -3618,11 +3628,11 @@ compiler_visit_nested_slice(struct compiler *c, slice_ty s,
36183628
break;
36193629
case Slice_kind:
36203630
return compiler_slice(c, s, ctx);
3621-
break;
36223631
case Index_kind:
36233632
VISIT(c, expr, s->v.Index.value);
36243633
break;
36253634
case ExtSlice_kind:
3635+
default:
36263636
PyErr_SetString(PyExc_SystemError,
36273637
"extended slice invalid in nested slice");
36283638
return 0;
@@ -3664,6 +3674,10 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
36643674
if (ctx != AugStore)
36653675
VISIT(c, expr, s->v.Index.value);
36663676
return compiler_handle_subscr(c, "index", ctx);
3677+
default:
3678+
PyErr_Format(PyExc_SystemError,
3679+
"invalid slice %d", s->kind);
3680+
return 0;
36673681
}
36683682
return 1;
36693683
}

0 commit comments

Comments
 (0)