Mercurial > cpython-lru_cache-weakref
annotate Python/sysmodule.c @ 15846:d41f9b0a40ca legacy-trunk
Neil discovered a bad DECREF on warnoptions, that caused repeated
re-initializing Python (Py_Finalize() followed by Py_Initialize()) to
blow up quickly. With the DECREF removed I can't get it to fail any
more. (Except it still leaks, but that's probably a separate issue.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 13 Jan 2001 22:06:05 +0000 |
| parents | a563eec46c1a |
| children | b44e77a12978 |
| 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 * |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
71 sys_displayhook(PyObject *self, PyObject *args) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
72 { |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
73 PyObject *o, *outf; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
74 PyInterpreterState *interp = PyThreadState_Get()->interp; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
75 PyObject *modules = interp->modules; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
76 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
77 |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
78 /* parse arguments */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
79 if (!PyArg_ParseTuple(args, "O:displayhook", &o)) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
80 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
81 |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
82 /* Print value except if None */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
83 /* After printing, also assign to '_' */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
84 /* Before, set '_' to None to avoid recursion */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
85 if (o == Py_None) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
86 Py_INCREF(Py_None); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
87 return Py_None; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
88 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
89 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
90 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
91 if (Py_FlushLine() != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
92 return NULL; |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
93 outf = PySys_GetObject("stdout"); |
|
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
94 if (outf == NULL) { |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
95 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
96 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
97 } |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
98 if (PyFile_WriteObject(o, outf, 0) != 0) |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
99 return NULL; |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
100 PyFile_SoftSpace(outf, 1); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
101 if (Py_FlushLine() != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
102 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
103 if (PyObject_SetAttrString(builtins, "_", o) != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
104 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
105 Py_INCREF(Py_None); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
106 return Py_None; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
107 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
108 |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
109 static char displayhook_doc[] = |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
110 "displayhook(o) -> None\n" |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
111 "\n" |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
112 "Print o to the stdout, and save it in __builtin__._\n"; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
113 |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
114 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
115 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
|
116 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
117 PyThreadState *tstate; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
118 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
|
119 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
120 tstate = PyThreadState_Get(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
121 return Py_BuildValue( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
122 "(OOO)", |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
123 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
|
124 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
|
125 tstate->exc_traceback != NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
126 tstate->exc_traceback : Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
127 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
128 |
|
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
|
129 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
|
130 "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
|
131 \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
|
132 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
|
133 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
|
134 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
135 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
136 sys_exit(PyObject *self, PyObject *args) |
| 6 | 137 { |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
138 /* Raise SystemExit so callers may catch it or clean up. */ |
| 5372 | 139 PyErr_SetObject(PyExc_SystemExit, args); |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
140 return NULL; |
| 6 | 141 } |
| 142 | |
|
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
|
143 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
|
144 "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
|
145 \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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 |
| 5372 | 152 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
153 sys_getdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
154 { |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
155 if (!PyArg_ParseTuple(args, ":getdefaultencoding")) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
156 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
157 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
158 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
159 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
160 static char getdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
161 "getdefaultencoding() -> string\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
162 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
163 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
|
164 implementation."; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
165 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
166 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
167 sys_setdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
168 { |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
169 char *encoding; |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
170 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding)) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
171 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
172 if (PyUnicode_SetDefaultEncoding(encoding)) |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
173 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
174 Py_INCREF(Py_None); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
175 return Py_None; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
176 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
177 |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
178 static char setdefaultencoding_doc[] = |
|
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
179 "setdefaultencoding(encoding)\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
180 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
181 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
|
182 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
183 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
184 sys_settrace(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
185 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
186 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 187 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
188 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
189 else |
| 5372 | 190 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
191 Py_XDECREF(tstate->sys_tracefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
192 tstate->sys_tracefunc = args; |
| 5372 | 193 Py_INCREF(Py_None); |
| 194 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
195 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
196 |
|
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
|
197 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
|
198 "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
|
199 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
200 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
|
201 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
|
202 |
| 5372 | 203 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
204 sys_setprofile(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
205 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
206 PyThreadState *tstate = PyThreadState_Get(); |
| 5372 | 207 if (args == Py_None) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
208 args = NULL; |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
209 else |
| 5372 | 210 Py_XINCREF(args); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
211 Py_XDECREF(tstate->sys_profilefunc); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
212 tstate->sys_profilefunc = args; |
| 5372 | 213 Py_INCREF(Py_None); |
| 214 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
215 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
216 |
|
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
|
217 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
|
218 "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
|
219 \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
|
220 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
|
221 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
|
222 |
| 5372 | 223 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
224 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
|
225 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
226 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
|
227 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
|
228 return NULL; |
| 5372 | 229 Py_INCREF(Py_None); |
| 230 return Py_None; | |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
231 } |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
232 |
|
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
|
233 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
|
234 "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
|
235 \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
|
236 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
|
237 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
|
238 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
239 static PyObject * |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
240 sys_setrecursionlimit(PyObject *self, PyObject *args) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
241 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
242 int new_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
243 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit)) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
244 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
245 if (new_limit <= 0) { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
246 PyErr_SetString(PyExc_ValueError, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
247 "recursion limit must be positive"); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
248 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
249 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
250 Py_SetRecursionLimit(new_limit); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
251 Py_INCREF(Py_None); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
252 return Py_None; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
253 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
254 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
255 static char setrecursionlimit_doc[] = |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
256 "setrecursionlimit(n)\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
257 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 dependent."; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
262 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
263 static PyObject * |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
264 sys_getrecursionlimit(PyObject *self, PyObject *args) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
265 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
266 if (!PyArg_ParseTuple(args, ":getrecursionlimit")) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
267 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
268 return PyInt_FromLong(Py_GetRecursionLimit()); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
269 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
270 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
271 static char getrecursionlimit_doc[] = |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
272 "getrecursionlimit()\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
273 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
278 #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
|
279 /* 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
|
280 #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
|
281 |
| 5372 | 282 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
283 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
|
284 { |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
285 int flag; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
286 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
|
287 return NULL; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
288 mallopt(M_DEBUG, flag); |
| 5372 | 289 Py_INCREF(Py_None); |
| 290 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
|
291 } |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
292 #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
|
293 |
| 5372 | 294 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
295 sys_getrefcount(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
296 { |
| 5372 | 297 PyObject *arg; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
298 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
299 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
|
300 return PyInt_FromLong(arg->ob_refcnt); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
301 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
302 |
|
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
|
303 #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
|
304 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
|
305 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
|
306 { |
|
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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 } |
|
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
|
312 |
|
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
|
313 #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
|
314 |
|
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
|
315 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
|
316 "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
|
317 \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
|
318 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
|
319 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
|
320 |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
321 #ifdef COUNT_ALLOCS |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
322 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
323 sys_getcounts(PyObject *self, PyObject *args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
324 { |
|
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 *get_counts(void); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
326 |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
327 if (!PyArg_ParseTuple(args, ":getcounts")) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
328 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
329 return get_counts(); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
330 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
331 #endif |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
332 |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
333 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
|
334 "_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
|
335 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 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
|
340 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
341 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
|
342 purposes only."; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
343 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
344 static PyObject * |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
345 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
|
346 { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
347 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
|
348 int depth = -1; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
349 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
350 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
|
351 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
352 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
353 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
|
354 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
|
355 --depth; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
356 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
357 if (f == NULL) { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
358 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
|
359 "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
|
360 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
361 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
362 Py_INCREF(f); |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
363 return (PyObject*)f; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
364 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
365 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
366 |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
367 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
368 /* 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
|
369 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
370 #endif |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
371 |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
372 #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
|
373 /* 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
|
374 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
|
375 #endif |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
376 |
| 5372 | 377 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
|
378 /* Might as well keep this in alphabetic order */ |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
379 {"displayhook", sys_displayhook, 1, displayhook_doc}, |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
380 {"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
|
381 {"exit", sys_exit, 0, exit_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
382 {"getdefaultencoding", sys_getdefaultencoding, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
383 getdefaultencoding_doc}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
384 #ifdef COUNT_ALLOCS |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
385 {"getcounts", sys_getcounts, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
386 #endif |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
387 #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
|
388 {"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
|
389 #endif |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
390 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
391 {"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
|
392 {"gettotalrefcount", sys_gettotalrefcount, 1}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
393 #endif |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
394 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
395 {"getrecursionlimit", sys_getrecursionlimit, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
396 getrecursionlimit_doc}, |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
397 {"_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
|
398 #ifdef USE_MALLOPT |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
399 {"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
|
400 #endif |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
401 {"setdefaultencoding", sys_setdefaultencoding, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
402 setdefaultencoding_doc}, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
403 {"setcheckinterval", sys_setcheckinterval, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
404 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
|
405 {"setprofile", sys_setprofile, 0, setprofile_doc}, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
406 {"setrecursionlimit", sys_setrecursionlimit, 1, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
407 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
|
408 {"settrace", sys_settrace, 0, settrace_doc}, |
| 86 | 409 {NULL, NULL} /* sentinel */ |
| 410 }; | |
| 411 | |
| 5372 | 412 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
413 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
|
414 { |
| 5372 | 415 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
|
416 int i; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
417 if (list == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 PyImport_Inittab[i].name); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
422 if (name == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
423 break; |
| 5372 | 424 PyList_Append(list, name); |
| 425 Py_DECREF(name); | |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
426 } |
| 5372 | 427 if (PyList_Sort(list) != 0) { |
| 428 Py_DECREF(list); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
429 list = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
430 } |
|
4904
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
431 if (list) { |
| 5372 | 432 PyObject *v = PyList_AsTuple(list); |
| 433 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
|
434 list = v; |
|
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
435 } |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
436 return list; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
437 } |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
438 |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
439 static PyObject *warnoptions = NULL; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
440 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
441 void |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
442 PySys_ResetWarnOptions(void) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
443 { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
444 if (warnoptions == NULL || !PyList_Check(warnoptions)) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
445 return; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
446 PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
447 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
448 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
449 void |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
450 PySys_AddWarnOption(char *s) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
451 { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
452 PyObject *str; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
453 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
454 if (warnoptions == NULL || !PyList_Check(warnoptions)) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
455 Py_XDECREF(warnoptions); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
456 warnoptions = PyList_New(0); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
457 if (warnoptions == NULL) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
458 return; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
459 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
460 str = PyString_FromString(s); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
461 if (str != NULL) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
462 PyList_Append(warnoptions, str); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
463 Py_DECREF(str); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
464 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
465 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
466 |
|
8840
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
467 /* 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 "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
|
473 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
|
474 \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
|
475 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
|
476 \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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 \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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 \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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 \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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 " |
|
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
|
500 #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
|
501 /* 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
|
502 "\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
|
503 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
|
504 \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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 __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
|
518 __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
|
519 __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
|
520 \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
|
521 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
|
522 \n\ |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
523 displayhook() -- print an object to the screen, and save it in __builtin__._\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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 setprofile() -- set the global profiling function\n\ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
530 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
|
531 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
|
532 " |
|
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
|
533 #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
|
534 /* 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
|
535 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
536 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
537 _PySys_Init(void) |
| 6 | 538 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
539 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
|
540 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
|
541 char *s; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
542 |
|
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
|
543 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 5372 | 544 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
|
545 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
546 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
|
547 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
|
548 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); |
| 5372 | 549 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
|
550 return NULL; |
| 5372 | 551 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 552 PyDict_SetItemString(sysdict, "stdout", sysout); | |
| 553 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
|
554 /* 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
|
555 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
|
556 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
|
557 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
|
558 Py_XDECREF(sysin); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
559 Py_XDECREF(sysout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
560 Py_XDECREF(syserr); |
| 5372 | 561 PyDict_SetItemString(sysdict, "version", |
| 562 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
|
563 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
|
564 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
|
565 v = PyInt_FromLong(PY_VERSION_HEX)); |
| 5372 | 566 Py_XDECREF(v); |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
567 /* |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
568 * 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
|
569 * 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
|
570 */ |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
571 #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
|
572 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
|
573 #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
|
574 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
|
575 #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
|
576 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
|
577 #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
|
578 s = "final"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
579 #endif |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
580 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
|
581 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
|
582 PY_MINOR_VERSION, |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
583 PY_MICRO_VERSION, s, |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
584 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
|
585 Py_XDECREF(v); |
| 5372 | 586 PyDict_SetItemString(sysdict, "copyright", |
| 587 v = PyString_FromString(Py_GetCopyright())); | |
| 588 Py_XDECREF(v); | |
| 589 PyDict_SetItemString(sysdict, "platform", | |
| 590 v = PyString_FromString(Py_GetPlatform())); | |
| 591 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
|
592 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
|
593 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
|
594 Py_XDECREF(v); |
| 5372 | 595 PyDict_SetItemString(sysdict, "prefix", |
| 596 v = PyString_FromString(Py_GetPrefix())); | |
| 597 Py_XDECREF(v); | |
| 598 PyDict_SetItemString(sysdict, "exec_prefix", | |
| 599 v = PyString_FromString(Py_GetExecPrefix())); | |
| 600 Py_XDECREF(v); | |
| 601 PyDict_SetItemString(sysdict, "maxint", | |
| 602 v = PyInt_FromLong(PyInt_GetMax())); | |
| 603 Py_XDECREF(v); | |
| 604 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
|
605 v = list_builtin_module_names()); |
| 5372 | 606 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
|
607 { |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
608 /* 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
|
609 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
|
610 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
|
611 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
|
612 |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 v = PyString_FromString(value)); |
|
128f641191c3
_PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents:
13977
diff
changeset
|
620 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
|
621 } |
|
4126
c80c515999b9
Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents:
3877
diff
changeset
|
622 #ifdef MS_COREDLL |
| 5372 | 623 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
|
624 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 5372 | 625 Py_XDECREF(v); |
| 626 PyDict_SetItemString(sysdict, "winver", | |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
627 v = PyString_FromString(PyWin_DLLVersionString)); |
| 5372 | 628 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
|
629 #endif |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
630 if (warnoptions == NULL) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
631 warnoptions = PyList_New(0); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
632 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
633 else { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
634 Py_INCREF(warnoptions); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
635 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
636 if (warnoptions != NULL) { |
|
15846
d41f9b0a40ca
Neil discovered a bad DECREF on warnoptions, that caused repeated
Guido van Rossum <guido@python.org>
parents:
15812
diff
changeset
|
637 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
638 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
639 |
| 5372 | 640 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
|
641 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
642 return m; |
| 86 | 643 } |
| 644 | |
| 5372 | 645 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
646 makepathobject(char *path, int delim) |
| 86 | 647 { |
| 648 int i, n; | |
| 649 char *p; | |
| 5372 | 650 PyObject *v, *w; |
| 6 | 651 |
| 86 | 652 n = 1; |
| 653 p = path; | |
| 654 while ((p = strchr(p, delim)) != NULL) { | |
| 655 n++; | |
| 656 p++; | |
| 657 } | |
| 5372 | 658 v = PyList_New(n); |
| 86 | 659 if (v == NULL) |
| 660 return NULL; | |
| 661 for (i = 0; ; i++) { | |
| 662 p = strchr(path, delim); | |
| 663 if (p == NULL) | |
| 664 p = strchr(path, '\0'); /* End of string */ | |
| 5372 | 665 w = PyString_FromStringAndSize(path, (int) (p - path)); |
| 86 | 666 if (w == NULL) { |
| 5372 | 667 Py_DECREF(v); |
| 86 | 668 return NULL; |
| 669 } | |
| 5372 | 670 PyList_SetItem(v, i, w); |
| 86 | 671 if (*p == '\0') |
| 672 break; | |
| 673 path = p+1; | |
| 674 } | |
| 675 return v; | |
| 676 } | |
| 677 | |
| 678 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
679 PySys_SetPath(char *path) |
| 86 | 680 { |
| 5372 | 681 PyObject *v; |
| 86 | 682 if ((v = makepathobject(path, DELIM)) == NULL) |
| 5372 | 683 Py_FatalError("can't create sys.path"); |
| 684 if (PySys_SetObject("path", v) != 0) | |
| 685 Py_FatalError("can't assign sys.path"); | |
| 686 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
|
687 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
688 |
| 5372 | 689 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
690 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
|
691 { |
| 5372 | 692 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
|
693 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
|
694 /* 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
|
695 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
|
696 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
|
697 argc = 1; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
698 } |
| 5372 | 699 av = PyList_New(argc); |
| 86 | 700 if (av != NULL) { |
| 701 int i; | |
| 702 for (i = 0; i < argc; i++) { | |
| 5372 | 703 PyObject *v = PyString_FromString(argv[i]); |
| 86 | 704 if (v == NULL) { |
| 5372 | 705 Py_DECREF(av); |
| 86 | 706 av = NULL; |
| 707 break; | |
| 708 } | |
| 5372 | 709 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
|
710 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
711 } |
| 86 | 712 return av; |
| 6 | 713 } |
| 714 | |
| 715 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
716 PySys_SetArgv(int argc, char **argv) |
| 6 | 717 { |
| 5372 | 718 PyObject *av = makeargvobject(argc, argv); |
| 719 PyObject *path = PySys_GetObject("path"); | |
| 86 | 720 if (av == NULL) |
| 5372 | 721 Py_FatalError("no mem for sys.argv"); |
| 722 if (PySys_SetObject("argv", av) != 0) | |
| 723 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
|
724 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
|
725 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
|
726 char *p = NULL; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
727 int n = 0; |
| 5372 | 728 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
|
729 #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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 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
|
735 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
|
736 /* 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 ; /* 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
|
742 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
|
743 /* 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 /* 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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
754 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
755 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
756 #endif /* HAVE_READLINK */ |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
757 #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
|
758 if (argc > 0 && argv0 != NULL) { |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
759 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
|
760 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
761 /* 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
|
762 q = strrchr(p ? p : argv0, '/'); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
763 if (q != NULL) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
764 p = q; |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
765 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
|
766 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
767 if (n > 1 && p[-1] != ':') |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
768 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
769 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
770 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
771 #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
|
772 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
|
773 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
774 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
|
775 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
776 #if SEP == '/' /* Special case for Unix filename syntax */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
777 if (n > 1) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
778 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
779 #endif /* Unix */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
780 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
781 #endif /* All others */ |
| 5372 | 782 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
|
783 if (a == NULL) |
| 5372 | 784 Py_FatalError("no mem for sys.path insertion"); |
| 785 if (PyList_Insert(path, 0, a) < 0) | |
| 786 Py_FatalError("sys.path.insert(0) failed"); | |
| 787 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
|
788 } |
| 5372 | 789 Py_DECREF(av); |
| 6 | 790 } |
|
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
|
791 |
|
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
|
792 |
|
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
|
793 /* 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
|
794 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
|
795 |
|
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
|
796 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
|
797 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
|
798 |
|
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
|
799 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
|
800 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
|
801 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
|
802 |
|
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
|
803 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
|
804 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
|
805 |
|
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
|
806 *** 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
|
807 |
|
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
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 |
|
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
|
815 */ |
|
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
|
816 |
|
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
|
817 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
818 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
|
819 { |
|
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
|
820 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
|
821 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
|
822 |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 } |
|
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
|
835 } |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
836 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
|
837 } |
|
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
|
838 |
|
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
|
839 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
|
840 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
|
841 { |
|
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
|
842 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
|
843 |
|
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
|
844 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
|
845 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
|
846 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
|
847 } |
|
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
|
848 |
|
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
|
849 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
|
850 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
|
851 { |
|
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
|
852 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
|
853 |
|
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
|
854 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
|
855 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
|
856 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
|
857 } |
