comparison Python/import.c @ 68730:fe1d421ca3fa

Issue #3080: Rename some path variables to path_list
author Victor Stinner <victor.stinner@haypocalc.com>
date Mon, 14 Mar 2011 13:22:54 -0400
parents 156818529636
children c1a5a7dca1ec
comparison
equal deleted inserted replaced
68729:156818529636 68730:fe1d421ca3fa
1536 err = PyDict_SetItemString(d, "__path__", path_list); 1536 err = PyDict_SetItemString(d, "__path__", path_list);
1537 if (err != 0) { 1537 if (err != 0) {
1538 Py_DECREF(path_list); 1538 Py_DECREF(path_list);
1539 return NULL; 1539 return NULL;
1540 } 1540 }
1541 fdp = find_module(name, initstr, path_list, buf, sizeof(buf), &fp, NULL); 1541 fdp = find_module(name, initstr, path_list,
1542 buf, sizeof(buf), &fp, NULL);
1542 Py_DECREF(path_list); 1543 Py_DECREF(path_list);
1543 if (fdp == NULL) { 1544 if (fdp == NULL) {
1544 if (PyErr_ExceptionMatches(PyExc_ImportError)) { 1545 if (PyErr_ExceptionMatches(PyExc_ImportError)) {
1545 PyErr_Clear(); 1546 PyErr_Clear();
1546 Py_INCREF(m); 1547 Py_INCREF(m);
3103 3104
3104 static PyObject * 3105 static PyObject *
3105 import_submodule(PyObject *mod, PyObject *subname, PyObject *fullname) 3106 import_submodule(PyObject *mod, PyObject *subname, PyObject *fullname)
3106 { 3107 {
3107 PyObject *modules = PyImport_GetModuleDict(); 3108 PyObject *modules = PyImport_GetModuleDict();
3108 PyObject *m = NULL, *bufobj, *path, *loader; 3109 PyObject *m = NULL, *bufobj, *path_list, *loader;
3109 char buf[MAXPATHLEN+1]; 3110 char buf[MAXPATHLEN+1];
3110 struct filedescr *fdp; 3111 struct filedescr *fdp;
3111 FILE *fp; 3112 FILE *fp;
3112 3113
3113 /* Require: 3114 /* Require:
3119 Py_INCREF(m); 3120 Py_INCREF(m);
3120 return m; 3121 return m;
3121 } 3122 }
3122 3123
3123 if (mod == Py_None) 3124 if (mod == Py_None)
3124 path = NULL; 3125 path_list = NULL;
3125 else { 3126 else {
3126 path = PyObject_GetAttrString(mod, "__path__"); 3127 path_list = PyObject_GetAttrString(mod, "__path__");
3127 if (path == NULL) { 3128 if (path_list == NULL) {
3128 PyErr_Clear(); 3129 PyErr_Clear();
3129 Py_INCREF(Py_None); 3130 Py_INCREF(Py_None);
3130 return Py_None; 3131 return Py_None;
3131 } 3132 }
3132 } 3133 }
3133 3134
3134 fdp = find_module(fullname, 3135 fdp = find_module(fullname, subname, path_list,
3135 subname, 3136 buf, MAXPATHLEN+1, &fp, &loader);
3136 path, buf, MAXPATHLEN+1, 3137 Py_XDECREF(path_list);
3137 &fp, &loader);
3138 Py_XDECREF(path);
3139 if (fdp == NULL) { 3138 if (fdp == NULL) {
3140 if (!PyErr_ExceptionMatches(PyExc_ImportError)) 3139 if (!PyErr_ExceptionMatches(PyExc_ImportError))
3141 return NULL; 3140 return NULL;
3142 PyErr_Clear(); 3141 PyErr_Clear();
3143 Py_INCREF(Py_None); 3142 Py_INCREF(Py_None);
3171 { 3170 {
3172 PyInterpreterState *interp = PyThreadState_Get()->interp; 3171 PyInterpreterState *interp = PyThreadState_Get()->interp;
3173 PyObject *modules_reloading = interp->modules_reloading; 3172 PyObject *modules_reloading = interp->modules_reloading;
3174 PyObject *modules = PyImport_GetModuleDict(); 3173 PyObject *modules = PyImport_GetModuleDict();
3175 char buf[MAXPATHLEN+1]; 3174 char buf[MAXPATHLEN+1];
3176 PyObject *path = NULL, *loader = NULL, *existing_m = NULL; 3175 PyObject *path_list = NULL, *loader = NULL, *existing_m = NULL;
3177 PyObject *nameobj, *bufobj, *subnameobj; 3176 PyObject *nameobj, *bufobj, *subnameobj;
3178 Py_UNICODE *name, *subname; 3177 Py_UNICODE *name, *subname;
3179 struct filedescr *fdp; 3178 struct filedescr *fdp;
3180 FILE *fp = NULL; 3179 FILE *fp = NULL;
3181 PyObject *newm = NULL; 3180 PyObject *newm = NULL;
3235 parentname); 3234 parentname);
3236 Py_DECREF(parentname); 3235 Py_DECREF(parentname);
3237 goto error; 3236 goto error;
3238 } 3237 }
3239 Py_DECREF(parentname); 3238 Py_DECREF(parentname);
3240 path = PyObject_GetAttrString(parent, "__path__"); 3239 path_list = PyObject_GetAttrString(parent, "__path__");
3241 if (path == NULL) 3240 if (path_list == NULL)
3242 PyErr_Clear(); 3241 PyErr_Clear();
3243 subname++; 3242 subname++;
3244 len = PyUnicode_GET_SIZE(nameobj) - (len + 1); 3243 len = PyUnicode_GET_SIZE(nameobj) - (len + 1);
3245 subnameobj = PyUnicode_FromUnicode(subname, len); 3244 subnameobj = PyUnicode_FromUnicode(subname, len);
3246 } 3245 }
3247 if (subnameobj == NULL) 3246 if (subnameobj == NULL)
3248 goto error; 3247 goto error;
3249 fdp = find_module(nameobj, subnameobj, 3248 fdp = find_module(nameobj, subnameobj, path_list,
3250 path, buf, MAXPATHLEN+1, &fp, &loader); 3249 buf, MAXPATHLEN+1, &fp, &loader);
3251 Py_DECREF(subnameobj); 3250 Py_DECREF(subnameobj);
3252 Py_XDECREF(path); 3251 Py_XDECREF(path_list);
3253 3252
3254 if (fdp == NULL) { 3253 if (fdp == NULL) {
3255 Py_XDECREF(loader); 3254 Py_XDECREF(loader);
3256 goto error; 3255 goto error;
3257 } 3256 }
3424 } 3423 }
3425 return list; 3424 return list;
3426 } 3425 }
3427 3426
3428 static PyObject * 3427 static PyObject *
3429 call_find_module(PyObject *name, PyObject *path) 3428 call_find_module(PyObject *name, PyObject *path_list)
3430 { 3429 {
3431 extern int fclose(FILE *); 3430 extern int fclose(FILE *);
3432 PyObject *fob, *ret; 3431 PyObject *fob, *ret;
3433 PyObject *pathobj; 3432 PyObject *pathobj;
3434 struct filedescr *fdp; 3433 struct filedescr *fdp;
3437 int fd = -1; 3436 int fd = -1;
3438 char *found_encoding = NULL; 3437 char *found_encoding = NULL;
3439 char *encoding = NULL; 3438 char *encoding = NULL;
3440 3439
3441 pathname[0] = '\0'; 3440 pathname[0] = '\0';
3442 if (path == Py_None) 3441 if (path_list == Py_None)
3443 path = NULL; 3442 path_list = NULL;
3444 fdp = find_module(NULL, name, path, pathname, MAXPATHLEN+1, &fp, NULL); 3443 fdp = find_module(NULL, name, path_list,
3444 pathname, MAXPATHLEN+1, &fp, NULL);
3445 if (fdp == NULL) 3445 if (fdp == NULL)
3446 return NULL; 3446 return NULL;
3447 if (fp != NULL) { 3447 if (fp != NULL) {
3448 fd = fileno(fp); 3448 fd = fileno(fp);
3449 if (fd != -1) 3449 if (fd != -1)