History

python: remove automatic compiled module loading (.pyc files)

cinap_lenrek committed 10 years ago

Commit 6103afd1 parent f222a0c1 file · +6 −135Browse files

Showing the changes to sys/src/cmd/python/Python (1 of 1 file). Show all

Unified · Split

sys/src/cmd/python/Python/import.c+6−135
@@ -88,16 +88,11 @@ struct filedescr * _PyImport_Filetab = NULL; · 87 unmodified lines
8888 #ifdef RISCOS
8989 static const struct filedescr _PyImport_StandardFiletab[] = {
9090 {"/py", "U", PY_SOURCE},
91− {"/pyc", "rb", PY_COMPILED},
9291 {0, 0}
9392 };
9493 #else
9594 static const struct filedescr _PyImport_StandardFiletab[] = {
9695 {".py", "U", PY_SOURCE},
97−#ifdef MS_WINDOWS
98− {".pyw", "U", PY_SOURCE},
99−#endif
100− {".pyc", "rb", PY_COMPILED},
10196 {0, 0}
10297 };
10398 #endif
@@ -688,69 +683,6 @@ PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) · 584 unmodified lines
688683 }
689684
690685
691−/* Given a pathname for a Python source file, fill a buffer with the
692− pathname for the corresponding compiled file. Return the pathname
693− for the compiled file, or NULL if there's no space in the buffer.
694− Doesn't set an exception. */
695−
696−static char *
697−make_compiled_pathname(char *pathname, char *buf, size_t buflen)
698−{
699− size_t len = strlen(pathname);
700− if (len+2 > buflen)
701− return NULL;
702−
703−#ifdef MS_WINDOWS
704− /* Treat .pyw as if it were .py. The case of ".pyw" must match
705− that used in _PyImport_StandardFiletab. */
706− if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0)
707− --len; /* pretend 'w' isn't there */
708−#endif
709− memcpy(buf, pathname, len);
710− buf[len] = Py_OptimizeFlag ? 'o' : 'c';
711− buf[len+1] = '\0';
712−
713− return buf;
714−}
715−
716−
717−/* Given a pathname for a Python source file, its time of last
718− modification, and a pathname for a compiled file, check whether the
719− compiled file represents the same version of the source. If so,
720− return a FILE pointer for the compiled file, positioned just after
721− the header; if not, return NULL.
722− Doesn't set an exception. */
723−
724−static FILE *
725−check_compiled_module(char *pathname, time_t mtime, char *cpathname)
726−{
727− FILE *fp;
728− long magic;
729− long pyc_mtime;
730−
731− fp = fopen(cpathname, "rb");
732− if (fp == NULL)
733− return NULL;
734− magic = PyMarshal_ReadLongFromFile(fp);
735− if (magic != pyc_magic) {
736− if (Py_VerboseFlag)
737− PySys_WriteStderr("# %s has bad magic\n", cpathname);
738− fclose(fp);
739− return NULL;
740− }
741− pyc_mtime = PyMarshal_ReadLongFromFile(fp);
742− if (pyc_mtime != mtime) {
743− if (Py_VerboseFlag)
744− PySys_WriteStderr("# %s has bad mtime\n", cpathname);
745− fclose(fp);
746− return NULL;
747− }
748− if (Py_VerboseFlag)
749− PySys_WriteStderr("# %s matches %s\n", cpathname, pathname);
750− return fp;
751−}
752−
753−
754686 /* Read a code object from a file and check it for validity */
755687
756688 static PyCodeObject *
@@ -854,47 +786,6 @@ open_exclusive(char *filename) · 97 unmodified lines
854786 #endif
855787 }
856788
857−
858−/* Write a compiled module to a file, placing the time of last
859− modification of its source into the header.
860− Errors are ignored, if a write error occurs an attempt is made to
861− remove the file. */
862−
863−static void
864−write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
865−{
866− FILE *fp;
867−
868− fp = open_exclusive(cpathname);
869− if (fp == NULL) {
870− if (Py_VerboseFlag)
871− PySys_WriteStderr(
872− "# can't create %s\n", cpathname);
873− return;
874− }
875− PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
876− /* First write a 0 for mtime */
877− PyMarshal_WriteLongToFile(0L, fp, Py_MARSHAL_VERSION);
878− PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);
879− if (fflush(fp) != 0 || ferror(fp)) {
880− if (Py_VerboseFlag)
881− PySys_WriteStderr("# can't write %s\n", cpathname);
882− /* Don't keep partial file */
883− fclose(fp);
884− (void) unlink(cpathname);
885− return;
886− }
887− /* Now write the true mtime */
888− fseek(fp, 4L, 0);
889− assert(mtime < LONG_MAX);
890− PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
891− fflush(fp);
892− fclose(fp);
893− if (Py_VerboseFlag)
894− PySys_WriteStderr("# wrote %s\n", cpathname);
895−}
896−
897−
898789 /* Load a source module from a given file and return its module
899790 object WITH INCREMENTED REFERENCE COUNT. If there's a matching
900791 byte-compiled file, use that instead. */
@@ -905,7 +796,6 @@ load_source_module(char *name, char *pathname, FILE *fp) · 4 unmodified lines
905796 time_t mtime;
906797 FILE *fpc;
907798 char buf[MAXPATHLEN+1];
908− char *cpathname;
909799 PyCodeObject *co;
910800 PyObject *m;
911801
@@ -927,31 +817,12 @@ load_source_module(char *name, char *pathname, FILE *fp) · 15 unmodified lines
927817 return NULL;
928818 }
929819 #endif
930− cpathname = make_compiled_pathname(pathname, buf,
931− (size_t)MAXPATHLEN + 1);
932− if (cpathname != NULL &&
933− (fpc = check_compiled_module(pathname, mtime, cpathname))) {
934− co = read_compiled_module(cpathname, fpc);
935− fclose(fpc);
936− if (co == NULL)
937− return NULL;
938− if (Py_VerboseFlag)
939− PySys_WriteStderr("import %s # precompiled from %s\n",
940− name, cpathname);
941− pathname = cpathname;
942− }
943− else {
944− co = parse_source_module(pathname, fp);
945− if (co == NULL)
946− return NULL;
947− if (Py_VerboseFlag)
948− PySys_WriteStderr("import %s # from %s\n",
949− name, pathname);
950−
951− if(0) /* disabled this for now -- cinap */
952− if (cpathname)
953− write_compiled_module(co, cpathname, mtime);
954− }
820+ co = parse_source_module(pathname, fp);
821+ if (co == NULL)
822+ return NULL;
823+ if (Py_VerboseFlag)
824+ PySys_WriteStderr("import %s # from %s\n",
825+ name, pathname);
955826 m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
956827 Py_DECREF(co);
957828