diff options
| -rwxr-xr-x | Parser/asdl_c.py | 22 | ||||
| -rw-r--r-- | Python/Python-ast.c | 526 | ||||
| -rw-r--r-- | Python/bltinmodule.c | 6 | 
3 files changed, 464 insertions, 90 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 40b8499..1508e83 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -367,6 +367,7 @@ class Obj2ModVisitor(PickleVisitor):          self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)          self.emit("{", 0)          self.emit("PyObject* tmp = NULL;", 1) +        self.emit("int isinstance;", 1)          self.emit("", 0)      def sumTrailer(self, name): @@ -386,7 +387,13 @@ class Obj2ModVisitor(PickleVisitor):      def simpleSum(self, sum, name):          self.funcHeader(name)          for t in sum.types: -            self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1) +            line = ("isinstance = PyObject_IsInstance(obj, " +                    "(PyObject *)%s_type);") +            self.emit(line % (t.name,), 1) +            self.emit("if (isinstance == -1) {", 1) +            self.emit("return 1;", 2) +            self.emit("}", 1) +            self.emit("if (isinstance) {", 1)              self.emit("*out = %s;" % t.name, 2)              self.emit("return 0;", 2)              self.emit("}", 1) @@ -408,7 +415,12 @@ class Obj2ModVisitor(PickleVisitor):          for a in sum.attributes:              self.visitField(a, name, sum=sum, depth=1)          for t in sum.types: -            self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1) +            line = "isinstance = PyObject_IsInstance(obj, (PyObject*)%s_type);" +            self.emit(line % (t.name,), 1) +            self.emit("if (isinstance == -1) {", 1) +            self.emit("return 1;", 2) +            self.emit("}", 1) +            self.emit("if (isinstance) {", 1)              for f in t.fields:                  self.visitFieldDeclaration(f, t.name, sum=sum, depth=2)              self.emit("", 0) @@ -1093,11 +1105,15 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)      PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,                              (PyObject*)Interactive_type};      char *req_name[] = {"Module", "Expression", "Interactive"}; +    int isinstance;      assert(0 <= mode && mode <= 2);      init_types(); -    if (!PyObject_IsInstance(ast, req_type[mode])) { +    isinstance = PyObject_IsInstance(ast, req_type[mode]); +    if (isinstance == -1) +        return NULL; +    if (!isinstance) {          PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",                       req_name[mode], Py_TYPE(ast)->tp_name);          return NULL; diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 9ff3d8a..61e7427 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3175,13 +3175,18 @@ int  obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance;          if (obj == Py_None) {                  *out = NULL;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Module_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* body;                  if (PyObject_HasAttrString(obj, "body")) { @@ -3213,7 +3218,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* body;                  if (PyObject_HasAttrString(obj, "body")) { @@ -3245,7 +3254,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty body;                  if (PyObject_HasAttrString(obj, "body")) { @@ -3264,7 +3277,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* body;                  if (PyObject_HasAttrString(obj, "body")) { @@ -3309,6 +3326,7 @@ int  obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance;          int lineno;          int col_offset; @@ -3341,7 +3359,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");                  return 1;          } -        if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  identifier name;                  arguments_ty args;                  asdl_seq* body; @@ -3426,7 +3448,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  identifier name;                  asdl_seq* bases;                  asdl_seq* body; @@ -3524,7 +3550,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Return_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  if (PyObject_HasAttrString(obj, "value")) { @@ -3542,7 +3572,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* targets;                  if (PyObject_HasAttrString(obj, "targets")) { @@ -3574,7 +3608,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* targets;                  expr_ty value; @@ -3619,7 +3657,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty target;                  operator_ty op;                  expr_ty value; @@ -3664,7 +3706,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Print_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty dest;                  asdl_seq* values;                  bool nl; @@ -3721,7 +3767,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)For_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty target;                  expr_ty iter;                  asdl_seq* body; @@ -3806,7 +3856,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)While_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty test;                  asdl_seq* body;                  asdl_seq* orelse; @@ -3877,7 +3931,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)If_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty test;                  asdl_seq* body;                  asdl_seq* orelse; @@ -3948,7 +4006,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)With_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty context_expr;                  expr_ty optional_vars;                  asdl_seq* body; @@ -4006,7 +4068,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty type;                  expr_ty inst;                  expr_ty tback; @@ -4048,7 +4114,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* body;                  asdl_seq* handlers;                  asdl_seq* orelse; @@ -4133,7 +4203,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* body;                  asdl_seq* finalbody; @@ -4191,7 +4265,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty test;                  expr_ty msg; @@ -4222,7 +4300,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Import_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* names;                  if (PyObject_HasAttrString(obj, "names")) { @@ -4254,7 +4336,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  identifier module;                  asdl_seq* names;                  int level; @@ -4311,7 +4397,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Exec_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty body;                  expr_ty globals;                  expr_ty locals; @@ -4354,7 +4444,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Global_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* names;                  if (PyObject_HasAttrString(obj, "names")) { @@ -4386,7 +4480,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  if (PyObject_HasAttrString(obj, "value")) { @@ -4405,19 +4503,31 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Pass(lineno, col_offset, arena);                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Break_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Break(lineno, col_offset, arena);                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Continue(lineno, col_offset, arena);                  if (*out == NULL) goto failed; @@ -4436,6 +4546,7 @@ int  obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance;          int lineno;          int col_offset; @@ -4468,7 +4579,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");                  return 1;          } -        if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  boolop_ty op;                  asdl_seq* values; @@ -4513,7 +4628,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty left;                  operator_ty op;                  expr_ty right; @@ -4558,7 +4677,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  unaryop_ty op;                  expr_ty operand; @@ -4590,7 +4713,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  arguments_ty args;                  expr_ty body; @@ -4622,7 +4749,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty test;                  expr_ty body;                  expr_ty orelse; @@ -4667,7 +4798,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* keys;                  asdl_seq* values; @@ -4725,7 +4860,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty elt;                  asdl_seq* generators; @@ -4770,7 +4909,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty elt;                  asdl_seq* generators; @@ -4815,7 +4958,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  if (PyObject_HasAttrString(obj, "value")) { @@ -4833,7 +4980,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty left;                  asdl_int_seq* ops;                  asdl_seq* comparators; @@ -4905,7 +5056,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Call_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty func;                  asdl_seq* args;                  asdl_seq* keywords; @@ -5001,7 +5156,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Repr_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  if (PyObject_HasAttrString(obj, "value")) { @@ -5020,7 +5179,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Num_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  object n;                  if (PyObject_HasAttrString(obj, "n")) { @@ -5039,7 +5202,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Str_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  string s;                  if (PyObject_HasAttrString(obj, "s")) { @@ -5058,7 +5225,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  identifier attr;                  expr_context_ty ctx; @@ -5103,7 +5274,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  slice_ty slice;                  expr_context_ty ctx; @@ -5148,7 +5323,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Name_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  identifier id;                  expr_context_ty ctx; @@ -5180,7 +5359,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)List_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* elts;                  expr_context_ty ctx; @@ -5225,7 +5408,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* elts;                  expr_context_ty ctx; @@ -5283,28 +5470,53 @@ int  obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance; -        if (PyObject_IsInstance(obj, (PyObject*)Load_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Load;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Store_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Store;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Del_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Del;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = AugLoad;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = AugStore;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Param_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Param;                  return 0;          } @@ -5321,19 +5533,28 @@ int  obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance;          if (obj == Py_None) {                  *out = NULL;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Ellipsis(arena);                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty lower;                  expr_ty upper;                  expr_ty step; @@ -5375,7 +5596,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  asdl_seq* dims;                  if (PyObject_HasAttrString(obj, "dims")) { @@ -5407,7 +5632,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)                  if (*out == NULL) goto failed;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Index_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty value;                  if (PyObject_HasAttrString(obj, "value")) { @@ -5439,12 +5668,21 @@ int  obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance; -        if (PyObject_IsInstance(obj, (PyObject*)And_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = And;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Or_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Or;                  return 0;          } @@ -5461,52 +5699,101 @@ int  obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance; -        if (PyObject_IsInstance(obj, (PyObject*)Add_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Add;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Sub;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Mult;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Div_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Div;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Mod;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Pow;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = LShift;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = RShift;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = BitOr;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = BitXor;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = BitAnd;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = FloorDiv;                  return 0;          } @@ -5523,20 +5810,37 @@ int  obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance; -        if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Invert;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Not_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Not;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = UAdd;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)USub_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = USub;                  return 0;          } @@ -5553,44 +5857,85 @@ int  obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance; -        if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Eq;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = NotEq;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Lt;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = LtE;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Gt;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = GtE;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)Is_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = Is;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = IsNot;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)In_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = In;                  return 0;          } -        if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  *out = NotIn;                  return 0;          } @@ -5671,6 +6016,7 @@ int  obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)  {          PyObject* tmp = NULL; +        int isinstance;          int lineno;          int col_offset; @@ -5703,7 +6049,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)                  PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");                  return 1;          } -        if (PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type)) { +        isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); +        if (isinstance == -1) { +                return 1; +        } +        if (isinstance) {                  expr_ty type;                  expr_ty name;                  asdl_seq* body; @@ -6104,11 +6454,15 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)      PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,                              (PyObject*)Interactive_type};      char *req_name[] = {"Module", "Expression", "Interactive"}; +    int isinstance;      assert(0 <= mode && mode <= 2);      init_types(); -    if (!PyObject_IsInstance(ast, req_type[mode])) { +    isinstance = PyObject_IsInstance(ast, req_type[mode]); +    if (isinstance == -1) +        return NULL; +    if (!isinstance) {          PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",                       req_name[mode], Py_TYPE(ast)->tp_name);          return NULL; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index b201aaf..3132cf4 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -466,6 +466,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)  	int mode = -1;  	int dont_inherit = 0;  	int supplied_flags = 0; +	int is_ast;  	PyCompilerFlags cf;  	PyObject *result = NULL, *cmd, *tmp = NULL;  	Py_ssize_t length; @@ -505,7 +506,10 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)  		return NULL;  	} -	if (PyAST_Check(cmd)) { +	is_ast = PyAST_Check(cmd); +	if (is_ast == -1) +		return NULL; +	if (is_ast) {  		if (supplied_flags & PyCF_ONLY_AST) {  			Py_INCREF(cmd);  			result = cmd;  | 
