diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-11-20 01:38:49 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-11-20 01:38:49 (GMT) |
commit | 5b066817e2e777c8eff7776335482b9d6efd115b (patch) | |
tree | 4dc23dae3fd2708e743d7fcae0f210fed39887d0 /Parser/asdl_c.py | |
parent | c8c60c22845177f419e4de7305102310e336b1f0 (diff) | |
download | cpython-5b066817e2e777c8eff7776335482b9d6efd115b.zip cpython-5b066817e2e777c8eff7776335482b9d6efd115b.tar.gz cpython-5b066817e2e777c8eff7776335482b9d6efd115b.tar.bz2 |
use %R format code; fixes invalid dereferencing #10391
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-x | Parser/asdl_c.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index c71c4ef..1fdc6bc 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -366,19 +366,19 @@ 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) + # Prevent compiler warnings about unused variable. + self.emit("tmp = tmp;", 1) self.emit("int isinstance;", 1) self.emit("", 0) - def sumTrailer(self, name): + def sumTrailer(self, name, add_label=False): self.emit("", 0) - self.emit("tmp = PyObject_Repr(obj);", 1) # there's really nothing more we can do if this fails ... - self.emit("if (tmp == NULL) goto failed;", 1) - error = "expected some sort of %s, but got %%.400s" % name - format = "PyErr_Format(PyExc_TypeError, \"%s\", PyBytes_AS_STRING(tmp));" + error = "expected some sort of %s, but got %%R" % name + format = "PyErr_Format(PyExc_TypeError, \"%s\", obj);" self.emit(format % error, 1, reflow=False) - self.emit("failed:", 0) - self.emit("Py_XDECREF(tmp);", 1) + if add_label: + self.emit("failed:", 1) self.emit("return 1;", 1) self.emit("}", 0) self.emit("", 0) @@ -430,7 +430,7 @@ class Obj2ModVisitor(PickleVisitor): self.emit("if (*out == NULL) goto failed;", 2) self.emit("return 0;", 2) self.emit("}", 1) - self.sumTrailer(name) + self.sumTrailer(name, True) def visitAttributeDeclaration(self, a, name, sum=sum): ctype = get_c_type(a.type) |