Mercurial > cpython-lru_cache-weakref
annotate Python/sysmodule.c @ 15487:f0ca4c67957b legacy-trunk
_getframe(): New sys module function for getting at the stack frame.
Implements and closes SF patch #102106, with Guido's suggested
documentation changes.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Wed, 06 Dec 2000 21:47:46 +0000 |
| parents | 6f6f965c5e2d |
| children | 0f42f6669e80 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* System module */ |
| 3 | |
| 4 /* | |
| 5 Various bits of information used by the interpreter are collected in | |
| 6 module 'sys'. | |
| 86 | 7 Function member: |
|
2586
ae131b8b4e31
fix comment about exit()
Guido van Rossum <guido@python.org>
parents:
2421
diff
changeset
|
8 - exit(sts): raise SystemExit |
| 6 | 9 Data members: |
| 10 - stdin, stdout, stderr: standard file objects | |
| 86 | 11 - modules: the table of modules (dictionary) |
| 6 | 12 - path: module search path (list of strings) |
| 86 | 13 - argv: script arguments (list of strings) |
| 14 - ps1, ps2: optional primary and secondary prompts (strings) | |
| 6 | 15 */ |
| 16 | |
| 5372 | 17 #include "Python.h" |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
18 #include "compile.h" |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
19 #include "frameobject.h" |
| 86 | 20 |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
21 #include "osdefs.h" |
| 86 | 22 |
|
5550
43822e4fc27d
Use #ifdef in stead of #if (Jack)
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
23 #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
|
24 #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
|
25 #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
|
26 |
|
4291
1427d61f1307
Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents:
4256
diff
changeset
|
27 #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
|
28 extern void *PyWin_DLLhModule; |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
29 /* 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
|
30 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
|
31 #endif |
|
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
32 |
| 5372 | 33 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
34 PySys_GetObject(char *name) |
| 6 | 35 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
40 return PyDict_GetItemString(sd, name); |
| 6 | 41 } |
| 42 | |
| 43 FILE * | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
44 PySys_GetFile(char *name, FILE *def) |
| 6 | 45 { |
| 46 FILE *fp = NULL; | |
| 5372 | 47 PyObject *v = PySys_GetObject(name); |
| 48 if (v != NULL && PyFile_Check(v)) | |
| 49 fp = PyFile_AsFile(v); | |
| 6 | 50 if (fp == NULL) |
| 51 fp = def; | |
| 52 return fp; | |
| 53 } | |
| 54 | |
| 55 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
56 PySys_SetObject(char *name, PyObject *v) |
| 6 | 57 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 return 0; |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
63 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
64 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
|
65 } |
| 6 | 66 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
67 return PyDict_SetItemString(sd, name, v); |
| 6 | 68 } |
| 69 | |
| 5372 | 70 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
71 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
|
72 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
73 PyThreadState *tstate; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
74 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
|
75 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
76 tstate = PyThreadState_Get(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
77 return Py_BuildValue( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
78 "(OOO)", |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
79 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
|
80 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
|
81 tstate->exc_traceback != NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
82 tstate->exc_traceback : Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
83 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
84 |
|
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
|
85 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
|
86 "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
|
87 \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
|
88 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
|
89 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
|
90 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
91 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
92 sys_exit(PyObject *self, PyObject *args) |
| 6 | 93 { |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
94 /* Raise SystemExit so callers may catch it or clean up. */ |
| 5372 | 95 PyErr_SetObject(PyExc_SystemExit, args); |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
96 return NULL; |
| 6 | 97 } |
| 98 | |
|
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
|
99 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
|
100 "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
|
101 \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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 |
| 5372 | 108 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
109 sys_getdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
110 { |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
111 if (!PyArg_ParseTuple(args, ":getdefaultencoding")) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
112 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
113 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
114 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
115 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
116 static char getdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
117 "getdefaultencoding() -> string\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
118 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
119 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
|
120 implementation."; |
|
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 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
123 sys_setdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
124 { |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
125 char *encoding; |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
126 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding)) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
127 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
128 if (PyUnicode_SetDefaultEncoding(encoding)) |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
129 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
130 Py_INCREF(Py_None); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
131 return Py_None; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
132 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
133 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
134 static char setdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
135 "setdefaultencoding(encoding)\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
136 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
137 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
|
138 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
139 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
140 sys_settrace(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
141 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
142 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 143 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
144 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
145 else |
| 5372 | 146 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
147 Py_XDECREF(tstate->sys_tracefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
148 tstate->sys_tracefunc = args; |
| 5372 | 149 Py_INCREF(Py_None); |
| 150 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
151 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
152 |
|
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
|
153 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
|
154 "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
|
155 \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
|
156 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
|
157 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
|
158 |
| 5372 | 159 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
160 sys_setprofile(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
161 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
162 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 163 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
164 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
165 else |
| 5372 | 166 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
167 Py_XDECREF(tstate->sys_profilefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
168 tstate->sys_profilefunc = args; |
| 5372 | 169 Py_INCREF(Py_None); |
| 170 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
171 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
172 |
|
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
|
173 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
|
174 "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
|
175 \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
|
176 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
|
177 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
|
178 |
| 5372 | 179 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
180 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
|
181 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
182 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
|
183 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
|
184 return NULL; |
| 5372 | 185 Py_INCREF(Py_None); |
| 186 return Py_None; | |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
187 } |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
188 |
|
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
|
189 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
|
190 "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
|
191 \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
|
192 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
|
193 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
|
194 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
195 static PyObject * |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
196 sys_setrecursionlimit(PyObject *self, PyObject *args) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
197 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
198 int new_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
199 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit)) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
200 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
201 if (new_limit <= 0) { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
202 PyErr_SetString(PyExc_ValueError, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
203 "recursion limit must be positive"); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
204 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
205 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
206 Py_SetRecursionLimit(new_limit); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
207 Py_INCREF(Py_None); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
208 return Py_None; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
209 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
210 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
211 static char setrecursionlimit_doc[] = |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
212 "setrecursionlimit(n)\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
213 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
214 Set the maximum depth of the Python interpreter stack to n. This\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
215 limit prevents infinite recursion from causing an overflow of the C\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
216 stack and crashing Python. The highest possible limit is platform-\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
217 dependent."; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
218 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
219 static PyObject * |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
220 sys_getrecursionlimit(PyObject *self, PyObject *args) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
221 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
222 if (!PyArg_ParseTuple(args, ":getrecursionlimit")) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
223 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
224 return PyInt_FromLong(Py_GetRecursionLimit()); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
225 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
226 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
227 static char getrecursionlimit_doc[] = |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
228 "getrecursionlimit()\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
229 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
230 Return the current value of the recursion limit, the maximum depth\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
231 of the Python interpreter stack. This limit prevents infinite\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
232 recursion from causing an overflow of the C stack and crashing Python."; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
233 |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
234 #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
|
235 /* 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
|
236 #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
|
237 |
| 5372 | 238 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
239 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
|
240 { |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
241 int flag; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
242 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
|
243 return NULL; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
244 mallopt(M_DEBUG, flag); |
| 5372 | 245 Py_INCREF(Py_None); |
| 246 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
|
247 } |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
248 #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
|
249 |
| 5372 | 250 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
251 sys_getrefcount(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
252 { |
| 5372 | 253 PyObject *arg; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
254 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
255 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
|
256 return PyInt_FromLong(arg->ob_refcnt); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
257 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
258 |
|
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
|
259 #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
|
260 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
|
261 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
|
262 { |
|
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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 } |
|
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
|
268 |
|
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
|
269 #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
|
270 |
|
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
|
271 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
|
272 "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
|
273 \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
|
274 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
|
275 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
|
276 |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
277 #ifdef COUNT_ALLOCS |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
278 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
279 sys_getcounts(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
280 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
281 extern PyObject *get_counts(void); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
282 |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
283 if (!PyArg_ParseTuple(args, ":getcounts")) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
284 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
285 return get_counts(); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
286 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
287 #endif |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
288 |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
289 static char getframe_doc[] = |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
290 "_getframe([depth]) -> frameobject\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
291 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
292 Return a frame object from the call stack. If optional integer depth is\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
293 given, return the frame object that many calls below the top of the stack.\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
294 If that is deeper than the call stack, ValueError is raised. The default\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
295 for depth is zero, returning the frame at the top of the call stack.\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
296 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
297 This function should be used for internal and specialized\n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
298 purposes only."; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
299 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
300 static PyObject * |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
301 sys_getframe(PyObject *self, PyObject *args) |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
302 { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
303 PyFrameObject *f = PyThreadState_Get()->frame; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
304 int depth = -1; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
305 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
306 if (!PyArg_ParseTuple(args, "|i:_getframe", &depth)) |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
307 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
308 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
309 while (depth > 0 && f != NULL) { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
310 f = f->f_back; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
311 --depth; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
312 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
313 if (f == NULL) { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
314 PyErr_SetString(PyExc_ValueError, |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
315 "call stack is not deep enough"); |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
316 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
317 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
318 Py_INCREF(f); |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
319 return (PyObject*)f; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
320 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
321 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
322 |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
323 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
324 /* 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
|
325 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
326 #endif |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
327 |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
328 #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
|
329 /* 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
|
330 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
|
331 #endif |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
332 |
| 5372 | 333 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
|
334 /* 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
|
335 {"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
|
336 {"exit", sys_exit, 0, exit_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
337 {"getdefaultencoding", sys_getdefaultencoding, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
338 getdefaultencoding_doc}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
339 #ifdef COUNT_ALLOCS |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
340 {"getcounts", sys_getcounts, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
341 #endif |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
342 #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
|
343 {"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
|
344 #endif |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
345 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
346 {"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
|
347 {"gettotalrefcount", sys_gettotalrefcount, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
348 #endif |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
349 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
350 {"getrecursionlimit", sys_getrecursionlimit, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
351 getrecursionlimit_doc}, |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
352 {"_getframe", sys_getframe, 1, getframe_doc}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
353 #ifdef USE_MALLOPT |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
354 {"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
|
355 #endif |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
356 {"setdefaultencoding", sys_setdefaultencoding, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
357 setdefaultencoding_doc}, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
358 {"setcheckinterval", sys_setcheckinterval, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
359 setcheckinterval_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
|
360 {"setprofile", sys_setprofile, 0, setprofile_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
361 {"setrecursionlimit", sys_setrecursionlimit, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
362 setrecursionlimit_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
|
363 {"settrace", sys_settrace, 0, settrace_doc}, |
| 86 | 364 {NULL, NULL} /* sentinel */ |
| 365 }; | |
| 366 | |
| 5372 | 367 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
368 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
|
369 { |
| 5372 | 370 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
|
371 int i; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
372 if (list == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
373 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
|
374 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
|
375 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
|
376 PyImport_Inittab[i].name); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
377 if (name == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
378 break; |
| 5372 | 379 PyList_Append(list, name); |
| 380 Py_DECREF(name); | |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
381 } |
| 5372 | 382 if (PyList_Sort(list) != 0) { |
| 383 Py_DECREF(list); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
384 list = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
385 } |
|
4904
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
386 if (list) { |
| 5372 | 387 PyObject *v = PyList_AsTuple(list); |
| 388 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
|
389 list = v; |
|
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
390 } |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
391 return list; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
392 } |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
393 |
|
8840
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
394 /* 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 "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
|
400 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
|
401 \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
|
402 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
|
403 \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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 \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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 \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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 \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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 " |
|
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
|
427 #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
|
428 /* 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
|
429 "\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
|
430 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
|
431 \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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 __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
|
445 __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
|
446 __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
|
447 \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
|
448 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
|
449 \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
|
450 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
|
451 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
|
452 getrefcount() -- return the reference count for an object (plus one :-)\n\ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
453 getrecursionlimit() -- return the max recursion depth for the interpreter\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
|
454 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
|
455 setprofile() -- set the global profiling function\n\ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
456 setrecursionlimit() -- set the max recursion depth for the interpreter\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
|
457 settrace() -- set the global debug tracing function\n\ |
|
13971
aa4202702252
The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents:
13968
diff
changeset
|
458 " |
|
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
|
459 #endif |
|
13971
aa4202702252
The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents:
13968
diff
changeset
|
460 /* end of sys_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
|
461 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
462 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
463 _PySys_Init(void) |
| 6 | 464 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
465 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
|
466 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
|
467 char *s; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
468 |
|
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
|
469 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 5372 | 470 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
|
471 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
472 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
|
473 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
|
474 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); |
| 5372 | 475 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
|
476 return NULL; |
| 5372 | 477 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 478 PyDict_SetItemString(sysdict, "stdout", sysout); | |
| 479 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
|
480 /* 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
|
481 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
|
482 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
|
483 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
|
484 Py_XDECREF(sysin); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
485 Py_XDECREF(sysout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
486 Py_XDECREF(syserr); |
| 5372 | 487 PyDict_SetItemString(sysdict, "version", |
| 488 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
|
489 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
|
490 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
|
491 v = PyInt_FromLong(PY_VERSION_HEX)); |
| 5372 | 492 Py_XDECREF(v); |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
493 /* |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
494 * 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
|
495 * 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
|
496 */ |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
497 #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
|
498 s = "alpha"; |
|
14295
e5253b692e9f
_PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents:
14017
diff
changeset
|
499 #elif 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
|
500 s = "beta"; |
|
14295
e5253b692e9f
_PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents:
14017
diff
changeset
|
501 #elif 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
|
502 s = "candidate"; |
|
14295
e5253b692e9f
_PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents:
14017
diff
changeset
|
503 #elif 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
|
504 s = "final"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
505 #endif |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
506 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
|
507 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
|
508 PY_MINOR_VERSION, |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
509 PY_MICRO_VERSION, s, |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
510 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
|
511 Py_XDECREF(v); |
| 5372 | 512 PyDict_SetItemString(sysdict, "copyright", |
| 513 v = PyString_FromString(Py_GetCopyright())); | |
| 514 Py_XDECREF(v); | |
| 515 PyDict_SetItemString(sysdict, "platform", | |
| 516 v = PyString_FromString(Py_GetPlatform())); | |
| 517 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
|
518 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
|
519 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
|
520 Py_XDECREF(v); |
| 5372 | 521 PyDict_SetItemString(sysdict, "prefix", |
| 522 v = PyString_FromString(Py_GetPrefix())); | |
| 523 Py_XDECREF(v); | |
| 524 PyDict_SetItemString(sysdict, "exec_prefix", | |
| 525 v = PyString_FromString(Py_GetExecPrefix())); | |
| 526 Py_XDECREF(v); | |
| 527 PyDict_SetItemString(sysdict, "maxint", | |
| 528 v = PyInt_FromLong(PyInt_GetMax())); | |
| 529 Py_XDECREF(v); | |
| 530 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
|
531 v = list_builtin_module_names()); |
| 5372 | 532 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
|
533 { |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
534 /* 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
|
535 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
|
536 unsigned long number = 1; |
|
13977
eb9a36163a9e
Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents:
13971
diff
changeset
|
537 char *value; |
|
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
|
538 |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
539 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
|
540 if (s[0] == 0) |
|
13977
eb9a36163a9e
Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents:
13971
diff
changeset
|
541 value = "big"; |
|
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
|
542 else |
|
13977
eb9a36163a9e
Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents:
13971
diff
changeset
|
543 value = "little"; |
|
eb9a36163a9e
Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents:
13971
diff
changeset
|
544 PyDict_SetItemString(sysdict, "byteorder", |
|
14017
128f641191c3
_PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents:
13977
diff
changeset
|
545 v = PyString_FromString(value)); |
|
128f641191c3
_PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents:
13977
diff
changeset
|
546 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
|
547 } |
|
4126
c80c515999b9
Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents:
3877
diff
changeset
|
548 #ifdef MS_COREDLL |
| 5372 | 549 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
|
550 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 5372 | 551 Py_XDECREF(v); |
| 552 PyDict_SetItemString(sysdict, "winver", | |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
553 v = PyString_FromString(PyWin_DLLVersionString)); |
| 5372 | 554 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
|
555 #endif |
| 5372 | 556 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
|
557 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
558 return m; |
| 86 | 559 } |
| 560 | |
| 5372 | 561 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
562 makepathobject(char *path, int delim) |
| 86 | 563 { |
| 564 int i, n; | |
| 565 char *p; | |
| 5372 | 566 PyObject *v, *w; |
| 6 | 567 |
| 86 | 568 n = 1; |
| 569 p = path; | |
| 570 while ((p = strchr(p, delim)) != NULL) { | |
| 571 n++; | |
| 572 p++; | |
| 573 } | |
| 5372 | 574 v = PyList_New(n); |
| 86 | 575 if (v == NULL) |
| 576 return NULL; | |
| 577 for (i = 0; ; i++) { | |
| 578 p = strchr(path, delim); | |
| 579 if (p == NULL) | |
| 580 p = strchr(path, '\0'); /* End of string */ | |
| 5372 | 581 w = PyString_FromStringAndSize(path, (int) (p - path)); |
| 86 | 582 if (w == NULL) { |
| 5372 | 583 Py_DECREF(v); |
| 86 | 584 return NULL; |
| 585 } | |
| 5372 | 586 PyList_SetItem(v, i, w); |
| 86 | 587 if (*p == '\0') |
| 588 break; | |
| 589 path = p+1; | |
| 590 } | |
| 591 return v; | |
| 592 } | |
| 593 | |
| 594 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
595 PySys_SetPath(char *path) |
| 86 | 596 { |
| 5372 | 597 PyObject *v; |
| 86 | 598 if ((v = makepathobject(path, DELIM)) == NULL) |
| 5372 | 599 Py_FatalError("can't create sys.path"); |
| 600 if (PySys_SetObject("path", v) != 0) | |
| 601 Py_FatalError("can't assign sys.path"); | |
| 602 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
|
603 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
604 |
| 5372 | 605 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
606 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
|
607 { |
| 5372 | 608 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
|
609 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
|
610 /* 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
|
611 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
|
612 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
|
613 argc = 1; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
614 } |
| 5372 | 615 av = PyList_New(argc); |
| 86 | 616 if (av != NULL) { |
| 617 int i; | |
| 618 for (i = 0; i < argc; i++) { | |
| 5372 | 619 PyObject *v = PyString_FromString(argv[i]); |
| 86 | 620 if (v == NULL) { |
| 5372 | 621 Py_DECREF(av); |
| 86 | 622 av = NULL; |
| 623 break; | |
| 624 } | |
| 5372 | 625 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
|
626 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
627 } |
| 86 | 628 return av; |
| 6 | 629 } |
| 630 | |
| 631 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
632 PySys_SetArgv(int argc, char **argv) |
| 6 | 633 { |
| 5372 | 634 PyObject *av = makeargvobject(argc, argv); |
| 635 PyObject *path = PySys_GetObject("path"); | |
| 86 | 636 if (av == NULL) |
| 5372 | 637 Py_FatalError("no mem for sys.argv"); |
| 638 if (PySys_SetObject("argv", av) != 0) | |
| 639 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
|
640 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
|
641 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
|
642 char *p = NULL; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
643 int n = 0; |
| 5372 | 644 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
|
645 #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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 /* 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
|
653 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
|
654 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
|
655 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
|
656 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
|
657 ; /* 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
|
658 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
|
659 /* 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 /* 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
670 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
671 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
672 #endif /* HAVE_READLINK */ |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
673 #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
|
674 if (argc > 0 && argv0 != NULL) { |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
675 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
|
676 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
677 /* 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
|
678 q = strrchr(p ? p : argv0, '/'); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
679 if (q != NULL) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
680 p = q; |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
681 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
|
682 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
683 if (n > 1 && p[-1] != ':') |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
684 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
685 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
686 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
687 #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
|
688 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
|
689 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
690 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
|
691 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
692 #if SEP == '/' /* Special case for Unix filename syntax */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
693 if (n > 1) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
694 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
695 #endif /* Unix */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
696 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
697 #endif /* All others */ |
| 5372 | 698 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
|
699 if (a == NULL) |
| 5372 | 700 Py_FatalError("no mem for sys.path insertion"); |
| 701 if (PyList_Insert(path, 0, a) < 0) | |
| 702 Py_FatalError("sys.path.insert(0) failed"); | |
| 703 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
|
704 } |
| 5372 | 705 Py_DECREF(av); |
| 6 | 706 } |
|
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
|
707 |
|
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
|
708 |
|
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
|
709 /* 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
|
710 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
|
711 |
|
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
|
712 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
|
713 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
|
714 |
|
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
|
715 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
|
716 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
|
717 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
|
718 |
|
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
|
719 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
|
720 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
|
721 |
|
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
|
722 *** 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
|
723 |
|
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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 |
|
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
|
731 */ |
|
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
|
732 |
|
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
|
733 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
734 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
|
735 { |
|
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
|
736 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
|
737 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
|
738 |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 } |
|
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
|
751 } |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
752 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
|
753 } |
|
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
|
754 |
|
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
|
755 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
|
756 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
|
757 { |
|
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
|
758 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
|
759 |
|
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
|
760 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
|
761 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
|
762 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
|
763 } |
|
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
|
764 |
|
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
|
765 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
|
766 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
|
767 { |
|
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
|
768 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
|
769 |
|
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
|
770 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
|
771 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
|
772 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
|
773 } |
