diff -r d60c00015f01 Include/import.h --- a/Include/import.h Wed Oct 05 19:53:43 2011 +0200 +++ b/Include/import.h Wed Oct 05 22:38:58 2011 -0300 @@ -74,6 +74,8 @@ ); PyAPI_FUNC(int)_PyImport_FixupExtensionUnicode(PyObject*, char *, PyObject *); +const int the_byte_compiled_file_is_older(PyObject*); + struct _inittab { char *name; PyObject* (*initfunc)(void); diff -r d60c00015f01 Python/import.c --- a/Python/import.c Wed Oct 05 19:53:43 2011 +0200 +++ b/Python/import.c Wed Oct 05 22:38:58 2011 -0300 @@ -329,7 +329,7 @@ /* Forked as a side effect of import */ long me = PyThread_get_thread_ident(); PyThread_acquire_lock(import_lock, 0); - /* XXX: can the previous line fail? */ + /* XXX: can the previous line fail? */ import_lock_thread = me; import_lock_level--; } else { @@ -1277,6 +1277,51 @@ return 1; } +const int +the_byte_compiled_file_is_older(PyObject *filename) +{ + struct stat st; + FILE *fpc; + FILE *fp; + char buf[MAXPATHLEN+1]; + char *cpathname; + char *pathname; + PyObject *filebytes; + + filebytes = PyUnicode_EncodeFSDefault(filename); + if (filebytes == NULL) { + PyErr_Clear(); + return 0; + } + pathname = PyBytes_AS_STRING(filebytes); + fp = fopen(pathname, "r"); + + if (fstat(fileno(fp), &st) != 0) { + PyErr_Format(PyExc_RuntimeError, + "unable to get file status from '%s'", + pathname); + return 0; + } +#if SIZEOF_TIME_T > 4 + /* Python's .pyc timestamp handling presumes that the timestamp fits + in 4 bytes. This will be fine until sometime in the year 2038, + when a 4-byte signed time_t will overflow. + */ + if (st.st_mtime >> 32) { + PyErr_SetString(PyExc_OverflowError, + "modification time overflows a 4 byte field"); + return 0; + } +#endif + cpathname = make_compiled_pathname( + pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag); + + if (cpathname != NULL && + (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) + return 0; + return 1; +} + /* Load a source module from a given file and return its module object WITH INCREMENTED REFERENCE COUNT. If there's a matching byte-compiled file, use that instead. */ diff -r d60c00015f01 Python/traceback.c --- a/Python/traceback.c Wed Oct 05 19:53:43 2011 +0200 +++ b/Python/traceback.c Wed Oct 05 22:38:58 2011 -0300 @@ -311,7 +311,12 @@ if (err == 0) err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW); Py_DECREF(lineobj); - if (err == 0) + + //if the pyc is older than the source file + if (the_byte_compiled_file_is_older(filename) == 1) + err = PyFile_WriteString(" WARNING: Modified after import!", f); + + if (err == 0) err = PyFile_WriteString("\n", f); return err; }