Mercurial > cpython-lru_cache-weakref
annotate Python/sysmodule.c @ 2586:ae131b8b4e31 legacy-trunk
fix comment about exit()
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 20 Mar 1995 15:09:40 +0000 |
| parents | 6eda642f19d0 |
| children | 6cc637c60ce6 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* System module */ |
| 26 | |
| 27 /* | |
| 28 Various bits of information used by the interpreter are collected in | |
| 29 module 'sys'. | |
| 86 | 30 Function member: |
|
2586
ae131b8b4e31
fix comment about exit()
Guido van Rossum <guido@python.org>
parents:
2421
diff
changeset
|
31 - exit(sts): raise SystemExit |
| 6 | 32 Data members: |
| 33 - stdin, stdout, stderr: standard file objects | |
| 86 | 34 - modules: the table of modules (dictionary) |
| 6 | 35 - path: module search path (list of strings) |
| 86 | 36 - argv: script arguments (list of strings) |
| 37 - ps1, ps2: optional primary and secondary prompts (strings) | |
| 6 | 38 */ |
| 39 | |
| 86 | 40 #include "allobjects.h" |
| 41 | |
| 42 #include "sysmodule.h" | |
| 43 #include "import.h" | |
| 44 #include "modsupport.h" | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
45 #include "osdefs.h" |
| 86 | 46 |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
47 object *sys_trace, *sys_profile; |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
48 int sys_checkinterval; |
| 6 | 49 |
| 50 static object *sysdict; | |
| 51 | |
| 52 object * | |
| 53 sysget(name) | |
| 54 char *name; | |
| 55 { | |
| 56 return dictlookup(sysdict, name); | |
| 57 } | |
| 58 | |
| 59 FILE * | |
| 60 sysgetfile(name, def) | |
| 61 char *name; | |
| 62 FILE *def; | |
| 63 { | |
| 64 FILE *fp = NULL; | |
| 65 object *v = sysget(name); | |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1013
diff
changeset
|
66 if (v != NULL && is_fileobject(v)) |
| 6 | 67 fp = getfilefile(v); |
| 68 if (fp == NULL) | |
| 69 fp = def; | |
| 70 return fp; | |
| 71 } | |
| 72 | |
| 73 int | |
| 74 sysset(name, v) | |
| 75 char *name; | |
| 76 object *v; | |
| 77 { | |
|
631
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
78 if (v == NULL) { |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
79 if (dictlookup(sysdict, name) == NULL) |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
80 return 0; |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
81 else |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
82 return dictremove(sysdict, name); |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
83 } |
| 6 | 84 else |
| 85 return dictinsert(sysdict, name, v); | |
| 86 } | |
| 87 | |
| 88 static object * | |
| 89 sys_exit(self, args) | |
| 90 object *self; | |
| 91 object *args; | |
| 92 { | |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
93 /* Raise SystemExit so callers may catch it or clean up. */ |
|
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
94 err_setval(SystemExit, args); |
|
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
95 return NULL; |
| 6 | 96 } |
| 97 | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
98 static object * |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
99 sys_settrace(self, args) |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
100 object *self; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
101 object *args; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
102 { |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
103 if (args == None) |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
104 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
105 else |
|
901
fea3f594df77
sysmodule.c: calling sys.settrace() or sys.setprofile() without
Guido van Rossum <guido@python.org>
parents:
788
diff
changeset
|
106 XINCREF(args); |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
107 XDECREF(sys_trace); |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
108 sys_trace = args; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
109 INCREF(None); |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
110 return None; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
111 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
112 |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
113 static object * |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
114 sys_setprofile(self, args) |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
115 object *self; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
116 object *args; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
117 { |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
118 if (args == None) |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
119 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
120 else |
|
901
fea3f594df77
sysmodule.c: calling sys.settrace() or sys.setprofile() without
Guido van Rossum <guido@python.org>
parents:
788
diff
changeset
|
121 XINCREF(args); |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
122 XDECREF(sys_profile); |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
123 sys_profile = args; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
124 INCREF(None); |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
125 return None; |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
126 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
127 |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
128 static object * |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
129 sys_setcheckinterval(self, args) |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
130 object *self; |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
131 object *args; |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
132 { |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
133 if (!newgetargs(args, "i", &sys_checkinterval)) |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
134 return NULL; |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
135 INCREF(None); |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
136 return None; |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
137 } |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
138 |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
139 #ifdef USE_MALLOPT |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
140 /* Link with -lmalloc (or -lmpc) on an SGI */ |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
141 #include <malloc.h> |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
142 |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
143 static object * |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
144 sys_mdebug(self, args) |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
145 object *self; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
146 object *args; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
147 { |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
148 int flag; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
149 if (!getargs(args, "i", &flag)) |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
150 return NULL; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
151 mallopt(M_DEBUG, flag); |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
152 INCREF(None); |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
153 return None; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
154 } |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
155 #endif /* USE_MALLOPT */ |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
156 |
| 86 | 157 static struct methodlist sys_methods[] = { |
|
2421
6eda642f19d0
add explicit 0 flags for methodlist
Guido van Rossum <guido@python.org>
parents:
2093
diff
changeset
|
158 {"exit", sys_exit, 0}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
159 #ifdef USE_MALLOPT |
|
2421
6eda642f19d0
add explicit 0 flags for methodlist
Guido van Rossum <guido@python.org>
parents:
2093
diff
changeset
|
160 {"mdebug", sys_mdebug, 0}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
161 #endif |
|
2421
6eda642f19d0
add explicit 0 flags for methodlist
Guido van Rossum <guido@python.org>
parents:
2093
diff
changeset
|
162 {"setprofile", sys_setprofile, 0}, |
|
6eda642f19d0
add explicit 0 flags for methodlist
Guido van Rossum <guido@python.org>
parents:
2093
diff
changeset
|
163 {"settrace", sys_settrace, 0}, |
|
6eda642f19d0
add explicit 0 flags for methodlist
Guido van Rossum <guido@python.org>
parents:
2093
diff
changeset
|
164 {"setcheckinterval", sys_setcheckinterval, 0}, |
| 86 | 165 {NULL, NULL} /* sentinel */ |
| 166 }; | |
| 167 | |
| 6 | 168 static object *sysin, *sysout, *syserr; |
| 169 | |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
170 static object * |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
171 list_builtin_module_names() |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
172 { |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
173 object *list = newlistobject(0); |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
174 int i; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
175 if (list == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
176 return NULL; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
177 for (i = 0; inittab[i].name != NULL; i++) { |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
178 object *name = newstringobject(inittab[i].name); |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
179 if (name == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
180 break; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
181 addlistitem(list, name); |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
182 DECREF(name); |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
183 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
184 if (sortlist(list) != 0) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
185 DECREF(list); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
186 list = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
187 } |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
188 return list; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
189 } |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
190 |
| 6 | 191 void |
| 86 | 192 initsys() |
| 6 | 193 { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
194 extern long getmaxint PROTO((void)); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
195 extern char *getversion PROTO((void)); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
196 extern char *getcopyright PROTO((void)); |
|
265
187ba1733b17
Added fclose to newopenfileobject() calls.
Guido van Rossum <guido@python.org>
parents:
234
diff
changeset
|
197 extern int fclose PROTO((FILE *)); |
| 86 | 198 object *m = initmodule("sys", sys_methods); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
199 object *v; |
| 86 | 200 sysdict = getmoduledict(m); |
| 201 INCREF(sysdict); | |
| 6 | 202 /* NB keep an extra ref to the std files to avoid closing them |
| 203 when the user deletes them */ | |
|
265
187ba1733b17
Added fclose to newopenfileobject() calls.
Guido van Rossum <guido@python.org>
parents:
234
diff
changeset
|
204 sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); |
|
187ba1733b17
Added fclose to newopenfileobject() calls.
Guido van Rossum <guido@python.org>
parents:
234
diff
changeset
|
205 sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); |
|
187ba1733b17
Added fclose to newopenfileobject() calls.
Guido van Rossum <guido@python.org>
parents:
234
diff
changeset
|
206 syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); |
| 6 | 207 if (err_occurred()) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
208 fatal("can't initialize sys.std{in,out,err}"); |
| 6 | 209 dictinsert(sysdict, "stdin", sysin); |
| 210 dictinsert(sysdict, "stdout", sysout); | |
| 211 dictinsert(sysdict, "stderr", syserr); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
212 dictinsert(sysdict, "version", v = newstringobject(getversion())); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
213 XDECREF(v); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
214 dictinsert(sysdict, "copyright", v = newstringobject(getcopyright())); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
215 XDECREF(v); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
216 dictinsert(sysdict, "maxint", v = newintobject(getmaxint())); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
217 XDECREF(v); |
| 86 | 218 dictinsert(sysdict, "modules", get_modules()); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
219 dictinsert(sysdict, "builtin_module_names", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
220 v = list_builtin_module_names()); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
221 XDECREF(v); |
| 6 | 222 if (err_occurred()) |
| 223 fatal("can't insert sys.* objects in sys dict"); | |
| 86 | 224 } |
| 225 | |
| 226 static object * | |
| 227 makepathobject(path, delim) | |
| 228 char *path; | |
| 229 int delim; | |
| 230 { | |
| 231 int i, n; | |
| 232 char *p; | |
| 233 object *v, *w; | |
| 6 | 234 |
| 86 | 235 n = 1; |
| 236 p = path; | |
| 237 while ((p = strchr(p, delim)) != NULL) { | |
| 238 n++; | |
| 239 p++; | |
| 240 } | |
| 241 v = newlistobject(n); | |
| 242 if (v == NULL) | |
| 243 return NULL; | |
| 244 for (i = 0; ; i++) { | |
| 245 p = strchr(path, delim); | |
| 246 if (p == NULL) | |
| 247 p = strchr(path, '\0'); /* End of string */ | |
| 248 w = newsizedstringobject(path, (int) (p - path)); | |
| 249 if (w == NULL) { | |
| 250 DECREF(v); | |
| 251 return NULL; | |
| 252 } | |
| 253 setlistitem(v, i, w); | |
| 254 if (*p == '\0') | |
| 255 break; | |
| 256 path = p+1; | |
| 257 } | |
| 258 return v; | |
| 259 } | |
| 260 | |
| 261 void | |
| 262 setpythonpath(path) | |
| 263 char *path; | |
| 264 { | |
| 265 object *v; | |
| 266 if ((v = makepathobject(path, DELIM)) == NULL) | |
| 267 fatal("can't create sys.path"); | |
| 268 if (sysset("path", v) != 0) | |
| 269 fatal("can't assign sys.path"); | |
|
83
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
270 DECREF(v); |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
271 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
272 |
| 86 | 273 static object * |
| 274 makeargvobject(argc, argv) | |
| 275 int argc; | |
| 276 char **argv; | |
|
83
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
277 { |
| 86 | 278 object *av; |
|
596
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
279 if (argc <= 0 || argv == NULL) { |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
280 /* Ensure at least one (empty) argument is seen */ |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
281 static char *empty_argv[1] = {""}; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
282 argv = empty_argv; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
283 argc = 1; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
284 } |
| 86 | 285 av = newlistobject(argc); |
| 286 if (av != NULL) { | |
| 287 int i; | |
| 288 for (i = 0; i < argc; i++) { | |
| 289 object *v = newstringobject(argv[i]); | |
| 290 if (v == NULL) { | |
| 291 DECREF(av); | |
| 292 av = NULL; | |
| 293 break; | |
| 294 } | |
| 295 setlistitem(av, i, v); | |
|
83
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
296 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
297 } |
| 86 | 298 return av; |
| 6 | 299 } |
| 300 | |
| 301 void | |
| 86 | 302 setpythonargv(argc, argv) |
| 303 int argc; | |
| 304 char **argv; | |
| 6 | 305 { |
| 86 | 306 object *av = makeargvobject(argc, argv); |
| 307 if (av == NULL) | |
| 308 fatal("no mem for sys.argv"); | |
| 309 if (sysset("argv", av) != 0) | |
| 310 fatal("can't assign sys.argv"); | |
| 311 DECREF(av); | |
| 6 | 312 } |
