Commit 6f828186 authored by Alexandre Vassalotti's avatar Alexandre Vassalotti

Merged revisions 73683,73786 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73683 | georg.brandl | 2009-06-29 10:44:49 -0400 (Mon, 29 Jun 2009) | 1 line

  Fix error handling in PyCode_Optimize, by Alexander Schremmer at EuroPython sprint.
........
  r73786 | benjamin.peterson | 2009-07-02 18:56:16 -0400 (Thu, 02 Jul 2009) | 1 line

  condense with assertRaises
........
parent 7b53fbfd
...@@ -272,19 +272,8 @@ def f(): ...@@ -272,19 +272,8 @@ def f():
inner() inner()
y = 1 y = 1
try: self.assertRaises(UnboundLocalError, errorInOuter)
errorInOuter() self.assertRaises(NameError, errorInInner)
except UnboundLocalError:
pass
else:
self.fail()
try:
errorInInner()
except NameError:
pass
else:
self.fail()
# test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation # test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation
exec(""" exec("""
......
...@@ -330,7 +330,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -330,7 +330,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
/* Bail out if an exception is set */ /* Bail out if an exception is set */
if (PyErr_Occurred()) if (PyErr_Occurred())
goto exitUnchanged; goto exitError;
/* Bypass optimization when the lineno table is too complex */ /* Bypass optimization when the lineno table is too complex */
assert(PyBytes_Check(lineno_obj)); assert(PyBytes_Check(lineno_obj));
...@@ -348,7 +348,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -348,7 +348,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
/* Make a modifiable copy of the code string */ /* Make a modifiable copy of the code string */
codestr = (unsigned char *)PyMem_Malloc(codelen); codestr = (unsigned char *)PyMem_Malloc(codelen);
if (codestr == NULL) if (codestr == NULL)
goto exitUnchanged; goto exitError;
codestr = (unsigned char *)memcpy(codestr, codestr = (unsigned char *)memcpy(codestr,
PyBytes_AS_STRING(code), codelen); PyBytes_AS_STRING(code), codelen);
...@@ -363,11 +363,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -363,11 +363,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
/* Mapping to new jump targets after NOPs are removed */ /* Mapping to new jump targets after NOPs are removed */
addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
if (addrmap == NULL) if (addrmap == NULL)
goto exitUnchanged; goto exitError;
blocks = markblocks(codestr, codelen); blocks = markblocks(codestr, codelen);
if (blocks == NULL) if (blocks == NULL)
goto exitUnchanged; goto exitError;
assert(PyList_Check(consts)); assert(PyList_Check(consts));
for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) { for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) {
...@@ -413,7 +413,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -413,7 +413,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j)); name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
h = load_global(codestr, i, name, consts); h = load_global(codestr, i, name, consts);
if (h < 0) if (h < 0)
goto exitUnchanged; goto exitError;
else if (h == 0) else if (h == 0)
continue; continue;
cumlc = lastlc + 1; cumlc = lastlc + 1;
...@@ -667,6 +667,9 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -667,6 +667,9 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
PyMem_Free(blocks); PyMem_Free(blocks);
return code; return code;
exitError:
code = NULL;
exitUnchanged: exitUnchanged:
if (blocks != NULL) if (blocks != NULL)
PyMem_Free(blocks); PyMem_Free(blocks);
...@@ -674,6 +677,6 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, ...@@ -674,6 +677,6 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
PyMem_Free(addrmap); PyMem_Free(addrmap);
if (codestr != NULL) if (codestr != NULL)
PyMem_Free(codestr); PyMem_Free(codestr);
Py_INCREF(code); Py_XINCREF(code);
return code; return code;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment