summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-04-02 05:28:38 (GMT)
committerGuido van Rossum <guido@python.org>1997-04-02 05:28:38 (GMT)
commit2a7f58de1c3011a9ed167172e628ecdc70dbdb82 (patch)
tree11c2cd375b3e3bb1a00ab7da15e9fea4294f4260 /Python/pythonrun.c
parent228d7f3f67f399a456383890c3447efe92afac88 (diff)
downloadcpython-2a7f58de1c3011a9ed167172e628ecdc70dbdb82.zip
cpython-2a7f58de1c3011a9ed167172e628ecdc70dbdb82.tar.gz
cpython-2a7f58de1c3011a9ed167172e628ecdc70dbdb82.tar.bz2
Allow passing a .pyo file.
Print correct name in fatal error from PyErr_Print.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index b78e6f5..4d6b918 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -238,19 +238,22 @@ PyRun_SimpleFile(fp, filename)
return -1;
d = PyModule_GetDict(m);
ext = filename + strlen(filename) - 4;
+ if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0
#ifdef macintosh
/* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
- if ( strcmp(ext, ".pyc") == 0 || getfiletype(filename) == 'PYC ' ||
- getfiletype(filename) == 'APPL' ) {
-#else
- if ( strcmp(ext, ".pyc") == 0 ) {
+ || getfiletype(filename) == 'PYC '
+ || getfiletype(filename) == 'APPL'
#endif /* macintosh */
+ ) {
/* Try to run a pyc file. First, re-open in binary */
/* Don't close, done in main: fclose(fp); */
if( (fp = fopen(filename, "rb")) == NULL ) {
fprintf(stderr, "python: Can't reopen .pyc file\n");
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);
} else {
v = PyRun_File(fp, filename, file_input, d, d);
@@ -291,7 +294,7 @@ PyErr_Print()
Py_FlushLine();
fflush(stdout);
if (exception == NULL)
- Py_FatalError("print_error called but no exception");
+ Py_FatalError("PyErr_Print called but no exception");
if (exception == PyExc_SystemExit) {
if (v == NULL || v == Py_None)
Py_Exit(0);