Mercurial > cpython-lru_cache-weakref
annotate Python/sysmodule.c @ 13968:841cf9012ac3 legacy-trunk
Add a byte_order value to the sys module. The value is "big" for
big-endian machines and "little" for little-endian machines.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Mon, 14 Aug 2000 15:47:03 +0000 |
| parents | b54f11ada91e |
| children | aa4202702252 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
5 All rights reserved. |
| 145 | 6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13096
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 145 | 9 ******************************************************************/ |
| 10 | |
| 6 | 11 /* System module */ |
| 12 | |
| 13 /* | |
| 14 Various bits of information used by the interpreter are collected in | |
| 15 module 'sys'. | |
| 86 | 16 Function member: |
|
2586
ae131b8b4e31
fix comment about exit()
Guido van Rossum <guido@python.org>
parents:
2421
diff
changeset
|
17 - exit(sts): raise SystemExit |
| 6 | 18 Data members: |
| 19 - stdin, stdout, stderr: standard file objects | |
| 86 | 20 - modules: the table of modules (dictionary) |
| 6 | 21 - path: module search path (list of strings) |
| 86 | 22 - argv: script arguments (list of strings) |
| 23 - ps1, ps2: optional primary and secondary prompts (strings) | |
| 6 | 24 */ |
| 25 | |
| 5372 | 26 #include "Python.h" |
| 86 | 27 |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
28 #include "osdefs.h" |
| 86 | 29 |
|
5550
43822e4fc27d
Use #ifdef in stead of #if (Jack)
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
30 #ifdef HAVE_UNISTD_H |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
31 #include <unistd.h> |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
32 #endif |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
33 |
|
4291
1427d61f1307
Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents:
4256
diff
changeset
|
34 #ifdef MS_COREDLL |
|
3490
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
35 extern void *PyWin_DLLhModule; |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
36 /* A string loaded from the DLL at startup: */ |
|
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
37 extern const char *PyWin_DLLVersionString; |
|
3490
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
38 #endif |
|
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
39 |
| 5372 | 40 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
41 PySys_GetObject(char *name) |
| 6 | 42 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
43 PyThreadState *tstate = PyThreadState_Get(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
44 PyObject *sd = tstate->interp->sysdict; |
|
11374
66216f32403d
In PySys_GetObject(), it's possible that tstate->interp->sysdict is
Guido van Rossum <guido@python.org>
parents:
9964
diff
changeset
|
45 if (sd == NULL) |
|
66216f32403d
In PySys_GetObject(), it's possible that tstate->interp->sysdict is
Guido van Rossum <guido@python.org>
parents:
9964
diff
changeset
|
46 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
47 return PyDict_GetItemString(sd, name); |
| 6 | 48 } |
| 49 | |
| 50 FILE * | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
51 PySys_GetFile(char *name, FILE *def) |
| 6 | 52 { |
| 53 FILE *fp = NULL; | |
| 5372 | 54 PyObject *v = PySys_GetObject(name); |
| 55 if (v != NULL && PyFile_Check(v)) | |
| 56 fp = PyFile_AsFile(v); | |
| 6 | 57 if (fp == NULL) |
| 58 fp = def; | |
| 59 return fp; | |
| 60 } | |
| 61 | |
| 62 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
63 PySys_SetObject(char *name, PyObject *v) |
| 6 | 64 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
65 PyThreadState *tstate = PyThreadState_Get(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
66 PyObject *sd = tstate->interp->sysdict; |
|
631
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
67 if (v == NULL) { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
68 if (PyDict_GetItemString(sd, name) == NULL) |
|
631
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
69 return 0; |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
70 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
71 return PyDict_DelItemString(sd, name); |
|
631
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
72 } |
| 6 | 73 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
74 return PyDict_SetItemString(sd, name, v); |
| 6 | 75 } |
| 76 | |
| 5372 | 77 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
78 sys_exc_info(PyObject *self, PyObject *args) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
79 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
80 PyThreadState *tstate; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
81 if (!PyArg_ParseTuple(args, ":exc_info")) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
82 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
83 tstate = PyThreadState_Get(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
84 return Py_BuildValue( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
85 "(OOO)", |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
86 tstate->exc_type != NULL ? tstate->exc_type : Py_None, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
87 tstate->exc_value != NULL ? tstate->exc_value : Py_None, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
88 tstate->exc_traceback != NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
89 tstate->exc_traceback : Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
90 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
91 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
92 static char exc_info_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
93 "exc_info() -> (type, value, traceback)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
94 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
95 Return information about the exception that is currently being handled.\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
96 This should be called from inside an except clause only."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
97 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
98 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
99 sys_exit(PyObject *self, PyObject *args) |
| 6 | 100 { |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
101 /* Raise SystemExit so callers may catch it or clean up. */ |
| 5372 | 102 PyErr_SetObject(PyExc_SystemExit, args); |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
103 return NULL; |
| 6 | 104 } |
| 105 | |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
106 static char exit_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
107 "exit([status])\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
108 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
109 Exit the interpreter by raising SystemExit(status).\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
110 If the status is omitted or None, it defaults to zero (i.e., success).\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
111 If the status numeric, it will be used as the system exit status.\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
112 If it is another kind of object, it will be printed and the system\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
113 exit status will be one (i.e., failure)."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
114 |
| 5372 | 115 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
116 sys_getdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
117 { |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
118 if (!PyArg_ParseTuple(args, ":getdefaultencoding")) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
119 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
120 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
121 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
122 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
123 static char getdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
124 "getdefaultencoding() -> string\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
125 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
126 Return the current default string encoding used by the Unicode \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
127 implementation."; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
128 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
129 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
130 sys_setdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
131 { |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
132 char *encoding; |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
133 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding)) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
134 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
135 if (PyUnicode_SetDefaultEncoding(encoding)) |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
136 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
137 Py_INCREF(Py_None); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
138 return Py_None; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
139 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
140 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
141 static char setdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
142 "setdefaultencoding(encoding)\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
143 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
144 Set the current default string encoding used by the Unicode implementation."; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
145 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
146 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
147 sys_settrace(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
148 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
149 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 150 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
151 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
152 else |
| 5372 | 153 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
154 Py_XDECREF(tstate->sys_tracefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
155 tstate->sys_tracefunc = args; |
| 5372 | 156 Py_INCREF(Py_None); |
| 157 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
158 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
159 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
160 static char settrace_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
161 "settrace(function)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
162 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
163 Set the global debug tracing function. It will be called on each\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
164 function call. See the debugger chapter in the library manual."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
165 |
| 5372 | 166 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
167 sys_setprofile(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
168 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
169 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 170 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
171 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
172 else |
| 5372 | 173 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
174 Py_XDECREF(tstate->sys_profilefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
175 tstate->sys_profilefunc = args; |
| 5372 | 176 Py_INCREF(Py_None); |
| 177 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
178 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
179 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
180 static char setprofile_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
181 "setprofile(function)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
182 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
183 Set the profiling function. It will be called on each function call\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
184 and return. See the profiler chapter in the library manual."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
185 |
| 5372 | 186 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
187 sys_setcheckinterval(PyObject *self, PyObject *args) |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
188 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
189 PyThreadState *tstate = PyThreadState_Get(); |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11374
diff
changeset
|
190 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &tstate->interp->checkinterval)) |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
191 return NULL; |
| 5372 | 192 Py_INCREF(Py_None); |
| 193 return Py_None; | |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
194 } |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
195 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
196 static char setcheckinterval_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
197 "setcheckinterval(n)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
198 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
199 Tell the Python interpreter to check for asynchronous events every\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
200 n instructions. This also affects how often thread switches occur."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
201 |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
202 #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
|
203 /* 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
|
204 #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
|
205 |
| 5372 | 206 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
207 sys_mdebug(PyObject *self, PyObject *args) |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
208 { |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
209 int flag; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
210 if (!PyArg_ParseTuple(args, "i:mdebug", &flag)) |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
211 return NULL; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
212 mallopt(M_DEBUG, flag); |
| 5372 | 213 Py_INCREF(Py_None); |
| 214 return Py_None; | |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
215 } |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
216 #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
|
217 |
| 5372 | 218 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
219 sys_getrefcount(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
220 { |
| 5372 | 221 PyObject *arg; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
222 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
223 return NULL; |
|
12965
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
224 return PyInt_FromLong(arg->ob_refcnt); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
225 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
226 |
|
12965
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
227 #ifdef Py_TRACE_REFS |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
228 static PyObject * |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
229 sys_gettotalrefcount(PyObject *self, PyObject *args) |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
230 { |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
231 extern long _Py_RefTotal; |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
232 if (!PyArg_ParseTuple(args, ":gettotalrefcount")) |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
233 return NULL; |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
234 return PyInt_FromLong(_Py_RefTotal); |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
235 } |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
236 |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
237 #endif /* Py_TRACE_REFS */ |
|
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
238 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
239 static char getrefcount_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
240 "getrefcount(object) -> integer\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
241 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
242 Return the current reference count for the object. This includes the\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
243 temporary reference in the argument list, so it is at least 2."; |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
244 |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
245 #ifdef COUNT_ALLOCS |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
246 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
247 sys_getcounts(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
248 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
249 extern PyObject *get_counts(void); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
250 |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
251 if (!PyArg_ParseTuple(args, ":getcounts")) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
252 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
253 return get_counts(); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
254 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
255 #endif |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
256 |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
257 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
258 /* Defined in objects.c because it uses static globals if that file */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
259 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
260 #endif |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
261 |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
262 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
263 /* Defined in ceval.c because it uses static globals if that file */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
264 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
265 #endif |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
266 |
| 5372 | 267 static PyMethodDef sys_methods[] = { |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
268 /* Might as well keep this in alphabetic order */ |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
269 {"exc_info", sys_exc_info, 1, exc_info_doc}, |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
270 {"exit", sys_exit, 0, exit_doc}, |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
271 {"getdefaultencoding", sys_getdefaultencoding, 1, getdefaultencoding_doc}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
272 #ifdef COUNT_ALLOCS |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
273 {"getcounts", sys_getcounts, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
274 #endif |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
275 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
276 {"getdxp", _Py_GetDXProfile, 1}, |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
277 #endif |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
278 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
279 {"getobjects", _Py_GetObjects, 1}, |
|
12965
04c89d77dfdb
Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents:
12877
diff
changeset
|
280 {"gettotalrefcount", sys_gettotalrefcount, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
281 #endif |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
282 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
283 #ifdef USE_MALLOPT |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
284 {"mdebug", sys_mdebug, 1}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
285 #endif |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
286 {"setdefaultencoding", sys_setdefaultencoding, 1, setdefaultencoding_doc}, |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
287 {"setcheckinterval", sys_setcheckinterval, 1, setcheckinterval_doc}, |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
288 {"setprofile", sys_setprofile, 0, setprofile_doc}, |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
289 {"settrace", sys_settrace, 0, settrace_doc}, |
| 86 | 290 {NULL, NULL} /* sentinel */ |
| 291 }; | |
| 292 | |
| 5372 | 293 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
294 list_builtin_module_names(void) |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
295 { |
| 5372 | 296 PyObject *list = PyList_New(0); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
297 int i; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
298 if (list == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
299 return NULL; |
|
6550
f406ec35bfca
Get rid of another reference to _PyImport_Inittab (now a static array)
Guido van Rossum <guido@python.org>
parents:
6352
diff
changeset
|
300 for (i = 0; PyImport_Inittab[i].name != NULL; i++) { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
301 PyObject *name = PyString_FromString( |
|
6550
f406ec35bfca
Get rid of another reference to _PyImport_Inittab (now a static array)
Guido van Rossum <guido@python.org>
parents:
6352
diff
changeset
|
302 PyImport_Inittab[i].name); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
303 if (name == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
304 break; |
| 5372 | 305 PyList_Append(list, name); |
| 306 Py_DECREF(name); | |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
307 } |
| 5372 | 308 if (PyList_Sort(list) != 0) { |
| 309 Py_DECREF(list); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
310 list = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
311 } |
|
4904
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
312 if (list) { |
| 5372 | 313 PyObject *v = PyList_AsTuple(list); |
| 314 Py_DECREF(list); | |
|
4904
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
315 list = v; |
|
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
316 } |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
317 return list; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
318 } |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
319 |
|
8840
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
320 /* XXX This doc string is too long to be a single string literal in VC++ 5.0. |
|
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
321 Two literals concatenated works just fine. If you have a K&R compiler |
|
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
322 or other abomination that however *does* understand longer strings, |
|
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
323 get rid of the !!! comment in the middle and the quotes that surround it. */ |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
324 static char sys_doc[] = |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
325 "This module provides access to some objects used or maintained by the\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
326 interpreter and to functions that interact strongly with the interpreter.\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
327 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
328 Dynamic objects:\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
329 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
330 argv -- command line arguments; argv[0] is the script pathname if known\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
331 path -- module search path; path[0] is the script directory, else ''\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
332 modules -- dictionary of loaded modules\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
333 exitfunc -- you may set this to a function to be called when Python exits\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
334 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
335 stdin -- standard input file object; used by raw_input() and input()\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
336 stdout -- standard output file object; used by the print statement\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
337 stderr -- standard error object; used for error messages\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
338 By assigning another file object (or an object that behaves like a file)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
339 to one of these, it is possible to redirect all of the interpreter's I/O.\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
340 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
341 last_type -- type of last uncaught exception\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
342 last_value -- value of last uncaught exception\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
343 last_traceback -- traceback of last uncaught exception\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
344 These three are only available in an interactive session after a\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
345 traceback has been printed.\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
346 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
347 exc_type -- type of exception currently being handled\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
348 exc_value -- value of exception currently being handled\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
349 exc_traceback -- traceback of exception currently being handled\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
350 The function exc_info() should be used instead of these three,\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
351 because it is thread-safe.\n\ |
|
9885
030ee50bd8d1
Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents:
9746
diff
changeset
|
352 " |
|
030ee50bd8d1
Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents:
9746
diff
changeset
|
353 #ifndef MS_WIN16 |
|
030ee50bd8d1
Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents:
9746
diff
changeset
|
354 /* Concatenating string here */ |
|
030ee50bd8d1
Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents:
9746
diff
changeset
|
355 "\n\ |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
356 Static objects:\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
357 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
358 maxint -- the largest supported integer (the smallest is -maxint-1)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
359 builtin_module_names -- tuple of module names built into this intepreter\n\ |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
360 version -- the version of this interpreter as a string\n\ |
|
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
361 version_info -- version information as a tuple\n\ |
|
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
362 hexversion -- version information encoded as a single integer\n\ |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
363 copyright -- copyright notice pertaining to this interpreter\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
364 platform -- platform identifier\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
365 executable -- pathname of this Python interpreter\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
366 prefix -- prefix used to find the Python library\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
367 exec_prefix -- prefix used to find the machine-specific Python library\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
368 dllhandle -- [Windows only] integer handle of the Python DLL\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
369 winver -- [Windows only] version number of the Python DLL\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
370 __stdin__ -- the original stdin; don't use!\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
371 __stdout__ -- the original stdout; don't use!\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
372 __stderr__ -- the original stderr; don't use!\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
373 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
374 Functions:\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
375 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
376 exc_info() -- return thread-safe information about the current exception\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
377 exit() -- exit the interpreter by raising SystemExit\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
378 getrefcount() -- return the reference count for an object (plus one :-)\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
379 setcheckinterval() -- control how often the interpreter checks for events\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
380 setprofile() -- set the global profiling function\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
381 settrace() -- set the global debug tracing function\n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
382 "; |
|
9885
030ee50bd8d1
Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents:
9746
diff
changeset
|
383 #endif |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
384 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
385 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
386 _PySys_Init(void) |
| 6 | 387 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
388 PyObject *m, *v, *sysdict; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
389 PyObject *sysin, *sysout, *syserr; |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
390 char *s; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
391 |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
392 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 5372 | 393 sysdict = PyModule_GetDict(m); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
394 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
395 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
396 sysout = PyFile_FromFile(stdout, "<stdout>", "w", NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
397 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); |
| 5372 | 398 if (PyErr_Occurred()) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
399 return NULL; |
| 5372 | 400 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 401 PyDict_SetItemString(sysdict, "stdout", sysout); | |
| 402 PyDict_SetItemString(sysdict, "stderr", syserr); | |
|
7402
c7454ca7d3ac
Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents:
6550
diff
changeset
|
403 /* Make backup copies for cleanup */ |
|
c7454ca7d3ac
Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents:
6550
diff
changeset
|
404 PyDict_SetItemString(sysdict, "__stdin__", sysin); |
|
c7454ca7d3ac
Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents:
6550
diff
changeset
|
405 PyDict_SetItemString(sysdict, "__stdout__", sysout); |
|
c7454ca7d3ac
Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents:
6550
diff
changeset
|
406 PyDict_SetItemString(sysdict, "__stderr__", syserr); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
407 Py_XDECREF(sysin); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
408 Py_XDECREF(sysout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
409 Py_XDECREF(syserr); |
| 5372 | 410 PyDict_SetItemString(sysdict, "version", |
| 411 v = PyString_FromString(Py_GetVersion())); | |
|
9964
d44cb87e500d
_PySys_Init(): Nailed small memory leak. The stringobject created for
Barry Warsaw <barry@python.org>
parents:
9885
diff
changeset
|
412 Py_XDECREF(v); |
|
9746
9342c60eaac0
Add sys.hexversion, which is an integer encoding the version in hexadecimal.
Guido van Rossum <guido@python.org>
parents:
9328
diff
changeset
|
413 PyDict_SetItemString(sysdict, "hexversion", |
|
9342c60eaac0
Add sys.hexversion, which is an integer encoding the version in hexadecimal.
Guido van Rossum <guido@python.org>
parents:
9328
diff
changeset
|
414 v = PyInt_FromLong(PY_VERSION_HEX)); |
| 5372 | 415 Py_XDECREF(v); |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
416 /* |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
417 * These release level checks are mutually exclusive and cover |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
418 * the field, so don't get too fancy with the pre-processor! |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
419 */ |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
420 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
421 s = "alpha"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
422 #endif |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
423 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
424 s = "beta"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
425 #endif |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
426 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
427 s = "candidate"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
428 #endif |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
429 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
430 s = "final"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
431 #endif |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
432 PyDict_SetItemString(sysdict, "version_info", |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
433 v = Py_BuildValue("iiisi", PY_MAJOR_VERSION, |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
434 PY_MINOR_VERSION, |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
435 PY_MICRO_VERSION, s, |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
436 PY_RELEASE_SERIAL)); |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
437 Py_XDECREF(v); |
| 5372 | 438 PyDict_SetItemString(sysdict, "copyright", |
| 439 v = PyString_FromString(Py_GetCopyright())); | |
| 440 Py_XDECREF(v); | |
| 441 PyDict_SetItemString(sysdict, "platform", | |
| 442 v = PyString_FromString(Py_GetPlatform())); | |
| 443 Py_XDECREF(v); | |
|
5598
1f206c91daee
Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents:
5550
diff
changeset
|
444 PyDict_SetItemString(sysdict, "executable", |
|
1f206c91daee
Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents:
5550
diff
changeset
|
445 v = PyString_FromString(Py_GetProgramFullPath())); |
|
1f206c91daee
Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents:
5550
diff
changeset
|
446 Py_XDECREF(v); |
| 5372 | 447 PyDict_SetItemString(sysdict, "prefix", |
| 448 v = PyString_FromString(Py_GetPrefix())); | |
| 449 Py_XDECREF(v); | |
| 450 PyDict_SetItemString(sysdict, "exec_prefix", | |
| 451 v = PyString_FromString(Py_GetExecPrefix())); | |
| 452 Py_XDECREF(v); | |
| 453 PyDict_SetItemString(sysdict, "maxint", | |
| 454 v = PyInt_FromLong(PyInt_GetMax())); | |
| 455 Py_XDECREF(v); | |
| 456 PyDict_SetItemString(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
|
457 v = list_builtin_module_names()); |
| 5372 | 458 Py_XDECREF(v); |
|
13968
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
459 { |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
460 /* Assumes that longs are at least 2 bytes long. |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
461 Should be safe! */ |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
462 unsigned long number = 1; |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
463 |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
464 s = (char *) &number; |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
465 if (s[0] == 0) |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
466 PyDict_SetItemString(sysdict, "byte_order", |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
467 PyString_FromString("big")); |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
468 else |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
469 PyDict_SetItemString(sysdict, "byte_order", |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
470 PyString_FromString("little")); |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
471 } |
|
4126
c80c515999b9
Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents:
3877
diff
changeset
|
472 #ifdef MS_COREDLL |
| 5372 | 473 PyDict_SetItemString(sysdict, "dllhandle", |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12965
diff
changeset
|
474 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 5372 | 475 Py_XDECREF(v); |
| 476 PyDict_SetItemString(sysdict, "winver", | |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
477 v = PyString_FromString(PyWin_DLLVersionString)); |
| 5372 | 478 Py_XDECREF(v); |
|
3490
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
479 #endif |
| 5372 | 480 if (PyErr_Occurred()) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
481 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
482 return m; |
| 86 | 483 } |
| 484 | |
| 5372 | 485 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
486 makepathobject(char *path, int delim) |
| 86 | 487 { |
| 488 int i, n; | |
| 489 char *p; | |
| 5372 | 490 PyObject *v, *w; |
| 6 | 491 |
| 86 | 492 n = 1; |
| 493 p = path; | |
| 494 while ((p = strchr(p, delim)) != NULL) { | |
| 495 n++; | |
| 496 p++; | |
| 497 } | |
| 5372 | 498 v = PyList_New(n); |
| 86 | 499 if (v == NULL) |
| 500 return NULL; | |
| 501 for (i = 0; ; i++) { | |
| 502 p = strchr(path, delim); | |
| 503 if (p == NULL) | |
| 504 p = strchr(path, '\0'); /* End of string */ | |
| 5372 | 505 w = PyString_FromStringAndSize(path, (int) (p - path)); |
| 86 | 506 if (w == NULL) { |
| 5372 | 507 Py_DECREF(v); |
| 86 | 508 return NULL; |
| 509 } | |
| 5372 | 510 PyList_SetItem(v, i, w); |
| 86 | 511 if (*p == '\0') |
| 512 break; | |
| 513 path = p+1; | |
| 514 } | |
| 515 return v; | |
| 516 } | |
| 517 | |
| 518 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
519 PySys_SetPath(char *path) |
| 86 | 520 { |
| 5372 | 521 PyObject *v; |
| 86 | 522 if ((v = makepathobject(path, DELIM)) == NULL) |
| 5372 | 523 Py_FatalError("can't create sys.path"); |
| 524 if (PySys_SetObject("path", v) != 0) | |
| 525 Py_FatalError("can't assign sys.path"); | |
| 526 Py_DECREF(v); | |
|
83
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
527 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
528 |
| 5372 | 529 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
530 makeargvobject(int argc, char **argv) |
|
83
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
531 { |
| 5372 | 532 PyObject *av; |
|
596
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
533 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
|
534 /* 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
|
535 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
|
536 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
|
537 argc = 1; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
538 } |
| 5372 | 539 av = PyList_New(argc); |
| 86 | 540 if (av != NULL) { |
| 541 int i; | |
| 542 for (i = 0; i < argc; i++) { | |
| 5372 | 543 PyObject *v = PyString_FromString(argv[i]); |
| 86 | 544 if (v == NULL) { |
| 5372 | 545 Py_DECREF(av); |
| 86 | 546 av = NULL; |
| 547 break; | |
| 548 } | |
| 5372 | 549 PyList_SetItem(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
|
550 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
551 } |
| 86 | 552 return av; |
| 6 | 553 } |
| 554 | |
| 555 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
556 PySys_SetArgv(int argc, char **argv) |
| 6 | 557 { |
| 5372 | 558 PyObject *av = makeargvobject(argc, argv); |
| 559 PyObject *path = PySys_GetObject("path"); | |
| 86 | 560 if (av == NULL) |
| 5372 | 561 Py_FatalError("no mem for sys.argv"); |
| 562 if (PySys_SetObject("argv", av) != 0) | |
| 563 Py_FatalError("can't assign sys.argv"); | |
|
3877
408e374934e5
Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents:
3806
diff
changeset
|
564 if (path != NULL) { |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
565 char *argv0 = argv[0]; |
|
3877
408e374934e5
Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents:
3806
diff
changeset
|
566 char *p = NULL; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
567 int n = 0; |
| 5372 | 568 PyObject *a; |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
569 #ifdef HAVE_READLINK |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
570 char link[MAXPATHLEN+1]; |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
571 char argv0copy[2*MAXPATHLEN+1]; |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
572 int nr = 0; |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
573 if (argc > 0 && argv0 != NULL) |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
574 nr = readlink(argv0, link, MAXPATHLEN); |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
575 if (nr > 0) { |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
576 /* It's a symlink */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
577 link[nr] = '\0'; |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
578 if (link[0] == SEP) |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
579 argv0 = link; /* Link to absolute path */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
580 else if (strchr(link, SEP) == NULL) |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
581 ; /* Link without path */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
582 else { |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
583 /* Must join(dirname(argv0), link) */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
584 char *q = strrchr(argv0, SEP); |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
585 if (q == NULL) |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
586 argv0 = link; /* argv0 without path */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
587 else { |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
588 /* Must make a copy */ |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
589 strcpy(argv0copy, argv0); |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
590 q = strrchr(argv0copy, SEP); |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
591 strcpy(q+1, link); |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
592 argv0 = argv0copy; |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
593 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
594 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
595 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
596 #endif /* HAVE_READLINK */ |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
597 #if SEP == '\\' /* Special case for MS filename syntax */ |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
598 if (argc > 0 && argv0 != NULL) { |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
599 char *q; |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
600 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
601 /* Test for alternate separator */ |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
602 q = strrchr(p ? p : argv0, '/'); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
603 if (q != NULL) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
604 p = q; |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
605 if (p != NULL) { |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
606 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
607 if (n > 1 && p[-1] != ':') |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
608 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
609 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
610 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
611 #else /* All other filename syntaxes */ |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
612 if (argc > 0 && argv0 != NULL) |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
613 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
614 if (p != NULL) { |
|
5340
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
615 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
616 #if SEP == '/' /* Special case for Unix filename syntax */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
617 if (n > 1) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
618 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
619 #endif /* Unix */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
620 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
621 #endif /* All others */ |
| 5372 | 622 a = PyString_FromStringAndSize(argv0, n); |
|
3877
408e374934e5
Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents:
3806
diff
changeset
|
623 if (a == NULL) |
| 5372 | 624 Py_FatalError("no mem for sys.path insertion"); |
| 625 if (PyList_Insert(path, 0, a) < 0) | |
| 626 Py_FatalError("sys.path.insert(0) failed"); | |
| 627 Py_DECREF(a); | |
|
3806
93868c7a15c9
As a side effect of calling PySys_SetArgv (setpythonargv), the
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
628 } |
| 5372 | 629 Py_DECREF(av); |
| 6 | 630 } |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
631 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
632 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
633 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface. |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
634 Adapted from code submitted by Just van Rossum. |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
635 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
636 PySys_WriteStdout(format, ...) |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
637 PySys_WriteStderr(format, ...) |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
638 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
639 The first function writes to sys.stdout; the second to sys.stderr. When |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
640 there is a problem, they write to the real (C level) stdout or stderr; |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
641 no exceptions are raised. |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
642 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
643 Both take a printf-style format string as their first argument followed |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
644 by a variable length argument list determined by the format string. |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
645 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
646 *** WARNING *** |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
647 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
648 The format should limit the total size of the formatted output string to |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
649 1000 bytes. In particular, this means that no unrestricted "%s" formats |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
650 should occur; these should be limited using "%.<N>s where <N> is a |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
651 decimal number calculated so that <N> plus the maximum size of other |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
652 formatted text does not exceed 1000 bytes. Also watch out for "%f", |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
653 which can print hundreds of digits for very large numbers. |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
654 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
655 */ |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
656 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
657 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
658 mywrite(char *name, FILE *fp, const char *format, va_list va) |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
659 { |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
660 PyObject *file; |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
661 PyObject *error_type, *error_value, *error_traceback; |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
662 |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
663 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
664 file = PySys_GetObject(name); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
665 if (file == NULL || PyFile_AsFile(file) == fp) |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
666 vfprintf(fp, format, va); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
667 else { |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
668 char buffer[1001]; |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
669 if (vsprintf(buffer, format, va) >= sizeof(buffer)) |
|
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
670 Py_FatalError("PySys_WriteStdout/err: buffer overrun"); |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
671 if (PyFile_WriteString(buffer, file) != 0) { |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
672 PyErr_Clear(); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
673 fputs(buffer, fp); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
674 } |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
675 } |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
676 PyErr_Restore(error_type, error_value, error_traceback); |
|
8314
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
677 } |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
678 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
679 void |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
680 PySys_WriteStdout(const char *format, ...) |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
681 { |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
682 va_list va; |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
683 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
684 va_start(va, format); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
685 mywrite("stdout", stdout, format, va); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
686 va_end(va); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
687 } |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
688 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
689 void |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
690 PySys_WriteStderr(const char *format, ...) |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
691 { |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
692 va_list va; |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
693 |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
694 va_start(va, format); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
695 mywrite("stderr", stderr, format, va); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
696 va_end(va); |
|
f94d5ae642a9
New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents:
7402
diff
changeset
|
697 } |
