Mercurial > cpython-lru_cache-weakref
annotate Python/sysmodule.c @ 27712:16856c9514e0 legacy-trunk
Small function call optimization and special build option for call stats.
-DCALL_PROFILE: Count the number of function calls executed.
When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made. It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.
Optimization:
When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx(). The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc. The inlined version simply allocates the frame and
copies the arguments values into the frame.
The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables. This change allows fast_function() to get into the fast
path with fewer tests.
I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 05 Feb 2003 23:13:00 +0000 |
| parents | 585a6460f577 |
| children | 0fe321e78ad3 |
| 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 |
|
25666
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
23 #ifdef MS_WINDOWS |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
24 #define WIN32_LEAN_AND_MEAN |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
25 #include "windows.h" |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
26 #endif /* MS_WINDOWS */ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
27 |
|
4291
1427d61f1307
Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents:
4256
diff
changeset
|
28 #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
|
29 extern void *PyWin_DLLhModule; |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
30 /* 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
|
31 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
|
32 #endif |
|
1dfc519ea3cb
Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents:
3326
diff
changeset
|
33 |
| 5372 | 34 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
35 PySys_GetObject(char *name) |
| 6 | 36 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
41 return PyDict_GetItemString(sd, name); |
| 6 | 42 } |
| 43 | |
| 44 FILE * | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
45 PySys_GetFile(char *name, FILE *def) |
| 6 | 46 { |
| 47 FILE *fp = NULL; | |
| 5372 | 48 PyObject *v = PySys_GetObject(name); |
| 49 if (v != NULL && PyFile_Check(v)) | |
| 50 fp = PyFile_AsFile(v); | |
| 6 | 51 if (fp == NULL) |
| 52 fp = def; | |
| 53 return fp; | |
| 54 } | |
| 55 | |
| 56 int | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
57 PySys_SetObject(char *name, PyObject *v) |
| 6 | 58 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 return 0; |
|
f5a2bc39e10e
sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents:
596
diff
changeset
|
64 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
65 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
|
66 } |
| 6 | 67 else |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
68 return PyDict_SetItemString(sd, name, v); |
| 6 | 69 } |
| 70 | |
| 5372 | 71 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
72 sys_displayhook(PyObject *self, PyObject *o) |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
73 { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
74 PyObject *outf; |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
75 PyInterpreterState *interp = PyThreadState_Get()->interp; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
76 PyObject *modules = interp->modules; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
77 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
78 |
|
18805
4462c57f6c94
Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents:
18689
diff
changeset
|
79 if (builtins == NULL) { |
|
4462c57f6c94
Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents:
18689
diff
changeset
|
80 PyErr_SetString(PyExc_RuntimeError, "lost __builtin__"); |
|
4462c57f6c94
Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents:
18689
diff
changeset
|
81 return NULL; |
|
4462c57f6c94
Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents:
18689
diff
changeset
|
82 } |
|
4462c57f6c94
Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents:
18689
diff
changeset
|
83 |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
84 /* Print value except if None */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
85 /* After printing, also assign to '_' */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
86 /* Before, set '_' to None to avoid recursion */ |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
87 if (o == Py_None) { |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
88 Py_INCREF(Py_None); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
89 return Py_None; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
90 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
91 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
92 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
93 if (Py_FlushLine() != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
94 return NULL; |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
95 outf = PySys_GetObject("stdout"); |
|
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
96 if (outf == NULL) { |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
97 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
98 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
99 } |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
100 if (PyFile_WriteObject(o, outf, 0) != 0) |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
101 return NULL; |
|
15812
a563eec46c1a
stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents:
15811
diff
changeset
|
102 PyFile_SoftSpace(outf, 1); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
103 if (Py_FlushLine() != 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 if (PyObject_SetAttrString(builtins, "_", o) != 0) |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
106 return NULL; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
107 Py_INCREF(Py_None); |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
108 return Py_None; |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
109 } |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
110 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
111 PyDoc_STRVAR(displayhook_doc, |
| 17164 | 112 "displayhook(object) -> None\n" |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
113 "\n" |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
114 "Print an object to sys.stdout and also save it in __builtin__._\n" |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
115 ); |
| 17164 | 116 |
| 117 static PyObject * | |
| 118 sys_excepthook(PyObject* self, PyObject* args) | |
| 119 { | |
| 120 PyObject *exc, *value, *tb; | |
|
20655
7344687bf2c0
Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
121 if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb)) |
| 17164 | 122 return NULL; |
| 123 PyErr_Display(exc, value, tb); | |
| 124 Py_INCREF(Py_None); | |
| 125 return Py_None; | |
| 126 } | |
| 127 | |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
128 PyDoc_STRVAR(excepthook_doc, |
| 17164 | 129 "excepthook(exctype, value, traceback) -> None\n" |
| 130 "\n" | |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
131 "Handle an exception by displaying it with a traceback on sys.stderr.\n" |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
132 ); |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
133 |
|
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
134 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
135 sys_exc_info(PyObject *self) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
136 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
137 PyThreadState *tstate; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
138 tstate = PyThreadState_Get(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
139 return Py_BuildValue( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
140 "(OOO)", |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
141 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
|
142 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
|
143 tstate->exc_traceback != NULL ? |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
144 tstate->exc_traceback : Py_None); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
145 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
146 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
147 PyDoc_STRVAR(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
|
148 "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
|
149 \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 Return information about the exception that is currently being handled.\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
151 This should be called from inside an except clause only." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
152 ); |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
153 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5377
diff
changeset
|
154 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
155 sys_exit(PyObject *self, PyObject *args) |
| 6 | 156 { |
|
22604
3f4b2f93e8b5
Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22531
diff
changeset
|
157 PyObject *exit_code = 0; |
|
3f4b2f93e8b5
Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22531
diff
changeset
|
158 if (!PyArg_ParseTuple(args, "|O:exit", &exit_code)) |
|
3f4b2f93e8b5
Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22531
diff
changeset
|
159 return NULL; |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
160 /* Raise SystemExit so callers may catch it or clean up. */ |
|
22604
3f4b2f93e8b5
Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22531
diff
changeset
|
161 PyErr_SetObject(PyExc_SystemExit, exit_code); |
|
549
4efff6cea90f
Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents:
476
diff
changeset
|
162 return NULL; |
| 6 | 163 } |
| 164 | |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
165 PyDoc_STRVAR(exit_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
|
166 "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
|
167 \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
|
168 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
|
169 If the status is omitted or None, it defaults to zero (i.e., success).\n\ |
|
22531
ef314b37e260
backport nascheme's checkin of
Michael W. Hudson <mwh@python.net>
parents:
22119
diff
changeset
|
170 If the status is numeric, it will be used as the system exit status.\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
|
171 If it is another kind of object, it will be printed and the system\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
172 exit status will be one (i.e., failure)." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
173 ); |
|
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
|
174 |
|
20943
e4d380f5f297
Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents:
20655
diff
changeset
|
175 #ifdef Py_USING_UNICODE |
|
e4d380f5f297
Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents:
20655
diff
changeset
|
176 |
| 5372 | 177 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
178 sys_getdefaultencoding(PyObject *self) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
179 { |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
180 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
181 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
182 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
183 PyDoc_STRVAR(getdefaultencoding_doc, |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
184 "getdefaultencoding() -> string\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
185 \n\ |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
186 Return the current default string encoding used by the Unicode \n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
187 implementation." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
188 ); |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
189 |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
190 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
191 sys_setdefaultencoding(PyObject *self, PyObject *args) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
192 { |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
193 char *encoding; |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
194 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding)) |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
195 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
196 if (PyUnicode_SetDefaultEncoding(encoding)) |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
197 return NULL; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
198 Py_INCREF(Py_None); |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
199 return Py_None; |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
200 } |
|
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
201 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
202 PyDoc_STRVAR(setdefaultencoding_doc, |
|
12877
78231bbe605d
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
12649
diff
changeset
|
203 "setdefaultencoding(encoding)\n\ |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
204 \n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
205 Set the current default string encoding used by the Unicode implementation." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
206 ); |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
207 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
208 #endif |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
209 |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
210 /* |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
211 * Cached interned string objects used for calling the profile and |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
212 * trace functions. Initialized by trace_init(). |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
213 */ |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
214 static PyObject *whatstrings[4] = {NULL, NULL, NULL, NULL}; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
215 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
216 static int |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
217 trace_init(void) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
218 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
219 static char *whatnames[4] = {"call", "exception", "line", "return"}; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
220 PyObject *name; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
221 int i; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
222 for (i = 0; i < 4; ++i) { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
223 if (whatstrings[i] == NULL) { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
224 name = PyString_InternFromString(whatnames[i]); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
225 if (name == NULL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
226 return -1; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
227 whatstrings[i] = name; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
228 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
229 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
230 return 0; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
231 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
232 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
233 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
234 static PyObject * |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
235 call_trampoline(PyThreadState *tstate, PyObject* callback, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
236 PyFrameObject *frame, int what, PyObject *arg) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
237 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
238 PyObject *args = PyTuple_New(3); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
239 PyObject *whatstr; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
240 PyObject *result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
241 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
242 if (args == NULL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
243 return NULL; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
244 Py_INCREF(frame); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
245 whatstr = whatstrings[what]; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
246 Py_INCREF(whatstr); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
247 if (arg == NULL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
248 arg = Py_None; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
249 Py_INCREF(arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
250 PyTuple_SET_ITEM(args, 0, (PyObject *)frame); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
251 PyTuple_SET_ITEM(args, 1, whatstr); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
252 PyTuple_SET_ITEM(args, 2, arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
253 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
254 /* call the Python-level function */ |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
255 PyFrame_FastToLocals(frame); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
256 result = PyEval_CallObject(callback, args); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
257 PyFrame_LocalsToFast(frame, 1); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
258 if (result == NULL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
259 PyTraceBack_Here(frame); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
260 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
261 /* cleanup */ |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
262 Py_DECREF(args); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
263 return result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
264 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
265 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
266 static int |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
267 profile_trampoline(PyObject *self, PyFrameObject *frame, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
268 int what, PyObject *arg) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
269 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
270 PyThreadState *tstate = frame->f_tstate; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
271 PyObject *result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
272 |
|
20247
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
273 if (arg == NULL) |
|
a4d328d50897
Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
274 arg = Py_None; |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
275 result = call_trampoline(tstate, self, frame, what, arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
276 if (result == NULL) { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
277 PyEval_SetProfile(NULL, NULL); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
278 return -1; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
279 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
280 Py_DECREF(result); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
281 return 0; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
282 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
283 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
284 static int |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
285 trace_trampoline(PyObject *self, PyFrameObject *frame, |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
286 int what, PyObject *arg) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
287 { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
288 PyThreadState *tstate = frame->f_tstate; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
289 PyObject *callback; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
290 PyObject *result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
291 |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
292 if (what == PyTrace_CALL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
293 callback = self; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
294 else |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
295 callback = frame->f_trace; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
296 if (callback == NULL) |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
297 return 0; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
298 result = call_trampoline(tstate, callback, frame, what, arg); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
299 if (result == NULL) { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
300 PyEval_SetTrace(NULL, NULL); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
301 Py_XDECREF(frame->f_trace); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
302 frame->f_trace = NULL; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
303 return -1; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
304 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
305 if (result != Py_None) { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
306 PyObject *temp = frame->f_trace; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
307 frame->f_trace = NULL; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
308 Py_XDECREF(temp); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
309 frame->f_trace = result; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
310 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
311 else { |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
312 Py_DECREF(result); |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
313 } |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
314 return 0; |
|
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
315 } |
|
18136
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
17396
diff
changeset
|
316 |
|
12649
c92668766f5d
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12398
diff
changeset
|
317 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
318 sys_settrace(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
319 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
320 if (trace_init() == -1) |
|
18136
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
17396
diff
changeset
|
321 return NULL; |
| 5372 | 322 if (args == Py_None) |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
323 PyEval_SetTrace(NULL, NULL); |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
324 else |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
325 PyEval_SetTrace(trace_trampoline, args); |
| 5372 | 326 Py_INCREF(Py_None); |
| 327 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
328 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
329 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
330 PyDoc_STRVAR(settrace_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
|
331 "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
|
332 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
333 Set the global debug tracing function. It will be called on each\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
334 function call. See the debugger chapter in the library manual." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
335 ); |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
336 |
| 5372 | 337 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
338 sys_setprofile(PyObject *self, PyObject *args) |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
339 { |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
340 if (trace_init() == -1) |
|
18136
4cb34314bd97
Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents:
17396
diff
changeset
|
341 return NULL; |
| 5372 | 342 if (args == Py_None) |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
343 PyEval_SetProfile(NULL, NULL); |
|
788
ba4ec13c0f9f
Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents:
710
diff
changeset
|
344 else |
|
18326
e427afb5637f
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
18298
diff
changeset
|
345 PyEval_SetProfile(profile_trampoline, args); |
| 5372 | 346 Py_INCREF(Py_None); |
| 347 return Py_None; | |
|
710
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
348 } |
|
bc5c77fa8006
Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents:
631
diff
changeset
|
349 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
350 PyDoc_STRVAR(setprofile_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
|
351 "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
|
352 \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
|
353 Set the profiling function. It will be called on each function call\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
354 and return. See the profiler chapter in the library manual." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
355 ); |
|
8566
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
356 |
| 5372 | 357 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
358 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
|
359 { |
|
25108
3a26e352f0a6
replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents:
25099
diff
changeset
|
360 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval)) |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
361 return NULL; |
| 5372 | 362 Py_INCREF(Py_None); |
| 363 return Py_None; | |
|
2093
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
364 } |
|
e8cafb2b743a
sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
365 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
366 PyDoc_STRVAR(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
|
367 "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
|
368 \n\ |
|
6e8b0e754a7f
Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents:
8314
diff
changeset
|
369 Tell the Python interpreter to check for asynchronous events every\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
370 n instructions. This also affects how often thread switches occur." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
371 ); |
|
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
|
372 |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
373 static PyObject * |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
374 sys_setrecursionlimit(PyObject *self, PyObject *args) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
375 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
376 int new_limit; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
377 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit)) |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
378 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
379 if (new_limit <= 0) { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
380 PyErr_SetString(PyExc_ValueError, |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
381 "recursion limit must be positive"); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
382 return NULL; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
383 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
384 Py_SetRecursionLimit(new_limit); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
385 Py_INCREF(Py_None); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
386 return Py_None; |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
387 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
388 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
389 PyDoc_STRVAR(setrecursionlimit_doc, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
390 "setrecursionlimit(n)\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
391 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
392 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
|
393 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
|
394 stack and crashing Python. The highest possible limit is platform-\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
395 dependent." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
396 ); |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
397 |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
398 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
399 sys_getrecursionlimit(PyObject *self) |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
400 { |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
401 return PyInt_FromLong(Py_GetRecursionLimit()); |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
402 } |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
403 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
404 PyDoc_STRVAR(getrecursionlimit_doc, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
405 "getrecursionlimit()\n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
406 \n\ |
|
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
407 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
|
408 of the Python interpreter stack. This limit prevents infinite\n\ |
|
24013
71f13cf4f9e2
Got rid of an extraneous semicolon.
Jack Jansen <jack.jansen@cwi.nl>
parents:
23947
diff
changeset
|
409 recursion from causing an overflow of the C stack and crashing Python." |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
410 ); |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
411 |
|
25666
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
412 #ifdef MS_WINDOWS |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
413 PyDoc_STRVAR(getwindowsversion_doc, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
414 "getwindowsversion()\n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
415 \n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
416 Return information about the running version of Windows.\n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
417 The result is a tuple of (major, minor, build, platform, text)\n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
418 All elements are numbers, except text which is a string.\n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
419 Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n\ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
420 " |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
421 ); |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
422 |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
423 static PyObject * |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
424 sys_getwindowsversion(PyObject *self) |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
425 { |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
426 OSVERSIONINFO ver; |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
427 ver.dwOSVersionInfoSize = sizeof(ver); |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
428 if (!GetVersionEx(&ver)) |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
429 return PyErr_SetFromWindowsErr(0); |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
430 return Py_BuildValue("HHHHs", |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
431 ver.dwMajorVersion, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
432 ver.dwMinorVersion, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
433 ver.dwBuildNumber, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
434 ver.dwPlatformId, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
435 ver.szCSDVersion); |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
436 } |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
437 |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
438 #endif /* MS_WINDOWS */ |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
439 |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
440 #ifdef HAVE_DLOPEN |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
441 static PyObject * |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
442 sys_setdlopenflags(PyObject *self, PyObject *args) |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
443 { |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
444 int new_val; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
445 PyThreadState *tstate = PyThreadState_Get(); |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
446 if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val)) |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
447 return NULL; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
448 if (!tstate) |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
449 return NULL; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
450 tstate->interp->dlopenflags = new_val; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
451 Py_INCREF(Py_None); |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
452 return Py_None; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
453 } |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
454 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
455 PyDoc_STRVAR(setdlopenflags_doc, |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
456 "setdlopenflags(n) -> None\n\ |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
457 \n\ |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
458 Set the flags that will be used for dlopen() calls. Among other\n\ |
|
21833
070d392042e3
Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21712
diff
changeset
|
459 things, this will enable a lazy resolving of symbols when importing\n\ |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
460 a module, if called as sys.setdlopenflags(0)\n\ |
|
21833
070d392042e3
Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21712
diff
changeset
|
461 To share symbols across extension modules, call as\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
462 sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)" |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
463 ); |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
464 |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
465 static PyObject * |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
466 sys_getdlopenflags(PyObject *self, PyObject *args) |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
467 { |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
468 PyThreadState *tstate = PyThreadState_Get(); |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
469 if (!tstate) |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
470 return NULL; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
471 return PyInt_FromLong(tstate->interp->dlopenflags); |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
472 } |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
473 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
474 PyDoc_STRVAR(getdlopenflags_doc, |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
475 "getdlopenflags() -> int\n\ |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
476 \n\ |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
477 Return the current value of the flags that are used for dlopen()\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
478 calls. The flag constants are defined in the dl module." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
479 ); |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
480 #endif |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
481 |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
482 #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
|
483 /* 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
|
484 #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
|
485 |
| 5372 | 486 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
487 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
|
488 { |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
489 int flag; |
|
12136
9b9abde032b3
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
490 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
|
491 return NULL; |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
492 mallopt(M_DEBUG, flag); |
| 5372 | 493 Py_INCREF(Py_None); |
| 494 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
|
495 } |
|
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
496 #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
|
497 |
| 5372 | 498 static PyObject * |
|
20655
7344687bf2c0
Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
499 sys_getrefcount(PyObject *self, PyObject *arg) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
500 { |
|
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
|
501 return PyInt_FromLong(arg->ob_refcnt); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
502 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
503 |
|
24126
fdf80e04e4bb
Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents:
24071
diff
changeset
|
504 #ifdef Py_REF_DEBUG |
|
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
|
505 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
506 sys_gettotalrefcount(PyObject *self) |
|
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
|
507 { |
|
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
|
508 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
|
509 } |
|
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
|
510 |
|
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
|
511 #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
|
512 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
513 PyDoc_STRVAR(getrefcount_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
|
514 "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
|
515 \n\ |
|
23947
37118b6e5f46
Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents:
23746
diff
changeset
|
516 Return the reference count of object. The count returned is generally\n\ |
|
37118b6e5f46
Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents:
23746
diff
changeset
|
517 one higher than you might expect, because it includes the (temporary)\n\ |
|
37118b6e5f46
Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents:
23746
diff
changeset
|
518 reference as an argument to getrefcount()." |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
519 ); |
|
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
|
520 |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
521 #ifdef COUNT_ALLOCS |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
522 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
523 sys_getcounts(PyObject *self) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
524 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
525 extern PyObject *get_counts(void); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
526 |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
527 return get_counts(); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
528 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
529 #endif |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
530 |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
531 PyDoc_STRVAR(getframe_doc, |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
532 "_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
|
533 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 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
|
538 \n\ |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
539 This function should be used for internal and specialized\n\ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
540 purposes only." |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
541 ); |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
542 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
543 static PyObject * |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
544 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
|
545 { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
546 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
|
547 int depth = -1; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
548 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
549 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
|
550 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
551 |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
552 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
|
553 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
|
554 --depth; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
555 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
556 if (f == NULL) { |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
557 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
|
558 "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
|
559 return NULL; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
560 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
561 Py_INCREF(f); |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
562 return (PyObject*)f; |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
563 } |
|
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
564 |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
565 PyDoc_STRVAR(callstats_doc, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
566 "callstats() -> tuple of integers\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
567 \n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
568 Return a tuple of function call statistics, if CALL_PROFILE was defined\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
569 when Python was built. Otherwise, return None.\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
570 \n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
571 When enabled, this function returns detailed, implementation-specific\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
572 details about the number of function calls executed. The return value is\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
573 a 11-tuple where the entries in the tuple are counts of:\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
574 0. all function calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
575 1. calls to PyFunction_Type objects\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
576 2. PyFunction calls that do not create an argument tuple\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
577 3. PyFunction calls that do not create an argument tuple\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
578 and bypass PyEval_EvalCodeEx()\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
579 4. PyMethod calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
580 5. PyMethod calls on bound methods\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
581 6. PyType calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
582 7. PyCFunction calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
583 8. generator calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
584 9. All other calls\n\ |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
585 10. Number of stack pops performed by call_function()" |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
586 ); |
|
15487
f0ca4c67957b
_getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
587 |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
588 #ifdef Py_TRACE_REFS |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
589 /* 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
|
590 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
591 #endif |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3585
diff
changeset
|
592 |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
593 #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
|
594 /* 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
|
595 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
|
596 #endif |
|
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
597 |
| 5372 | 598 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
|
599 /* Might as well keep this in alphabetic order */ |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
600 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
601 callstats_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
602 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
603 {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
604 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, |
|
22604
3f4b2f93e8b5
Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22531
diff
changeset
|
605 {"exit", sys_exit, METH_VARARGS, exit_doc}, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
606 #ifdef Py_USING_UNICODE |
|
27712
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
607 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, |
|
16856c9514e0
Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27156
diff
changeset
|
608 METH_NOARGS, getdefaultencoding_doc}, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
609 #endif |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
610 #ifdef HAVE_DLOPEN |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
611 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
612 getdlopenflags_doc}, |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
613 #endif |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
614 #ifdef COUNT_ALLOCS |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
615 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
616 #endif |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
617 #ifdef DYNAMIC_EXECUTION_PROFILE |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
618 {"getdxp", _Py_GetDXProfile, METH_VARARGS}, |
|
5047
7a9cac7cb910
Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents:
4904
diff
changeset
|
619 #endif |
|
3585
4ed09a3c3201
TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents:
3490
diff
changeset
|
620 #ifdef Py_TRACE_REFS |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
621 {"getobjects", _Py_GetObjects, METH_VARARGS}, |
|
24126
fdf80e04e4bb
Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents:
24071
diff
changeset
|
622 #endif |
|
fdf80e04e4bb
Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents:
24071
diff
changeset
|
623 #ifdef Py_REF_DEBUG |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
624 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS}, |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2810
diff
changeset
|
625 #endif |
|
20655
7344687bf2c0
Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents:
20247
diff
changeset
|
626 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
627 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
628 getrecursionlimit_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
629 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, |
|
25666
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
630 #ifdef MS_WINDOWS |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
631 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
632 getwindowsversion_doc}, |
|
4a825b902310
Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents:
25108
diff
changeset
|
633 #endif /* MS_WINDOWS */ |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
634 #ifdef USE_MALLOPT |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
635 {"mdebug", sys_mdebug, METH_VARARGS}, |
|
1013
a1ce5a949828
Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents:
901
diff
changeset
|
636 #endif |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
637 #ifdef Py_USING_UNICODE |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
638 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
639 setdefaultencoding_doc}, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
640 #endif |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
641 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
642 setcheckinterval_doc}, |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
643 #ifdef HAVE_DLOPEN |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
644 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
645 setdlopenflags_doc}, |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
646 #endif |
|
22119
0859e764509e
SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents:
21833
diff
changeset
|
647 {"setprofile", sys_setprofile, METH_O, setprofile_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
18805
diff
changeset
|
648 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
649 setrecursionlimit_doc}, |
|
22119
0859e764509e
SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents:
21833
diff
changeset
|
650 {"settrace", sys_settrace, METH_O, settrace_doc}, |
| 86 | 651 {NULL, NULL} /* sentinel */ |
| 652 }; | |
| 653 | |
| 5372 | 654 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
655 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
|
656 { |
| 5372 | 657 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
|
658 int i; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
659 if (list == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 PyImport_Inittab[i].name); |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
664 if (name == NULL) |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
665 break; |
| 5372 | 666 PyList_Append(list, name); |
| 667 Py_DECREF(name); | |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
668 } |
| 5372 | 669 if (PyList_Sort(list) != 0) { |
| 670 Py_DECREF(list); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
671 list = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
672 } |
|
4904
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
673 if (list) { |
| 5372 | 674 PyObject *v = PyList_AsTuple(list); |
| 675 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
|
676 list = v; |
|
5dc20a9e0506
Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
677 } |
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
678 return list; |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
679 } |
|
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
680 |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
681 static PyObject *warnoptions = NULL; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
682 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
683 void |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
684 PySys_ResetWarnOptions(void) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
685 { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
686 if (warnoptions == NULL || !PyList_Check(warnoptions)) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
687 return; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
688 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
|
689 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
690 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
691 void |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
692 PySys_AddWarnOption(char *s) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
693 { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
694 PyObject *str; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
695 |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
696 if (warnoptions == NULL || !PyList_Check(warnoptions)) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
697 Py_XDECREF(warnoptions); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
698 warnoptions = PyList_New(0); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
699 if (warnoptions == NULL) |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
700 return; |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
701 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
702 str = PyString_FromString(s); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
703 if (str != NULL) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
704 PyList_Append(warnoptions, str); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
705 Py_DECREF(str); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
706 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
707 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
708 |
|
8840
44baef8ab5c8
Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents:
8566
diff
changeset
|
709 /* 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
|
710 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
|
711 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
|
712 get rid of the !!! comment in the middle and the quotes that surround it. */ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
713 PyDoc_VAR(sys_doc) = |
|
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
714 PyDoc_STR( |
|
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
|
715 "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
|
716 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
|
717 \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
|
718 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
|
719 \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
|
720 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
|
721 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
|
722 modules -- dictionary of loaded modules\n\ |
| 17164 | 723 \n\ |
| 724 displayhook -- called to show results in an interactive session\n\ | |
| 725 excepthook -- called to handle any uncaught exception other than SystemExit\n\ | |
| 726 To customize printing in an interactive session or to install a custom\n\ | |
| 727 top-level exception handler, assign other functions to replace these.\n\ | |
| 728 \n\ | |
| 729 exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\ | |
| 730 Assigning to sys.exitfunc is deprecated; use the atexit module instead.\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
|
731 \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
|
732 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
|
733 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
|
734 stderr -- standard error object; used for error messages\n\ |
| 17164 | 735 By assigning other file objects (or objects that behave like files)\n\ |
| 736 to these, it is possible to redirect all of the interpreter's I/O.\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
|
737 \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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 \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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 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
|
749 " |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
750 ) |
| 17164 | 751 /* concatenating string here */ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
752 PyDoc_STR( |
|
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
|
753 "\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
|
754 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
|
755 \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
|
756 maxint -- the largest supported integer (the smallest is -maxint-1)\n\ |
|
18298
982163c4e9d2
Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents:
18136
diff
changeset
|
757 maxunicode -- the largest supported character\n\ |
|
21833
070d392042e3
Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21712
diff
changeset
|
758 builtin_module_names -- tuple of module names built into this interpreter\n\ |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 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
|
766 exec_prefix -- prefix used to find the machine-specific Python library\n\ |
| 17164 | 767 " |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
768 ) |
| 17164 | 769 #ifdef MS_WINDOWS |
| 770 /* concatenating string here */ | |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
771 PyDoc_STR( |
| 17164 | 772 "dllhandle -- [Windows only] integer handle of the Python DLL\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
|
773 winver -- [Windows only] version number of the Python DLL\n\ |
| 17164 | 774 " |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
775 ) |
| 17164 | 776 #endif /* MS_WINDOWS */ |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
777 PyDoc_STR( |
| 17164 | 778 "__stdin__ -- the original stdin; don't touch!\n\ |
| 779 __stdout__ -- the original stdout; don't touch!\n\ | |
| 780 __stderr__ -- the original stderr; don't touch!\n\ | |
| 781 __displayhook__ -- the original displayhook; don't touch!\n\ | |
| 782 __excepthook__ -- the original excepthook; don't touch!\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
|
783 \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
|
784 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
|
785 \n\ |
|
15811
1a00d21910c8
Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
15595
diff
changeset
|
786 displayhook() -- print an object to the screen, and save it in __builtin__._\n\ |
| 17164 | 787 excepthook() -- print an exception and its traceback to sys.stderr\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
|
788 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
|
789 exit() -- exit the interpreter by raising SystemExit\n\ |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
790 getdlopenflags() -- returns flags to be used for dlopen() calls\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
|
791 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
|
792 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
|
793 setcheckinterval() -- control how often the interpreter checks for events\n\ |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18326
diff
changeset
|
794 setdlopenflags() -- set the flags to be used for dlopen() calls\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
|
795 setprofile() -- set the global profiling function\n\ |
|
14308
b8b3f76ffd51
add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14295
diff
changeset
|
796 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
|
797 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
|
798 " |
|
23746
43ddcdcd3c71
Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents:
22604
diff
changeset
|
799 ) |
|
13971
aa4202702252
The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents:
13968
diff
changeset
|
800 /* 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
|
801 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
802 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
803 _PySys_Init(void) |
| 6 | 804 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
805 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
|
806 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
|
807 char *s; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
808 |
|
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
|
809 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 5372 | 810 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
|
811 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
812 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
|
813 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
|
814 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); |
| 5372 | 815 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
|
816 return NULL; |
| 5372 | 817 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 818 PyDict_SetItemString(sysdict, "stdout", sysout); | |
| 819 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
|
820 /* 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
|
821 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
|
822 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
|
823 PyDict_SetItemString(sysdict, "__stderr__", syserr); |
| 17164 | 824 PyDict_SetItemString(sysdict, "__displayhook__", |
| 825 PyDict_GetItemString(sysdict, "displayhook")); | |
| 826 PyDict_SetItemString(sysdict, "__excepthook__", | |
| 827 PyDict_GetItemString(sysdict, "excepthook")); | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
828 Py_XDECREF(sysin); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
829 Py_XDECREF(sysout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
830 Py_XDECREF(syserr); |
| 5372 | 831 PyDict_SetItemString(sysdict, "version", |
| 832 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
|
833 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
|
834 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
|
835 v = PyInt_FromLong(PY_VERSION_HEX)); |
| 5372 | 836 Py_XDECREF(v); |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
837 /* |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
838 * 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
|
839 * 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
|
840 */ |
|
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
841 #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
|
842 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
|
843 #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
|
844 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
|
845 #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
|
846 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
|
847 #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
|
848 s = "final"; |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
849 #endif |
|
12394
60dd95c75999
Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents:
12136
diff
changeset
|
850 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
|
851 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
|
852 PY_MINOR_VERSION, |
|
12398
2392d10e21f1
Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents:
12396
diff
changeset
|
853 PY_MICRO_VERSION, s, |
|
12396
f82b2577fa0c
Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents:
12394
diff
changeset
|
854 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
|
855 Py_XDECREF(v); |
|
25099
a69a12484d69
expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents:
24126
diff
changeset
|
856 PyDict_SetItemString(sysdict, "api_version", |
|
a69a12484d69
expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents:
24126
diff
changeset
|
857 v = PyInt_FromLong(PYTHON_API_VERSION)); |
|
a69a12484d69
expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents:
24126
diff
changeset
|
858 Py_XDECREF(v); |
| 5372 | 859 PyDict_SetItemString(sysdict, "copyright", |
| 860 v = PyString_FromString(Py_GetCopyright())); | |
| 861 Py_XDECREF(v); | |
| 862 PyDict_SetItemString(sysdict, "platform", | |
| 863 v = PyString_FromString(Py_GetPlatform())); | |
| 864 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
|
865 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
|
866 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
|
867 Py_XDECREF(v); |
| 5372 | 868 PyDict_SetItemString(sysdict, "prefix", |
| 869 v = PyString_FromString(Py_GetPrefix())); | |
| 870 Py_XDECREF(v); | |
| 871 PyDict_SetItemString(sysdict, "exec_prefix", | |
| 872 v = PyString_FromString(Py_GetExecPrefix())); | |
| 873 Py_XDECREF(v); | |
| 874 PyDict_SetItemString(sysdict, "maxint", | |
| 875 v = PyInt_FromLong(PyInt_GetMax())); | |
| 876 Py_XDECREF(v); | |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
877 #ifdef Py_USING_UNICODE |
|
18298
982163c4e9d2
Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents:
18136
diff
changeset
|
878 PyDict_SetItemString(sysdict, "maxunicode", |
|
982163c4e9d2
Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents:
18136
diff
changeset
|
879 v = PyInt_FromLong(PyUnicode_GetMax())); |
|
982163c4e9d2
Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents:
18136
diff
changeset
|
880 Py_XDECREF(v); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
881 #endif |
| 5372 | 882 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
|
883 v = list_builtin_module_names()); |
| 5372 | 884 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
|
885 { |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
886 /* 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
|
887 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
|
888 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
|
889 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
|
890 |
|
841cf9012ac3
Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents:
13694
diff
changeset
|
891 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
|
892 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
|
893 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
|
894 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
|
895 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
|
896 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
|
897 v = PyString_FromString(value)); |
|
128f641191c3
_PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents:
13977
diff
changeset
|
898 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
|
899 } |
|
4126
c80c515999b9
Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents:
3877
diff
changeset
|
900 #ifdef MS_COREDLL |
| 5372 | 901 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
|
902 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 5372 | 903 Py_XDECREF(v); |
| 904 PyDict_SetItemString(sysdict, "winver", | |
|
6352
b62a7a59414e
Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents:
5955
diff
changeset
|
905 v = PyString_FromString(PyWin_DLLVersionString)); |
| 5372 | 906 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
|
907 #endif |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
908 if (warnoptions == NULL) { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
909 warnoptions = PyList_New(0); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
910 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
911 else { |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
912 Py_INCREF(warnoptions); |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
913 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
914 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
|
915 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); |
|
15595
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
916 } |
|
0f42f6669e80
Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents:
15487
diff
changeset
|
917 |
| 5372 | 918 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
|
919 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5863
diff
changeset
|
920 return m; |
| 86 | 921 } |
| 922 | |
| 5372 | 923 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
924 makepathobject(char *path, int delim) |
| 86 | 925 { |
| 926 int i, n; | |
| 927 char *p; | |
| 5372 | 928 PyObject *v, *w; |
| 6 | 929 |
| 86 | 930 n = 1; |
| 931 p = path; | |
| 932 while ((p = strchr(p, delim)) != NULL) { | |
| 933 n++; | |
| 934 p++; | |
| 935 } | |
| 5372 | 936 v = PyList_New(n); |
| 86 | 937 if (v == NULL) |
| 938 return NULL; | |
| 939 for (i = 0; ; i++) { | |
| 940 p = strchr(path, delim); | |
| 941 if (p == NULL) | |
| 942 p = strchr(path, '\0'); /* End of string */ | |
| 5372 | 943 w = PyString_FromStringAndSize(path, (int) (p - path)); |
| 86 | 944 if (w == NULL) { |
| 5372 | 945 Py_DECREF(v); |
| 86 | 946 return NULL; |
| 947 } | |
| 5372 | 948 PyList_SetItem(v, i, w); |
| 86 | 949 if (*p == '\0') |
| 950 break; | |
| 951 path = p+1; | |
| 952 } | |
| 953 return v; | |
| 954 } | |
| 955 | |
| 956 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
957 PySys_SetPath(char *path) |
| 86 | 958 { |
| 5372 | 959 PyObject *v; |
| 86 | 960 if ((v = makepathobject(path, DELIM)) == NULL) |
| 5372 | 961 Py_FatalError("can't create sys.path"); |
| 962 if (PySys_SetObject("path", v) != 0) | |
| 963 Py_FatalError("can't assign sys.path"); | |
| 964 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
|
965 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
966 |
| 5372 | 967 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
968 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
|
969 { |
| 5372 | 970 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
|
971 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
|
972 /* 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
|
973 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
|
974 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
|
975 argc = 1; |
|
e18f1fa398a3
Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents:
549
diff
changeset
|
976 } |
| 5372 | 977 av = PyList_New(argc); |
| 86 | 978 if (av != NULL) { |
| 979 int i; | |
| 980 for (i = 0; i < argc; i++) { | |
| 5372 | 981 PyObject *v = PyString_FromString(argv[i]); |
| 86 | 982 if (v == NULL) { |
| 5372 | 983 Py_DECREF(av); |
| 86 | 984 av = NULL; |
| 985 break; | |
| 986 } | |
| 5372 | 987 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
|
988 } |
|
f6bcf3c1d714
Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
989 } |
| 86 | 990 return av; |
| 6 | 991 } |
| 992 | |
| 993 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
994 PySys_SetArgv(int argc, char **argv) |
| 6 | 995 { |
|
27156
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
996 #ifdef MS_WINDOWS |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
997 char fullpath[MAX_PATH]; |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
998 #endif |
| 5372 | 999 PyObject *av = makeargvobject(argc, argv); |
| 1000 PyObject *path = PySys_GetObject("path"); | |
| 86 | 1001 if (av == NULL) |
| 5372 | 1002 Py_FatalError("no mem for sys.argv"); |
| 1003 if (PySys_SetObject("argv", av) != 0) | |
| 1004 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
|
1005 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
|
1006 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
|
1007 char *p = NULL; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1008 int n = 0; |
| 5372 | 1009 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
|
1010 #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
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 /* 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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 ; /* 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
|
1023 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
|
1024 /* 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 /* 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
|
1030 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
|
1031 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
|
1032 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
|
1033 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
|
1034 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
1035 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
1036 } |
|
db673e98f28d
Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents:
5047
diff
changeset
|
1037 #endif /* HAVE_READLINK */ |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1038 #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
|
1039 if (argc > 0 && argv0 != NULL) { |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1040 char *q; |
|
27156
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1041 #ifdef MS_WINDOWS |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1042 char *ptemp; |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1043 if (GetFullPathName(argv0, |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1044 sizeof(fullpath), |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1045 fullpath, |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1046 &ptemp)) { |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1047 argv0 = fullpath; |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1048 } |
|
585a6460f577
Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents:
25666
diff
changeset
|
1049 #endif |
|
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
|
1050 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1051 /* 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
|
1052 q = strrchr(p ? p : argv0, '/'); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1053 if (q != NULL) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1054 p = q; |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1055 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
|
1056 n = p + 1 - argv0; |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1057 if (n > 1 && p[-1] != ':') |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1058 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1059 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1060 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1061 #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
|
1062 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
|
1063 p = strrchr(argv0, SEP); |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1064 if (p != NULL) { |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17164
diff
changeset
|
1065 #ifndef RISCOS |
|
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
|
1066 n = p + 1 - argv0; |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17164
diff
changeset
|
1067 #else /* don't include trailing separator */ |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17164
diff
changeset
|
1068 n = p - argv0; |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17164
diff
changeset
|
1069 #endif /* RISCOS */ |
|
4256
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1070 #if SEP == '/' /* Special case for Unix filename syntax */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1071 if (n > 1) |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1072 n--; /* Drop trailing separator */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1073 #endif /* Unix */ |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1074 } |
|
e225e70fd657
Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents:
4126
diff
changeset
|
1075 #endif /* All others */ |
| 5372 | 1076 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
|
1077 if (a == NULL) |
| 5372 | 1078 Py_FatalError("no mem for sys.path insertion"); |
| 1079 if (PyList_Insert(path, 0, a) < 0) | |
| 1080 Py_FatalError("sys.path.insert(0) failed"); | |
| 1081 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
|
1082 } |
| 5372 | 1083 Py_DECREF(av); |
| 6 | 1084 } |
|
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
|
1085 |
|
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
|
1086 |
|
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
|
1087 /* 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
|
1088 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
|
1089 |
|
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
|
1090 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
|
1091 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
|
1092 |
|
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
|
1093 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
|
1094 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
|
1095 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
|
1096 |
|
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
|
1097 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
|
1098 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
|
1099 |
|
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
|
1100 *** 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
|
1101 |
|
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
|
1102 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
|
1103 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
|
1104 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
|
1105 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
|
1106 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
|
1107 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
|
1108 |
|
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
|
1109 */ |
|
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
|
1110 |
|
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
|
1111 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1112 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
|
1113 { |
|
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
|
1114 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
|
1115 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
|
1116 |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
1117 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
|
1118 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
|
1119 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
|
1120 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
|
1121 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
|
1122 char buffer[1001]; |
|
21127
dd28a4ecb37f
mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
Tim Peters <tim.peters@gmail.com>
parents:
21091
diff
changeset
|
1123 const int written = PyOS_vsnprintf(buffer, sizeof(buffer), |
|
dd28a4ecb37f
mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
Tim Peters <tim.peters@gmail.com>
parents:
21091
diff
changeset
|
1124 format, 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
|
1125 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
|
1126 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
|
1127 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
|
1128 } |
|
21145
87fa6e9bd77e
mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
Tim Peters <tim.peters@gmail.com>
parents:
21127
diff
changeset
|
1129 if (written < 0 || written >= sizeof(buffer)) { |
|
21091
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1130 const char *truncated = "... truncated"; |
|
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1131 if (PyFile_WriteString(truncated, file) != 0) { |
|
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1132 PyErr_Clear(); |
|
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1133 fputs(truncated, fp); |
|
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1134 } |
|
47f6533674fd
Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20943
diff
changeset
|
1135 } |
|
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
|
1136 } |
|
9328
81574e4646b4
Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents:
8840
diff
changeset
|
1137 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
|
1138 } |
|
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
|
1139 |
|
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
|
1140 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
|
1141 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
|
1142 { |
|
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
|
1143 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
|
1144 |
|
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
|
1145 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
|
1146 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
|
1147 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
|
1148 } |
|
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
|
1149 |
|
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
|
1150 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
|
1151 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
|
1152 { |
|
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
|
1153 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
|
1154 |
|
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
|
1155 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
|
1156 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
|
1157 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
|
1158 } |
