diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-13 00:54:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-13 00:54:15 (GMT) |
commit | 5f429e02274f85f4ba19276847e323b13fae6568 (patch) | |
tree | 176e42c26c0b0ac59301f85e25b4819cffc7a0e3 /Parser | |
parent | c169c781a807e0d0e1463d510be9523b1d6c2689 (diff) | |
download | cpython-5f429e02274f85f4ba19276847e323b13fae6568.zip cpython-5f429e02274f85f4ba19276847e323b13fae6568.tar.gz cpython-5f429e02274f85f4ba19276847e323b13fae6568.tar.bz2 |
account for PyObject_IsInstance's new ability to fail
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 22 |
1 files changed, 19 insertions, 3 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; |