Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a86f77d

Browse files
committed
Crrected a flow control error that caused the wrong error message when
load-module() didn't find a built-in or frozen module. Also got rid of is_frozen(), which duplicated the functionality of find_frozen()!=NULL.
1 parent b95901e commit a86f77d

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

Python/import.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ load_source_module(name, pathname, fp)
546546
static PyObject *load_module Py_PROTO((char *, FILE *, char *, int));
547547
static struct filedescr *find_module Py_PROTO((char *, PyObject *,
548548
char *, int, FILE **));
549+
static struct _frozen *find_frozen Py_PROTO((char *name));
549550

550551
/* Load a package and return its module object WITH INCREMENTED
551552
REFERENCE COUNT */
@@ -622,22 +623,6 @@ is_builtin(name)
622623
return 0;
623624
}
624625

625-
/* Helper to test for frozen module */
626-
627-
static int
628-
is_frozen(name)
629-
char *name;
630-
{
631-
struct _frozen *p;
632-
for (p = PyImport_FrozenModules; ; p++) {
633-
if (p->name == NULL)
634-
break;
635-
if (strcmp(p->name, name) == 0)
636-
return 1;
637-
}
638-
return 0;
639-
}
640-
641626

642627
/* Search the path (default sys.path) for a module. Return the
643628
corresponding filedescr struct, and (via return arguments) the
@@ -666,7 +651,7 @@ find_module(name, path, buf, buflen, p_fp)
666651
static struct filedescr fd = {"", "", C_BUILTIN};
667652
return &fd;
668653
}
669-
if (is_frozen(name)) {
654+
if (find_frozen(name) != NULL) {
670655
static struct filedescr fd = {"", "", PY_FROZEN};
671656
return &fd;
672657
}
@@ -837,14 +822,14 @@ load_module(name, fp, buf, type)
837822
else
838823
err = PyImport_ImportFrozenModule(name);
839824
if (err < 0)
840-
goto failure;
825+
return NULL;
841826
if (err == 0) {
842827
PyErr_Format(PyExc_ImportError,
843828
"Purported %s module %.200s not found",
844829
type == C_BUILTIN ?
845830
"builtin" : "frozen",
846831
name);
847-
goto failure;
832+
return NULL;
848833
}
849834
modules = PyImport_GetModuleDict();
850835
m = PyDict_GetItemString(modules, name);
@@ -855,13 +840,12 @@ load_module(name, fp, buf, type)
855840
type == C_BUILTIN ?
856841
"builtin" : "frozen",
857842
name);
858-
goto failure;
843+
return NULL;
859844
}
860845
Py_INCREF(m);
861846
break;
862847

863848
default:
864-
failure:
865849
PyErr_Format(PyExc_ImportError,
866850
"Don't know how to import %.200s (type code %d)",
867851
name, type);
@@ -1636,7 +1620,7 @@ imp_is_frozen(self, args)
16361620
char *name;
16371621
if (!PyArg_ParseTuple(args, "s", &name))
16381622
return NULL;
1639-
return PyInt_FromLong(is_frozen(name));
1623+
return PyInt_FromLong(find_frozen(name) != NULL);
16401624
}
16411625

16421626
static FILE *

0 commit comments

Comments
 (0)