Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 72848:81380082d216
Use identifier API for PyObject_GetAttrString.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Mon, 10 Oct 2011 18:11:30 +0200 |
| parents | 5e33219492bc |
| children | 7109f31300fb |
comparison
equal
deleted
inserted
replaced
| 72847:f924e0f62bcb | 72848:81380082d216 |
|---|---|
| 139 static char* | 139 static char* |
| 140 get_codec_name(const char *encoding) | 140 get_codec_name(const char *encoding) |
| 141 { | 141 { |
| 142 char *name_utf8, *name_str; | 142 char *name_utf8, *name_str; |
| 143 PyObject *codec, *name = NULL; | 143 PyObject *codec, *name = NULL; |
| 144 _Py_identifier(name); | |
| 144 | 145 |
| 145 codec = _PyCodec_Lookup(encoding); | 146 codec = _PyCodec_Lookup(encoding); |
| 146 if (!codec) | 147 if (!codec) |
| 147 goto error; | 148 goto error; |
| 148 | 149 |
| 149 name = PyObject_GetAttrString(codec, "name"); | 150 name = _PyObject_GetAttrId(codec, &PyId_name); |
| 150 Py_CLEAR(codec); | 151 Py_CLEAR(codec); |
| 151 if (!name) | 152 if (!name) |
| 152 goto error; | 153 goto error; |
| 153 | 154 |
| 154 name_utf8 = _PyUnicode_AsString(name); | 155 name_utf8 = _PyUnicode_AsString(name); |
| 828 Py_None, Py_None, Py_None, 0); | 829 Py_None, Py_None, Py_None, 0); |
| 829 if (buf == NULL) | 830 if (buf == NULL) |
| 830 goto error; | 831 goto error; |
| 831 | 832 |
| 832 if (buffering) { | 833 if (buffering) { |
| 833 raw = PyObject_GetAttrString(buf, "raw"); | 834 _Py_identifier(raw); |
| 835 raw = _PyObject_GetAttrId(buf, &PyId_raw); | |
| 834 if (raw == NULL) | 836 if (raw == NULL) |
| 835 goto error; | 837 goto error; |
| 836 } | 838 } |
| 837 else { | 839 else { |
| 838 raw = buf; | 840 raw = buf; |
| 1113 PyObject *m, *d, *v, *w, *oenc = NULL; | 1115 PyObject *m, *d, *v, *w, *oenc = NULL; |
| 1114 mod_ty mod; | 1116 mod_ty mod; |
| 1115 PyArena *arena; | 1117 PyArena *arena; |
| 1116 char *ps1 = "", *ps2 = "", *enc = NULL; | 1118 char *ps1 = "", *ps2 = "", *enc = NULL; |
| 1117 int errcode = 0; | 1119 int errcode = 0; |
| 1120 _Py_identifier(encoding); | |
| 1118 | 1121 |
| 1119 if (fp == stdin) { | 1122 if (fp == stdin) { |
| 1120 /* Fetch encoding from sys.stdin */ | 1123 /* Fetch encoding from sys.stdin */ |
| 1121 v = PySys_GetObject("stdin"); | 1124 v = PySys_GetObject("stdin"); |
| 1122 if (v == NULL || v == Py_None) | 1125 if (v == NULL || v == Py_None) |
| 1123 return -1; | 1126 return -1; |
| 1124 oenc = PyObject_GetAttrString(v, "encoding"); | 1127 oenc = _PyObject_GetAttrId(v, &PyId_encoding); |
| 1125 if (!oenc) | 1128 if (!oenc) |
| 1126 return -1; | 1129 return -1; |
| 1127 enc = _PyUnicode_AsString(oenc); | 1130 enc = _PyUnicode_AsString(oenc); |
| 1128 if (enc == NULL) | 1131 if (enc == NULL) |
| 1129 return -1; | 1132 return -1; |
| 1316 parse_syntax_error(PyObject *err, PyObject **message, const char **filename, | 1319 parse_syntax_error(PyObject *err, PyObject **message, const char **filename, |
| 1317 int *lineno, int *offset, const char **text) | 1320 int *lineno, int *offset, const char **text) |
| 1318 { | 1321 { |
| 1319 long hold; | 1322 long hold; |
| 1320 PyObject *v; | 1323 PyObject *v; |
| 1324 _Py_identifier(msg); | |
| 1325 _Py_identifier(filename); | |
| 1326 _Py_identifier(lineno); | |
| 1327 _Py_identifier(offset); | |
| 1328 _Py_identifier(text); | |
| 1321 | 1329 |
| 1322 /* old style errors */ | 1330 /* old style errors */ |
| 1323 if (PyTuple_Check(err)) | 1331 if (PyTuple_Check(err)) |
| 1324 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, | 1332 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, |
| 1325 lineno, offset, text); | 1333 lineno, offset, text); |
| 1326 | 1334 |
| 1327 /* new style errors. `err' is an instance */ | 1335 /* new style errors. `err' is an instance */ |
| 1328 | 1336 |
| 1329 if (! (v = PyObject_GetAttrString(err, "msg"))) | 1337 if (! (v = _PyObject_GetAttrId(err, &PyId_msg))) |
| 1330 goto finally; | 1338 goto finally; |
| 1331 *message = v; | 1339 *message = v; |
| 1332 | 1340 |
| 1333 if (!(v = PyObject_GetAttrString(err, "filename"))) | 1341 if (!(v = _PyObject_GetAttrId(err, &PyId_filename))) |
| 1334 goto finally; | 1342 goto finally; |
| 1335 if (v == Py_None) | 1343 if (v == Py_None) |
| 1336 *filename = NULL; | 1344 *filename = NULL; |
| 1337 else if (! (*filename = _PyUnicode_AsString(v))) | 1345 else if (! (*filename = _PyUnicode_AsString(v))) |
| 1338 goto finally; | 1346 goto finally; |
| 1339 | 1347 |
| 1340 Py_DECREF(v); | 1348 Py_DECREF(v); |
| 1341 if (!(v = PyObject_GetAttrString(err, "lineno"))) | 1349 if (!(v = _PyObject_GetAttrId(err, &PyId_lineno))) |
| 1342 goto finally; | 1350 goto finally; |
| 1343 hold = PyLong_AsLong(v); | 1351 hold = PyLong_AsLong(v); |
| 1344 Py_DECREF(v); | 1352 Py_DECREF(v); |
| 1345 v = NULL; | 1353 v = NULL; |
| 1346 if (hold < 0 && PyErr_Occurred()) | 1354 if (hold < 0 && PyErr_Occurred()) |
| 1347 goto finally; | 1355 goto finally; |
| 1348 *lineno = (int)hold; | 1356 *lineno = (int)hold; |
| 1349 | 1357 |
| 1350 if (!(v = PyObject_GetAttrString(err, "offset"))) | 1358 if (!(v = _PyObject_GetAttrId(err, &PyId_offset))) |
| 1351 goto finally; | 1359 goto finally; |
| 1352 if (v == Py_None) { | 1360 if (v == Py_None) { |
| 1353 *offset = -1; | 1361 *offset = -1; |
| 1354 Py_DECREF(v); | 1362 Py_DECREF(v); |
| 1355 v = NULL; | 1363 v = NULL; |
| 1360 if (hold < 0 && PyErr_Occurred()) | 1368 if (hold < 0 && PyErr_Occurred()) |
| 1361 goto finally; | 1369 goto finally; |
| 1362 *offset = (int)hold; | 1370 *offset = (int)hold; |
| 1363 } | 1371 } |
| 1364 | 1372 |
| 1365 if (!(v = PyObject_GetAttrString(err, "text"))) | 1373 if (!(v = _PyObject_GetAttrId(err, &PyId_text))) |
| 1366 goto finally; | 1374 goto finally; |
| 1367 if (v == Py_None) | 1375 if (v == Py_None) |
| 1368 *text = NULL; | 1376 *text = NULL; |
| 1369 else if (!PyUnicode_Check(v) || | 1377 else if (!PyUnicode_Check(v) || |
| 1370 !(*text = _PyUnicode_AsString(v))) | 1378 !(*text = _PyUnicode_AsString(v))) |
| 1429 fflush(stdout); | 1437 fflush(stdout); |
| 1430 if (value == NULL || value == Py_None) | 1438 if (value == NULL || value == Py_None) |
| 1431 goto done; | 1439 goto done; |
| 1432 if (PyExceptionInstance_Check(value)) { | 1440 if (PyExceptionInstance_Check(value)) { |
| 1433 /* The error code should be in the `code' attribute. */ | 1441 /* The error code should be in the `code' attribute. */ |
| 1434 PyObject *code = PyObject_GetAttrString(value, "code"); | 1442 _Py_identifier(code); |
| 1443 PyObject *code = _PyObject_GetAttrId(value, &PyId_code); | |
| 1435 if (code) { | 1444 if (code) { |
| 1436 Py_DECREF(value); | 1445 Py_DECREF(value); |
| 1437 value = code; | 1446 value = code; |
| 1438 if (value == Py_None) | 1447 if (value == Py_None) |
| 1439 goto done; | 1448 goto done; |
| 1586 /* Don't do anything else */ | 1595 /* Don't do anything else */ |
| 1587 } | 1596 } |
| 1588 else { | 1597 else { |
| 1589 PyObject* moduleName; | 1598 PyObject* moduleName; |
| 1590 char* className; | 1599 char* className; |
| 1600 _Py_identifier(__module__); | |
| 1591 assert(PyExceptionClass_Check(type)); | 1601 assert(PyExceptionClass_Check(type)); |
| 1592 className = PyExceptionClass_Name(type); | 1602 className = PyExceptionClass_Name(type); |
| 1593 if (className != NULL) { | 1603 if (className != NULL) { |
| 1594 char *dot = strrchr(className, '.'); | 1604 char *dot = strrchr(className, '.'); |
| 1595 if (dot != NULL) | 1605 if (dot != NULL) |
| 1596 className = dot+1; | 1606 className = dot+1; |
| 1597 } | 1607 } |
| 1598 | 1608 |
| 1599 moduleName = PyObject_GetAttrString(type, "__module__"); | 1609 moduleName = _PyObject_GetAttrId(type, &PyId___module__); |
| 1600 if (moduleName == NULL || !PyUnicode_Check(moduleName)) | 1610 if (moduleName == NULL || !PyUnicode_Check(moduleName)) |
| 1601 { | 1611 { |
| 1602 Py_XDECREF(moduleName); | 1612 Py_XDECREF(moduleName); |
| 1603 err = PyFile_WriteString("<unknown>", f); | 1613 err = PyFile_WriteString("<unknown>", f); |
| 1604 } | 1614 } |
