diff options
author | Guido van Rossum <guido@python.org> | 1993-04-01 20:59:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-04-01 20:59:32 (GMT) |
commit | f56e3db1dd4bedc9331933504f5008a03f5d3131 (patch) | |
tree | e5dad2acc4127f93e054658c6226ecec274c2930 | |
parent | 41ffccbba75413c64efad283da19b8038aa07dd1 (diff) | |
download | cpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.zip cpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.tar.gz cpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.tar.bz2 |
Support for frozen scripts; added -i option.
-rw-r--r-- | Include/marshal.h | 1 | ||||
-rw-r--r-- | Modules/config.c.in | 20 | ||||
-rw-r--r-- | Python/frozenmain.c | 57 | ||||
-rw-r--r-- | Python/import.c | 42 | ||||
-rw-r--r-- | Python/marshal.c | 16 | ||||
-rw-r--r-- | Python/pythonmain.c | 19 |
6 files changed, 150 insertions, 5 deletions
diff --git a/Include/marshal.h b/Include/marshal.h index 9b16227..1adc2ad 100644 --- a/Include/marshal.h +++ b/Include/marshal.h @@ -31,3 +31,4 @@ void wr_object PROTO((object *, FILE *)); long rd_long PROTO((FILE *)); int rd_short PROTO((FILE *)); object *rd_object PROTO((FILE *)); +object *rds_object PROTO((char *, int)); diff --git a/Modules/config.c.in b/Modules/config.c.in index 7dba37c..fe48023 100644 --- a/Modules/config.c.in +++ b/Modules/config.c.in @@ -82,6 +82,8 @@ char version[80]; char *argv0; /* For dynamic loading in import.c */ +extern char verbose; + /*ARGSUSED*/ void initargs(p_argc, p_argv) @@ -98,7 +100,11 @@ initargs(p_argc, p_argv) #endif wargs(p_argc, p_argv); #endif /* USE_STDWIN */ - if (*p_argc < 2 && isatty(0) && isatty(1)) +#ifdef USE_FROZEN + if (verbose) +#else + if (verbose || *p_argc < 2 && isatty(0) && isatty(1)) +#endif { printf("Python %s.\n", version); printf( @@ -448,3 +454,15 @@ struct { {0, 0} /* Sentinel */ }; + +#ifdef USE_FROZEN +#include "frozen.c" +#else +struct frozen { + char *name; + char *code; + int size; +} frozen_modules[] = { + {0, 0, 0} +}; +#endif diff --git a/Python/frozenmain.c b/Python/frozenmain.c new file mode 100644 index 0000000..90d1623 --- /dev/null +++ b/Python/frozenmain.c @@ -0,0 +1,57 @@ +/*********************************************************** +Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, +Amsterdam, The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + +/* Python interpreter main program for frozen scripts */ + +#include "allobjects.h" + +extern char *getenv(); + +extern int debugging; +extern int verbose; + +main(argc, argv) + int argc; + char **argv; +{ + char *p; + int n; + if ((p = getenv("PYTHONDEBUG")) && *p != '\0') + debugging = 1; + if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') + verbose = 1; + initargs(&argc, &argv); /* Defined in config*.c */ + initall(); + setpythonargv(argc, argv); + n = init_frozen("__main__"); + if (n == 0) + fatal("__main__ not frozen"); + if (n < 0) { + print_error(); + goaway(1); + } + else + goaway(0); + /*NOTREACHED*/ +} diff --git a/Python/import.c b/Python/import.c index 2171f4b..4310afa 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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; +} diff --git a/Python/marshal.c b/Python/marshal.c index 65f7f2d..3853ff9 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -225,7 +225,8 @@ wr_object(x, fp) typedef WFILE RFILE; /* Same struct with different invariants */ #define r_byte(p) ((p)->fp ? getc((p)->fp) \ - : ((p)->ptr != (p)->end) ? *(p)->ptr++ : EOF) + : ((p)->ptr != (p)->end) ? \ + (unsigned char)*(p)->ptr++ : EOF) static int r_string(s, n, p) @@ -425,6 +426,19 @@ rd_object(fp) return r_object(&rf); } +object * +rds_object(str, len) + char *str; + int len; +{ + RFILE rf; + rf.fp = NULL; + rf.str = NULL; + rf.ptr = str; + rf.end = str + len; + return r_object(&rf); +} + /* And an interface for Python programs... */ static object * diff --git a/Python/pythonmain.c b/Python/pythonmain.c index 1718611..760e5da 100644 --- a/Python/pythonmain.c +++ b/Python/pythonmain.c @@ -34,6 +34,8 @@ extern int optind; extern char *optarg; extern int getopt PROTO((int, char **, char *)); +extern char *getenv(); + main(argc, argv) int argc; char **argv; @@ -43,10 +45,17 @@ main(argc, argv) char *command = NULL; char *filename = NULL; FILE *fp = stdin; + char *p; + int inspect = 0; + + if ((p = getenv("PYTHONDEBUG")) && *p != '\0') + debugging = 1; + if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') + verbose = 1; initargs(&argc, &argv); /* Defined in config*.c */ - while ((c = getopt(argc, argv, "c:dv")) != EOF) { + while ((c = getopt(argc, argv, "c:div")) != EOF) { if (c == 'c') { /* -c is the last option; following arguments that look like options are left for the @@ -64,6 +73,10 @@ main(argc, argv) debugging++; break; + case 'i': + inspect++; + break; + case 'v': verbose++; break; @@ -118,6 +131,10 @@ main(argc, argv) sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0; } + if (inspect && isatty((int)fileno(stdin)) && + (filename != NULL || command != NULL)) + sts = run(stdin, "<stdin>") != 0; + goaway(sts); /*NOTREACHED*/ } |