mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Support for frozen scripts; added -i option.
This commit is contained in:
parent
41ffccbba7
commit
f56e3db1dd
6 changed files with 150 additions and 5 deletions
|
@ -52,7 +52,7 @@ extern int verbose; /* Defined in pythonmain.c */
|
|||
extern char *argv0;
|
||||
#endif
|
||||
|
||||
/* Magic word to reject pre-0.9.9 .pyc files */
|
||||
/* Magic word to reject .pyc files generated by other Python versions */
|
||||
|
||||
#define MAGIC 0x99BE3AL
|
||||
|
||||
|
@ -325,8 +325,11 @@ import_module(name)
|
|||
char *name;
|
||||
{
|
||||
object *m;
|
||||
int n;
|
||||
if ((m = dictlookup(modules, name)) == NULL) {
|
||||
if (init_builtin(name)) {
|
||||
if ((n = init_builtin(name)) || (n = init_frozen(name))) {
|
||||
if (n < 0)
|
||||
return NULL;
|
||||
if ((m = dictlookup(modules, name)) == NULL)
|
||||
err_setstr(SystemError,
|
||||
"builtin module missing");
|
||||
|
@ -411,3 +414,38 @@ init_builtin(name)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern struct frozen {
|
||||
char *name;
|
||||
char *code;
|
||||
int size;
|
||||
} frozen_modules[];
|
||||
|
||||
int
|
||||
init_frozen(name)
|
||||
char *name;
|
||||
{
|
||||
struct frozen *p;
|
||||
codeobject *co;
|
||||
object *m, *d, *v;
|
||||
for (p = frozen_modules; ; p++) {
|
||||
if (p->name == NULL)
|
||||
return 0;
|
||||
if (strcmp(p->name, name) == 0)
|
||||
break;
|
||||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "import %s # frozen\n", name);
|
||||
co = (codeobject *) rds_object(p->code, p->size);
|
||||
if (co == NULL)
|
||||
return -1;
|
||||
if ((m = add_module(name)) == NULL ||
|
||||
(d = getmoduledict(m)) == NULL ||
|
||||
(v = eval_code(co, d, d, (object *)NULL)) == NULL) {
|
||||
DECREF(co);
|
||||
return -1;
|
||||
}
|
||||
DECREF(co);
|
||||
DECREF(v);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue