comparison Python/pythonrun.c @ 76084:43606a4085b0 3.2

fix parse_syntax_error to clean up its resources
author Benjamin Peterson <benjamin@python.org>
date Tue, 03 Apr 2012 00:30:38 -0400
parents 0e8bd4785ea0
children c97d78415f5a ff7587546a1d
comparison
equal deleted inserted replaced
76075:98ab6e322c40 76084:43606a4085b0
1333 /* old style errors */ 1333 /* old style errors */
1334 if (PyTuple_Check(err)) 1334 if (PyTuple_Check(err))
1335 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, 1335 return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
1336 lineno, offset, text); 1336 lineno, offset, text);
1337 1337
1338 *message = NULL;
1339
1338 /* new style errors. `err' is an instance */ 1340 /* new style errors. `err' is an instance */
1339 1341 *message = PyObject_GetAttrString(err, "msg");
1340 if (! (v = PyObject_GetAttrString(err, "msg"))) 1342 if (!*message)
1341 goto finally; 1343 goto finally;
1342 *message = v; 1344
1343 1345 v = PyObject_GetAttrString(err, "filename");
1344 if (!(v = PyObject_GetAttrString(err, "filename"))) 1346 if (!v)
1345 goto finally; 1347 goto finally;
1346 if (v == Py_None) 1348 if (v == Py_None) {
1349 Py_DECREF(v);
1347 *filename = NULL; 1350 *filename = NULL;
1348 else if (! (*filename = _PyUnicode_AsString(v))) 1351 }
1349 goto finally; 1352 else {
1350 1353 *filename = _PyUnicode_AsString(v);
1351 Py_DECREF(v); 1354 Py_DECREF(v);
1352 if (!(v = PyObject_GetAttrString(err, "lineno"))) 1355 if (!*filename)
1356 goto finally;
1357 }
1358
1359 v = PyObject_GetAttrString(err, "lineno");
1360 if (!v)
1353 goto finally; 1361 goto finally;
1354 hold = PyLong_AsLong(v); 1362 hold = PyLong_AsLong(v);
1355 Py_DECREF(v); 1363 Py_DECREF(v);
1356 v = NULL;
1357 if (hold < 0 && PyErr_Occurred()) 1364 if (hold < 0 && PyErr_Occurred())
1358 goto finally; 1365 goto finally;
1359 *lineno = (int)hold; 1366 *lineno = (int)hold;
1360 1367
1361 if (!(v = PyObject_GetAttrString(err, "offset"))) 1368 v = PyObject_GetAttrString(err, "offset");
1369 if (!v)
1362 goto finally; 1370 goto finally;
1363 if (v == Py_None) { 1371 if (v == Py_None) {
1364 *offset = -1; 1372 *offset = -1;
1365 Py_DECREF(v); 1373 Py_DECREF(v);
1366 v = NULL;
1367 } else { 1374 } else {
1368 hold = PyLong_AsLong(v); 1375 hold = PyLong_AsLong(v);
1369 Py_DECREF(v); 1376 Py_DECREF(v);
1370 v = NULL;
1371 if (hold < 0 && PyErr_Occurred()) 1377 if (hold < 0 && PyErr_Occurred())
1372 goto finally; 1378 goto finally;
1373 *offset = (int)hold; 1379 *offset = (int)hold;
1374 } 1380 }
1375 1381
1376 if (!(v = PyObject_GetAttrString(err, "text"))) 1382 v = PyObject_GetAttrString(err, "text");
1383 if (!v)
1377 goto finally; 1384 goto finally;
1378 if (v == Py_None) 1385 if (v == Py_None) {
1386 Py_DECREF(v);
1379 *text = NULL; 1387 *text = NULL;
1380 else if (!PyUnicode_Check(v) || 1388 }
1381 !(*text = _PyUnicode_AsString(v))) 1389 else {
1382 goto finally; 1390 *text = _PyUnicode_AsString(v);
1383 Py_DECREF(v); 1391 Py_DECREF(v);
1392 if (!*text)
1393 goto finally;
1394 }
1384 return 1; 1395 return 1;
1385 1396
1386 finally: 1397 finally:
1387 Py_XDECREF(v); 1398 Py_XDECREF(*message);
1388 return 0; 1399 return 0;
1389 } 1400 }
1390 1401
1391 void 1402 void
1392 PyErr_Print(void) 1403 PyErr_Print(void)