Mercurial > cpython-lru_cache-weakref
comparison Python/import.c @ 30979:86fdf8fe7f17 legacy-trunk
Getting rid of all the code inside #ifdef macintosh too.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Thu, 20 Nov 2003 01:44:59 +0000 |
| parents | 651fc8d98d99 |
| children | ca4374662632 |
comparison
equal
deleted
inserted
replaced
| 30978:4c8160088b34 | 30979:86fdf8fe7f17 |
|---|---|
| 9 #include "marshal.h" | 9 #include "marshal.h" |
| 10 #include "compile.h" | 10 #include "compile.h" |
| 11 #include "eval.h" | 11 #include "eval.h" |
| 12 #include "osdefs.h" | 12 #include "osdefs.h" |
| 13 #include "importdl.h" | 13 #include "importdl.h" |
| 14 #ifdef macintosh | |
| 15 #include "macglue.h" | |
| 16 #endif | |
| 17 | 14 |
| 18 #ifdef HAVE_FCNTL_H | 15 #ifdef HAVE_FCNTL_H |
| 19 #include <fcntl.h> | 16 #include <fcntl.h> |
| 20 #endif | 17 #endif |
| 21 | 18 |
| 833 PyMarshal_WriteLongToFile(mtime, fp); | 830 PyMarshal_WriteLongToFile(mtime, fp); |
| 834 fflush(fp); | 831 fflush(fp); |
| 835 fclose(fp); | 832 fclose(fp); |
| 836 if (Py_VerboseFlag) | 833 if (Py_VerboseFlag) |
| 837 PySys_WriteStderr("# wrote %s\n", cpathname); | 834 PySys_WriteStderr("# wrote %s\n", cpathname); |
| 838 #ifdef macintosh | |
| 839 PyMac_setfiletype(cpathname, 'Pyth', 'PYC '); | |
| 840 #endif | |
| 841 } | 835 } |
| 842 | 836 |
| 843 | 837 |
| 844 /* Load a source module from a given file and return its module | 838 /* Load a source module from a given file and return its module |
| 845 object WITH INCREMENTED REFERENCE COUNT. If there's a matching | 839 object WITH INCREMENTED REFERENCE COUNT. If there's a matching |
| 1121 } | 1115 } |
| 1122 strcpy(buf, PyString_AsString(path)); | 1116 strcpy(buf, PyString_AsString(path)); |
| 1123 strcat(buf, "."); | 1117 strcat(buf, "."); |
| 1124 strcat(buf, name); | 1118 strcat(buf, name); |
| 1125 strcpy(name, buf); | 1119 strcpy(name, buf); |
| 1126 #ifdef macintosh | |
| 1127 /* Freezing on the mac works different, and the modules are | |
| 1128 ** actually on sys.path. So we don't take the quick exit but | |
| 1129 ** continue with the normal flow. | |
| 1130 */ | |
| 1131 path = NULL; | |
| 1132 #else | |
| 1133 if (find_frozen(name) != NULL) { | 1120 if (find_frozen(name) != NULL) { |
| 1134 strcpy(buf, name); | 1121 strcpy(buf, name); |
| 1135 return &fd_frozen; | 1122 return &fd_frozen; |
| 1136 } | 1123 } |
| 1137 PyErr_Format(PyExc_ImportError, | 1124 PyErr_Format(PyExc_ImportError, |
| 1138 "No frozen submodule named %.200s", name); | 1125 "No frozen submodule named %.200s", name); |
| 1139 return NULL; | 1126 return NULL; |
| 1140 #endif | |
| 1141 } | 1127 } |
| 1142 if (path == NULL) { | 1128 if (path == NULL) { |
| 1143 if (is_builtin(name)) { | 1129 if (is_builtin(name)) { |
| 1144 strcpy(buf, name); | 1130 strcpy(buf, name); |
| 1145 return &fd_builtin; | 1131 return &fd_builtin; |
| 1231 Py_DECREF(loader); | 1217 Py_DECREF(loader); |
| 1232 } | 1218 } |
| 1233 /* no hook was successful, use builtin import */ | 1219 /* no hook was successful, use builtin import */ |
| 1234 } | 1220 } |
| 1235 | 1221 |
| 1236 #ifdef macintosh | |
| 1237 /* | |
| 1238 ** Speedup: each sys.path item is interned, and | |
| 1239 ** FindResourceModule remembers which items refer to | |
| 1240 ** folders (so we don't have to bother trying to look | |
| 1241 ** into them for resources). We only do this for string | |
| 1242 ** items. | |
| 1243 */ | |
| 1244 if (PyString_Check(PyList_GET_ITEM(path, i))) { | |
| 1245 PyString_InternInPlace(&PyList_GET_ITEM(path, i)); | |
| 1246 v = PyList_GET_ITEM(path, i); | |
| 1247 if (PyMac_FindResourceModule((PyStringObject *)v, name, buf)) { | |
| 1248 static struct filedescr resfiledescr = | |
| 1249 {"", "", PY_RESOURCE}; | |
| 1250 | |
| 1251 Py_XDECREF(copy); | |
| 1252 return &resfiledescr; | |
| 1253 } | |
| 1254 if (PyMac_FindCodeResourceModule((PyStringObject *)v, name, buf)) { | |
| 1255 static struct filedescr resfiledescr = | |
| 1256 {"", "", PY_CODERESOURCE}; | |
| 1257 | |
| 1258 Py_XDECREF(copy); | |
| 1259 return &resfiledescr; | |
| 1260 } | |
| 1261 } | |
| 1262 #endif | |
| 1263 if (len > 0 && buf[len-1] != SEP | 1222 if (len > 0 && buf[len-1] != SEP |
| 1264 #ifdef ALTSEP | 1223 #ifdef ALTSEP |
| 1265 && buf[len-1] != ALTSEP | 1224 && buf[len-1] != ALTSEP |
| 1266 #endif | 1225 #endif |
| 1267 ) | 1226 ) |
| 1288 Py_XDECREF(copy); | 1247 Py_XDECREF(copy); |
| 1289 return &fd_package; | 1248 return &fd_package; |
| 1290 } | 1249 } |
| 1291 #endif | 1250 #endif |
| 1292 #endif | 1251 #endif |
| 1293 #ifdef macintosh | |
| 1294 fdp = PyMac_FindModuleExtension(buf, &len, name); | |
| 1295 if (fdp) { | |
| 1296 #else | |
| 1297 #if defined(PYOS_OS2) | 1252 #if defined(PYOS_OS2) |
| 1298 /* take a snapshot of the module spec for restoration | 1253 /* take a snapshot of the module spec for restoration |
| 1299 * after the 8 character DLL hackery | 1254 * after the 8 character DLL hackery |
| 1300 */ | 1255 */ |
| 1301 saved_buf = strdup(buf); | 1256 saved_buf = strdup(buf); |
| 1329 } | 1284 } |
| 1330 #endif /* PYOS_OS2 */ | 1285 #endif /* PYOS_OS2 */ |
| 1331 strcpy(buf+len, fdp->suffix); | 1286 strcpy(buf+len, fdp->suffix); |
| 1332 if (Py_VerboseFlag > 1) | 1287 if (Py_VerboseFlag > 1) |
| 1333 PySys_WriteStderr("# trying %s\n", buf); | 1288 PySys_WriteStderr("# trying %s\n", buf); |
| 1334 #endif /* !macintosh */ | |
| 1335 filemode = fdp->mode; | 1289 filemode = fdp->mode; |
| 1336 if (filemode[0] == 'U') | 1290 if (filemode[0] == 'U') |
| 1337 filemode = "r" PY_STDIOTEXTMODE; | 1291 filemode = "r" PY_STDIOTEXTMODE; |
| 1338 fp = fopen(buf, filemode); | 1292 fp = fopen(buf, filemode); |
| 1339 if (fp != NULL) { | 1293 if (fp != NULL) { |
| 1406 #endif | 1360 #endif |
| 1407 | 1361 |
| 1408 #elif defined(DJGPP) | 1362 #elif defined(DJGPP) |
| 1409 #include <dir.h> | 1363 #include <dir.h> |
| 1410 | 1364 |
| 1411 #elif defined(macintosh) | |
| 1412 #include <TextUtils.h> | |
| 1413 | |
| 1414 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) | 1365 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) |
| 1415 #include <sys/types.h> | 1366 #include <sys/types.h> |
| 1416 #include <dirent.h> | 1367 #include <dirent.h> |
| 1417 | 1368 |
| 1418 #elif defined(PYOS_OS2) | 1369 #elif defined(PYOS_OS2) |
| 1472 "Can't find file for module %.100s\n(filename %.300s)", | 1423 "Can't find file for module %.100s\n(filename %.300s)", |
| 1473 name, buf); | 1424 name, buf); |
| 1474 return 0; | 1425 return 0; |
| 1475 } | 1426 } |
| 1476 return strncmp(ffblk.ff_name, name, namelen) == 0; | 1427 return strncmp(ffblk.ff_name, name, namelen) == 0; |
| 1477 | |
| 1478 /* macintosh */ | |
| 1479 #elif defined(macintosh) | |
| 1480 FSSpec fss; | |
| 1481 OSErr err; | |
| 1482 | |
| 1483 if (Py_GETENV("PYTHONCASEOK") != NULL) | |
| 1484 return 1; | |
| 1485 | |
| 1486 err = FSMakeFSSpec(0, 0, Pstring(buf), &fss); | |
| 1487 if (err) { | |
| 1488 PyErr_Format(PyExc_NameError, | |
| 1489 "Can't find file for module %.100s\n(filename %.300s)", | |
| 1490 name, buf); | |
| 1491 return 0; | |
| 1492 } | |
| 1493 return fss.name[0] >= namelen && | |
| 1494 strncmp(name, (char *)fss.name+1, namelen) == 0; | |
| 1495 | 1428 |
| 1496 /* new-fangled macintosh (macosx) */ | 1429 /* new-fangled macintosh (macosx) */ |
| 1497 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) | 1430 #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) |
| 1498 DIR *dirp; | 1431 DIR *dirp; |
| 1499 struct dirent *dp; | 1432 struct dirent *dp; |
| 1707 case C_EXTENSION: | 1640 case C_EXTENSION: |
| 1708 m = _PyImport_LoadDynamicModule(name, buf, fp); | 1641 m = _PyImport_LoadDynamicModule(name, buf, fp); |
| 1709 break; | 1642 break; |
| 1710 #endif | 1643 #endif |
| 1711 | 1644 |
| 1712 #ifdef macintosh | |
| 1713 case PY_RESOURCE: | |
| 1714 m = PyMac_LoadResourceModule(name, buf); | |
| 1715 break; | |
| 1716 case PY_CODERESOURCE: | |
| 1717 m = PyMac_LoadCodeResourceModule(name, buf); | |
| 1718 break; | |
| 1719 #endif | |
| 1720 | |
| 1721 case PKG_DIRECTORY: | 1645 case PKG_DIRECTORY: |
| 1722 m = load_package(name, buf); | 1646 m = load_package(name, buf); |
| 1723 break; | 1647 break; |
| 1724 | 1648 |
| 1725 case C_BUILTIN: | 1649 case C_BUILTIN: |
| 2676 if (fob == NULL) | 2600 if (fob == NULL) |
| 2677 fclose(fp); | 2601 fclose(fp); |
| 2678 return m; | 2602 return m; |
| 2679 } | 2603 } |
| 2680 | 2604 |
| 2681 #ifdef macintosh | |
| 2682 static PyObject * | |
| 2683 imp_load_resource(PyObject *self, PyObject *args) | |
| 2684 { | |
| 2685 char *name; | |
| 2686 char *pathname; | |
| 2687 PyObject *m; | |
| 2688 | |
| 2689 if (!PyArg_ParseTuple(args, "ss:load_resource", &name, &pathname)) | |
| 2690 return NULL; | |
| 2691 m = PyMac_LoadResourceModule(name, pathname); | |
| 2692 return m; | |
| 2693 } | |
| 2694 #endif /* macintosh */ | |
| 2695 | |
| 2696 static PyObject * | 2605 static PyObject * |
| 2697 imp_load_module(PyObject *self, PyObject *args) | 2606 imp_load_module(PyObject *self, PyObject *args) |
| 2698 { | 2607 { |
| 2699 char *name; | 2608 char *name; |
| 2700 PyObject *fob; | 2609 PyObject *fob; |
| 2820 {"load_compiled", imp_load_compiled, METH_VARARGS}, | 2729 {"load_compiled", imp_load_compiled, METH_VARARGS}, |
| 2821 #ifdef HAVE_DYNAMIC_LOADING | 2730 #ifdef HAVE_DYNAMIC_LOADING |
| 2822 {"load_dynamic", imp_load_dynamic, METH_VARARGS}, | 2731 {"load_dynamic", imp_load_dynamic, METH_VARARGS}, |
| 2823 #endif | 2732 #endif |
| 2824 {"load_package", imp_load_package, METH_VARARGS}, | 2733 {"load_package", imp_load_package, METH_VARARGS}, |
| 2825 #ifdef macintosh | |
| 2826 {"load_resource", imp_load_resource, METH_VARARGS}, | |
| 2827 #endif | |
| 2828 {"load_source", imp_load_source, METH_VARARGS}, | 2734 {"load_source", imp_load_source, METH_VARARGS}, |
| 2829 {NULL, NULL} /* sentinel */ | 2735 {NULL, NULL} /* sentinel */ |
| 2830 }; | 2736 }; |
| 2831 | 2737 |
| 2832 static int | 2738 static int |
