Issue #23731: Implement PEP 488.

The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
This commit is contained in:
Brett Cannon 2015-04-13 14:21:02 -04:00
parent a63cc21234
commit f299abdafa
56 changed files with 4731 additions and 4621 deletions

View file

@ -563,13 +563,12 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
data = PyUnicode_DATA(*filename);
#define ascii_lower(c) ((c <= 127) ? Py_TOLOWER(c) : 0)
/* if filename.lower().endswith((".pyc", ".pyo")): */
/* if filename.lower().endswith(".pyc"): */
if (len >= 4 &&
PyUnicode_READ(kind, data, len-4) == '.' &&
ascii_lower(PyUnicode_READ(kind, data, len-3)) == 'p' &&
ascii_lower(PyUnicode_READ(kind, data, len-2)) == 'y' &&
(ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c' ||
ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'o'))
ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c')
{
*filename = PyUnicode_Substring(*filename, 0,
PyUnicode_GET_LENGTH(*filename)-1);

File diff suppressed because it is too large Load diff

View file

@ -265,7 +265,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename_str, PyCompilerFlags *f
static int
maybe_pyc_file(FILE *fp, const char* filename, const char* ext, int closeit)
{
if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0)
if (strcmp(ext, ".pyc") == 0)
return 1;
/* Only look into the file if we are allowed to close it, since
@ -371,9 +371,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
fprintf(stderr, "python: Can't reopen .pyc file\n");
goto done;
}
/* Turn on optimization if a .pyo file is given */
if (strcmp(ext, ".pyo") == 0)
Py_OptimizeFlag = 1;
if (set_main_loader(d, filename, "SourcelessFileLoader") < 0) {
fprintf(stderr, "python: failed to set __main__.__loader__\n");