mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
Allow passing a .pyo file.
Print correct name in fatal error from PyErr_Print.
This commit is contained in:
parent
228d7f3f67
commit
2a7f58de1c
1 changed files with 8 additions and 5 deletions
|
@ -238,19 +238,22 @@ PyRun_SimpleFile(fp, filename)
|
||||||
return -1;
|
return -1;
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
ext = filename + strlen(filename) - 4;
|
ext = filename + strlen(filename) - 4;
|
||||||
|
if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0
|
||||||
#ifdef macintosh
|
#ifdef macintosh
|
||||||
/* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
|
/* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
|
||||||
if ( strcmp(ext, ".pyc") == 0 || getfiletype(filename) == 'PYC ' ||
|
|| getfiletype(filename) == 'PYC '
|
||||||
getfiletype(filename) == 'APPL' ) {
|
|| getfiletype(filename) == 'APPL'
|
||||||
#else
|
|
||||||
if ( strcmp(ext, ".pyc") == 0 ) {
|
|
||||||
#endif /* macintosh */
|
#endif /* macintosh */
|
||||||
|
) {
|
||||||
/* Try to run a pyc file. First, re-open in binary */
|
/* Try to run a pyc file. First, re-open in binary */
|
||||||
/* Don't close, done in main: fclose(fp); */
|
/* Don't close, done in main: fclose(fp); */
|
||||||
if( (fp = fopen(filename, "rb")) == NULL ) {
|
if( (fp = fopen(filename, "rb")) == NULL ) {
|
||||||
fprintf(stderr, "python: Can't reopen .pyc file\n");
|
fprintf(stderr, "python: Can't reopen .pyc file\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/* Turn on optimization if a .pyo file is given */
|
||||||
|
if (strcmp(ext, ".pyo") == 0)
|
||||||
|
Py_OptimizeFlag = 1;
|
||||||
v = run_pyc_file(fp, filename, d, d);
|
v = run_pyc_file(fp, filename, d, d);
|
||||||
} else {
|
} else {
|
||||||
v = PyRun_File(fp, filename, file_input, d, d);
|
v = PyRun_File(fp, filename, file_input, d, d);
|
||||||
|
@ -291,7 +294,7 @@ PyErr_Print()
|
||||||
Py_FlushLine();
|
Py_FlushLine();
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (exception == NULL)
|
if (exception == NULL)
|
||||||
Py_FatalError("print_error called but no exception");
|
Py_FatalError("PyErr_Print called but no exception");
|
||||||
if (exception == PyExc_SystemExit) {
|
if (exception == PyExc_SystemExit) {
|
||||||
if (v == NULL || v == Py_None)
|
if (v == NULL || v == Py_None)
|
||||||
Py_Exit(0);
|
Py_Exit(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue