Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 1886:ac6a9f90f6fd legacy-trunk
* Import/pythonrun.h, Python/{import,pythonrun}.c,
mac/macsetfiletype.c: changes by Jack to execute .pyc file passed
as command line argument. On the Mac .pyc files are given a
special type so they can be double-clicked
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 14 Sep 1994 13:31:04 +0000 |
| parents | 61738ed6cc10 |
| children | 20f17b5accbf |
comparison
equal
deleted
inserted
replaced
| 1885:d3de2cad2c68 | 1886:ac6a9f90f6fd |
|---|---|
| 35 #include "compile.h" | 35 #include "compile.h" |
| 36 #include "eval.h" | 36 #include "eval.h" |
| 37 #include "ceval.h" | 37 #include "ceval.h" |
| 38 #include "pythonrun.h" | 38 #include "pythonrun.h" |
| 39 #include "import.h" | 39 #include "import.h" |
| 40 #include "marshal.h" | |
| 40 | 41 |
| 41 #ifdef HAVE_SIGNAL_H | 42 #ifdef HAVE_SIGNAL_H |
| 42 #include <signal.h> | 43 #include <signal.h> |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 190 run_script(fp, filename) | 191 run_script(fp, filename) |
| 191 FILE *fp; | 192 FILE *fp; |
| 192 char *filename; | 193 char *filename; |
| 193 { | 194 { |
| 194 object *m, *d, *v; | 195 object *m, *d, *v; |
| 196 char *ext; | |
| 197 | |
| 195 m = add_module("__main__"); | 198 m = add_module("__main__"); |
| 196 if (m == NULL) | 199 if (m == NULL) |
| 197 return -1; | 200 return -1; |
| 198 d = getmoduledict(m); | 201 d = getmoduledict(m); |
| 199 v = run_file(fp, filename, file_input, d, d); | 202 ext = filename + strlen(filename) - 4; |
| 203 if ( strcmp(ext, ".pyc") == 0 ) { | |
| 204 /* Try to run a pyc file. First, re-open in binary */ | |
| 205 fclose(fp); | |
| 206 if( (fp = fopen(filename, "rb")) == NULL ) { | |
| 207 fprintf(stderr, "python: Can't reopen .pyc file\n"); | |
| 208 return -1; | |
| 209 } | |
| 210 v = run_pyc_file(fp, filename, d, d); | |
| 211 } else { | |
| 212 v = run_file(fp, filename, file_input, d, d); | |
| 213 } | |
| 200 flushline(); | 214 flushline(); |
| 201 if (v == NULL) { | 215 if (v == NULL) { |
| 202 print_error(); | 216 print_error(); |
| 203 return -1; | 217 return -1; |
| 204 } | 218 } |
| 355 DECREF(co); | 369 DECREF(co); |
| 356 return v; | 370 return v; |
| 357 } | 371 } |
| 358 | 372 |
| 359 object * | 373 object * |
| 374 run_pyc_file(fp, filename, globals, locals) | |
| 375 FILE *fp; | |
| 376 char *filename; | |
| 377 object *globals, *locals; | |
| 378 { | |
| 379 codeobject *co; | |
| 380 object *v; | |
| 381 long magic; | |
| 382 long get_pyc_magic(); | |
| 383 | |
| 384 magic = rd_long(fp); | |
| 385 if (magic != get_pyc_magic()) { | |
| 386 err_setstr(RuntimeError, | |
| 387 "Bad magic number in .pyc file"); | |
| 388 return NULL; | |
| 389 } | |
| 390 (void) rd_long(fp); | |
| 391 v = rd_object(fp); | |
| 392 fclose(fp); | |
| 393 if (v == NULL || !is_codeobject(v)) { | |
| 394 XDECREF(v); | |
| 395 err_setstr(RuntimeError, | |
| 396 "Bad code object in .pyc file"); | |
| 397 return NULL; | |
| 398 } | |
| 399 co = (codeobject *)v; | |
| 400 v = eval_code(co, globals, locals, (object *)NULL, (object *)NULL); | |
| 401 DECREF(co); | |
| 402 return v; | |
| 403 } | |
| 404 | |
| 405 object * | |
| 360 compile_string(str, filename, start) | 406 compile_string(str, filename, start) |
| 361 char *str; | 407 char *str; |
| 362 char *filename; | 408 char *filename; |
| 363 int start; | 409 int start; |
| 364 { | 410 { |
