Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 1848:b724599401ff legacy-trunk
Merge back to main trunk
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 30 Aug 1994 08:27:36 +0000 |
| parents | 2937897a7d8b |
| children | d7e91437f0a2 |
comparison
equal
deleted
inserted
replaced
| 1847:0d318475f9e3 | 1848:b724599401ff |
|---|---|
| 1 /*********************************************************** | 1 /*********************************************************** |
| 2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, | 2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
| 3 Amsterdam, The Netherlands. | 3 Amsterdam, The Netherlands. |
| 4 | 4 |
| 5 All Rights Reserved | 5 All Rights Reserved |
| 6 | 6 |
| 7 Permission to use, copy, modify, and distribute this software and its | 7 Permission to use, copy, modify, and distribute this software and its |
| 166 if (name == NULL) | 166 if (name == NULL) |
| 167 break; | 167 break; |
| 168 addlistitem(list, name); | 168 addlistitem(list, name); |
| 169 DECREF(name); | 169 DECREF(name); |
| 170 } | 170 } |
| 171 if (sortlist(list) != 0) { | |
| 172 DECREF(list); | |
| 173 list = NULL; | |
| 174 } | |
| 171 return list; | 175 return list; |
| 172 } | 176 } |
| 173 | 177 |
| 174 void | 178 void |
| 175 initsys() | 179 initsys() |
| 176 { | 180 { |
| 181 extern long getmaxint PROTO((void)); | |
| 182 extern char *getversion PROTO((void)); | |
| 183 extern char *getcopyright PROTO((void)); | |
| 177 extern int fclose PROTO((FILE *)); | 184 extern int fclose PROTO((FILE *)); |
| 178 extern char version[]; | |
| 179 object *v = newstringobject(version); | |
| 180 object *m = initmodule("sys", sys_methods); | 185 object *m = initmodule("sys", sys_methods); |
| 186 object *v; | |
| 181 sysdict = getmoduledict(m); | 187 sysdict = getmoduledict(m); |
| 182 INCREF(sysdict); | 188 INCREF(sysdict); |
| 183 /* NB keep an extra ref to the std files to avoid closing them | 189 /* NB keep an extra ref to the std files to avoid closing them |
| 184 when the user deletes them */ | 190 when the user deletes them */ |
| 185 sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); | 191 sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); |
| 186 sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); | 192 sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); |
| 187 syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); | 193 syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); |
| 188 if (err_occurred()) | 194 if (err_occurred()) |
| 189 fatal("can't create sys.* objects"); | 195 fatal("can't initialize sys.std{in,out,err}"); |
| 190 dictinsert(sysdict, "stdin", sysin); | 196 dictinsert(sysdict, "stdin", sysin); |
| 191 dictinsert(sysdict, "stdout", sysout); | 197 dictinsert(sysdict, "stdout", sysout); |
| 192 dictinsert(sysdict, "stderr", syserr); | 198 dictinsert(sysdict, "stderr", syserr); |
| 193 dictinsert(sysdict, "version", v); | 199 dictinsert(sysdict, "version", v = newstringobject(getversion())); |
| 200 XDECREF(v); | |
| 201 dictinsert(sysdict, "copyright", v = newstringobject(getcopyright())); | |
| 202 XDECREF(v); | |
| 203 dictinsert(sysdict, "maxint", v = newintobject(getmaxint())); | |
| 204 XDECREF(v); | |
| 194 dictinsert(sysdict, "modules", get_modules()); | 205 dictinsert(sysdict, "modules", get_modules()); |
| 195 dictinsert(sysdict, "builtin_module_names", | 206 dictinsert(sysdict, "builtin_module_names", |
| 196 list_builtin_module_names()); | 207 list_builtin_module_names()); |
| 197 if (err_occurred()) | 208 if (err_occurred()) |
| 198 fatal("can't insert sys.* objects in sys dict"); | 209 fatal("can't insert sys.* objects in sys dict"); |
| 199 DECREF(v); | |
| 200 } | 210 } |
| 201 | 211 |
| 202 static object * | 212 static object * |
| 203 makepathobject(path, delim) | 213 makepathobject(path, delim) |
| 204 char *path; | 214 char *path; |
