Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 476:bec963f99bc9 legacy-trunk
Added sys.version object.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 10 Dec 1991 14:00:21 +0000 |
| parents | f900b692b37e |
| children | 4efff6cea90f |
comparison
equal
deleted
inserted
replaced
| 475:e2c3463c4d91 | 476:bec963f99bc9 |
|---|---|
| 113 | 113 |
| 114 void | 114 void |
| 115 initsys() | 115 initsys() |
| 116 { | 116 { |
| 117 extern int fclose PROTO((FILE *)); | 117 extern int fclose PROTO((FILE *)); |
| 118 extern char version[]; | |
| 119 object *v = newstringobject(version); | |
| 118 object *m = initmodule("sys", sys_methods); | 120 object *m = initmodule("sys", sys_methods); |
| 119 sysdict = getmoduledict(m); | 121 sysdict = getmoduledict(m); |
| 120 INCREF(sysdict); | 122 INCREF(sysdict); |
| 121 /* NB keep an extra ref to the std files to avoid closing them | 123 /* NB keep an extra ref to the std files to avoid closing them |
| 122 when the user deletes them */ | 124 when the user deletes them */ |
| 123 sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); | 125 sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); |
| 124 sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); | 126 sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); |
| 125 syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); | 127 syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); |
| 126 if (err_occurred()) | 128 if (err_occurred()) |
| 127 fatal("can't create sys.std* file objects"); | 129 fatal("can't create sys.* objects"); |
| 128 dictinsert(sysdict, "stdin", sysin); | 130 dictinsert(sysdict, "stdin", sysin); |
| 129 dictinsert(sysdict, "stdout", sysout); | 131 dictinsert(sysdict, "stdout", sysout); |
| 130 dictinsert(sysdict, "stderr", syserr); | 132 dictinsert(sysdict, "stderr", syserr); |
| 133 dictinsert(sysdict, "version", v); | |
| 131 dictinsert(sysdict, "modules", get_modules()); | 134 dictinsert(sysdict, "modules", get_modules()); |
| 132 if (err_occurred()) | 135 if (err_occurred()) |
| 133 fatal("can't insert sys.* objects in sys dict"); | 136 fatal("can't insert sys.* objects in sys dict"); |
| 137 DECREF(v); | |
| 134 } | 138 } |
| 135 | 139 |
| 136 static object * | 140 static object * |
| 137 makepathobject(path, delim) | 141 makepathobject(path, delim) |
| 138 char *path; | 142 char *path; |
