annotate Python/sysmodule.c @ 60889:86fadaebcf66

Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute indirectly Python signal handlers anymore because mywrite() ignores exceptions (KeyboardInterrupt).
author Victor Stinner <victor.stinner@haypocalc.com>
date Fri, 23 Apr 2010 12:02:30 +0000
parents 29fac4b1a51e
children cab14be0ada1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* System module */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Various bits of information used by the interpreter are collected in
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 module 'sys'.
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 Data members:
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 - stdin, stdout, stderr: standard file objects
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
11 - modules: the table of modules (dictionary)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 - path: module search path (list of strings)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
13 - argv: script arguments (list of strings)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
14 - ps1, ps2: optional primary and secondary prompts (strings)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
17 #include "Python.h"
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
18 #include "structseq.h"
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35673
diff changeset
19 #include "code.h"
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
20 #include "frameobject.h"
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
21 #include "eval.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
22
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
23 #include "osdefs.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
24
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
25 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
26 #define WIN32_LEAN_AND_MEAN
43813
1561763cda72 No need to include windows.h twice
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43777
diff changeset
27 #include <windows.h>
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
28 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
29
4291
1427d61f1307 Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents: 4256
diff changeset
30 #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
31 extern void *PyWin_DLLhModule;
6352
b62a7a59414e Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents: 5955
diff changeset
32 /* 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
33 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
34 #endif
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
35
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
36 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
37 #include <unixlib.h>
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
38 #endif
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
39
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
40 #ifdef HAVE_LANGINFO_H
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
41 #include <locale.h>
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
42 #include <langinfo.h>
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
43 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
44
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
45 PyObject *
42812
a99ec4befda8 Add const to input string parameters
Neal Norwitz <nnorwitz@gmail.com>
parents: 42703
diff changeset
46 PySys_GetObject(const char *name)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
48 PyThreadState *tstate = PyThreadState_GET();
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
49 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
50 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
51 return NULL;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
52 return PyDict_GetItemString(sd, name);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 int
42812
a99ec4befda8 Add const to input string parameters
Neal Norwitz <nnorwitz@gmail.com>
parents: 42703
diff changeset
56 PySys_SetObject(const char *name, PyObject *v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
58 PyThreadState *tstate = PyThreadState_GET();
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
59 PyObject *sd = tstate->interp->sysdict;
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
60 if (v == NULL) {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
61 if (PyDict_GetItemString(sd, name) == NULL)
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
62 return 0;
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
63 else
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
64 return PyDict_DelItemString(sd, name);
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
65 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 else
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
67 return PyDict_SetItemString(sd, name, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
70 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
71 sys_displayhook(PyObject *self, PyObject *o)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
72 {
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
73 PyObject *outf;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
74 PyInterpreterState *interp = PyThreadState_GET()->interp;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
75 PyObject *modules = interp->modules;
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 44086
diff changeset
76 PyObject *builtins = PyDict_GetItemString(modules, "builtins");
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
77
18805
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
78 if (builtins == NULL) {
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 44086
diff changeset
79 PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
18805
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
80 return NULL;
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
81 }
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
82
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
83 /* Print value except if None */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
84 /* After printing, also assign to '_' */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
85 /* Before, set '_' to None to avoid recursion */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
86 if (o == Py_None) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
87 Py_INCREF(Py_None);
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
88 return Py_None;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
89 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
90 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
91 return NULL;
15812
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
92 outf = PySys_GetObject("stdout");
43855
ee081609cee8 Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents: 43847
diff changeset
93 if (outf == NULL || outf == Py_None) {
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
94 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
95 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
96 }
15812
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
97 if (PyFile_WriteObject(o, outf, 0) != 0)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
98 return NULL;
40799
04f5cbc74424 Kill off softspace completely (except in formatter.py which seems to have
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
99 if (PyFile_WriteString("\n", outf) != 0)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
100 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
101 if (PyObject_SetAttrString(builtins, "_", o) != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
102 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
103 Py_INCREF(Py_None);
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
104 return Py_None;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
105 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
106
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
107 PyDoc_STRVAR(displayhook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
108 "displayhook(object) -> None\n"
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
109 "\n"
59300
29fac4b1a51e Merged revisions 78620 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58507
diff changeset
110 "Print an object to sys.stdout and also save it in builtins._\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
111 );
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
112
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
113 static PyObject *
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
114 sys_excepthook(PyObject* self, PyObject* args)
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
115 {
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
116 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
117 if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
118 return NULL;
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
119 PyErr_Display(exc, value, tb);
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
120 Py_INCREF(Py_None);
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
121 return Py_None;
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
122 }
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
123
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
124 PyDoc_STRVAR(excepthook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
125 "excepthook(exctype, value, traceback) -> None\n"
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
126 "\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
127 "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
128 );
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
129
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
130 static PyObject *
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
131 sys_exc_info(PyObject *self, PyObject *noargs)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
132 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
133 PyThreadState *tstate;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
134 tstate = PyThreadState_GET();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
135 return Py_BuildValue(
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
136 "(OOO)",
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
137 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
138 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
139 tstate->exc_traceback != NULL ?
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
140 tstate->exc_traceback : Py_None);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
141 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
142
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
143 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
144 "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
145 \n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
146 Return information about the most recent exception caught by an except\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
147 clause in the current stack frame or in an older stack frame."
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
148 );
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
149
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
150 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
151 sys_exit(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 {
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
153 PyObject *exit_code = 0;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
154 if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
155 return NULL;
549
4efff6cea90f Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents: 476
diff changeset
156 /* 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
157 PyErr_SetObject(PyExc_SystemExit, exit_code);
549
4efff6cea90f Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents: 476
diff changeset
158 return NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
161 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
162 "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
163 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
164 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
165 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
166 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
167 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
168 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
169 );
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
170
20943
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
171
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
172 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
173 sys_getdefaultencoding(PyObject *self)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
174 {
41956
b30c75d22f34 Change getdefaultencoding() and getfilesystemencoding()
Walter Dörwald <walter@livinglogic.de>
parents: 41846
diff changeset
175 return PyUnicode_FromString(PyUnicode_GetDefaultEncoding());
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
176 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
177
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
178 PyDoc_STRVAR(getdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
179 "getdefaultencoding() -> string\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
180 \n\
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
181 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
182 implementation."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
183 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
184
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
185 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
186 sys_setdefaultencoding(PyObject *self, PyObject *args)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
187 {
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
188 char *encoding;
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
189 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
190 return NULL;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
191 if (PyUnicode_SetDefaultEncoding(encoding))
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
192 return NULL;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
193 Py_INCREF(Py_None);
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
194 return Py_None;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
195 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
196
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
197 PyDoc_STRVAR(setdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
198 "setdefaultencoding(encoding)\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
199 \n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
200 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
201 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
202
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
203 static PyObject *
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
204 sys_getfilesystemencoding(PyObject *self)
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
205 {
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
206 if (Py_FileSystemDefaultEncoding)
41956
b30c75d22f34 Change getdefaultencoding() and getfilesystemencoding()
Walter Dörwald <walter@livinglogic.de>
parents: 41846
diff changeset
207 return PyUnicode_FromString(Py_FileSystemDefaultEncoding);
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
208 Py_INCREF(Py_None);
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
209 return Py_None;
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
210 }
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
211
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
212 PyDoc_STRVAR(getfilesystemencoding_doc,
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
213 "getfilesystemencoding() -> string\n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
214 \n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
215 Return the encoding used to convert Unicode filenames in\n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
216 operating system filenames."
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
217 );
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
218
49403
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
219 static PyObject *
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
220 sys_setfilesystemencoding(PyObject *self, PyObject *args)
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
221 {
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
222 PyObject *new_encoding;
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
223 if (!PyArg_ParseTuple(args, "U:setfilesystemencoding", &new_encoding))
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
224 return NULL;
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
225 if (_Py_SetFileSystemEncoding(new_encoding))
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
226 return NULL;
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
227 Py_INCREF(Py_None);
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
228 return Py_None;
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
229 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
230
49403
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
231 PyDoc_STRVAR(setfilesystemencoding_doc,
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
232 "setfilesystemencoding(string) -> None\n\
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
233 \n\
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
234 Set the encoding used to convert Unicode filenames in\n\
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
235 operating system filenames."
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
236 );
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
237
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
238 static PyObject *
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
239 sys_intern(PyObject *self, PyObject *args)
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
240 {
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
241 PyObject *s;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43761
diff changeset
242 if (!PyArg_ParseTuple(args, "U:intern", &s))
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
243 return NULL;
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43761
diff changeset
244 if (PyUnicode_CheckExact(s)) {
41957
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
245 Py_INCREF(s);
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
246 PyUnicode_InternInPlace(&s);
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
247 return s;
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
248 }
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
249 else {
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
250 PyErr_Format(PyExc_TypeError,
7015cccf29e3 Change sys.intern() so that unicode strings can be
Walter Dörwald <walter@livinglogic.de>
parents: 41956
diff changeset
251 "can't intern %.400s", s->ob_type->tp_name);
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
252 return NULL;
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
253 }
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
254 }
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
255
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
256 PyDoc_STRVAR(intern_doc,
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
257 "intern(string) -> string\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
258 \n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
259 ``Intern'' the given string. This enters the string in the (global)\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
260 table of interned strings whose purpose is to speed up dictionary lookups.\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
261 Return the string itself or the previously interned string object with the\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
262 same value.");
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
263
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
264
18326
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 * 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
267 * 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
268 */
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
269 static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
270
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
271 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
272 trace_init(void)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
273 {
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
274 static char *whatnames[7] = {"call", "exception", "line", "return",
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
275 "c_call", "c_exception", "c_return"};
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
276 PyObject *name;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
277 int i;
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
278 for (i = 0; i < 7; ++i) {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
279 if (whatstrings[i] == NULL) {
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41981
diff changeset
280 name = PyUnicode_InternFromString(whatnames[i]);
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
281 if (name == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
282 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
283 whatstrings[i] = name;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
284 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
285 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
286 return 0;
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
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
289
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
290 static PyObject *
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
291 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
292 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
293 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
294 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
295 PyObject *whatstr;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
296 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
297
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
298 if (args == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
299 return NULL;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
300 Py_INCREF(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
301 whatstr = whatstrings[what];
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
302 Py_INCREF(whatstr);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
303 if (arg == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
304 arg = Py_None;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
305 Py_INCREF(arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
306 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
307 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
308 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
309
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
310 /* 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
311 PyFrame_FastToLocals(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
312 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
313 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
314 if (result == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
315 PyTraceBack_Here(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
316
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
317 /* cleanup */
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
318 Py_DECREF(args);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
319 return result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
320 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
321
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
322 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
323 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
324 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
325 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
326 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
327 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
328
20247
a4d328d50897 Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents: 19343
diff changeset
329 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
330 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
331 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
332 if (result == NULL) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
333 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
334 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
335 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
336 Py_DECREF(result);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
337 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
338 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
339
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
340 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
341 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
342 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
343 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
344 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
345 PyObject *callback;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
346 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
347
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
348 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
349 callback = self;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
350 else
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
351 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
352 if (callback == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
353 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
354 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
355 if (result == NULL) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
356 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
357 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
358 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
359 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
360 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
361 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
362 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
363 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
364 Py_XDECREF(temp);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
365 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
366 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
367 else {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
368 Py_DECREF(result);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
369 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
370 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
371 }
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
372
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
373 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
374 sys_settrace(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
375 {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
376 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
377 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
378 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
379 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
380 else
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
381 PyEval_SetTrace(trace_trampoline, args);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
382 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
383 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
384 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
385
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
386 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
387 "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
388 \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
389 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
390 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
391 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
392
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
393 static PyObject *
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
394 sys_gettrace(PyObject *self, PyObject *args)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
395 {
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
396 PyThreadState *tstate = PyThreadState_GET();
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
397 PyObject *temp = tstate->c_traceobj;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
398
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
399 if (temp == NULL)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
400 temp = Py_None;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
401 Py_INCREF(temp);
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
402 return temp;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
403 }
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
404
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
405 PyDoc_STRVAR(gettrace_doc,
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
406 "gettrace()\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
407 \n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
408 Return the global debug tracing function set with sys.settrace.\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
409 See the debugger chapter in the library manual."
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
410 );
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
411
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
412 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
413 sys_setprofile(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
414 {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
415 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
416 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
417 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
418 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
419 else
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
420 PyEval_SetProfile(profile_trampoline, args);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
421 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
422 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
423 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
424
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
425 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
426 "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
427 \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
428 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
429 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
430 );
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
431
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
432 static PyObject *
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
433 sys_getprofile(PyObject *self, PyObject *args)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
434 {
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
435 PyThreadState *tstate = PyThreadState_GET();
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
436 PyObject *temp = tstate->c_profileobj;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
437
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
438 if (temp == NULL)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
439 temp = Py_None;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
440 Py_INCREF(temp);
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
441 return temp;
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
442 }
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
443
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
444 PyDoc_STRVAR(getprofile_doc,
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
445 "getprofile()\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
446 \n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
447 Return the profiling function set with sys.setprofile.\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
448 See the profiler chapter in the library manual."
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
449 );
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
450
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
451 static int _check_interval = 100;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
452
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
453 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
454 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
455 {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
456 if (PyErr_WarnEx(PyExc_DeprecationWarning,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
457 "sys.getcheckinterval() and sys.setcheckinterval() "
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
458 "are deprecated. Use sys.setswitchinterval() "
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
459 "instead.", 1) < 0)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
460 return NULL;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
461 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval))
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
462 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
463 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
464 return Py_None;
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
465 }
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
466
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
467 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
468 "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
469 \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
470 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
471 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
472 );
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
473
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
474 static PyObject *
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
475 sys_getcheckinterval(PyObject *self, PyObject *args)
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
476 {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
477 if (PyErr_WarnEx(PyExc_DeprecationWarning,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
478 "sys.getcheckinterval() and sys.setcheckinterval() "
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
479 "are deprecated. Use sys.getswitchinterval() "
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
480 "instead.", 1) < 0)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
481 return NULL;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
482 return PyLong_FromLong(_check_interval);
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
483 }
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
484
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
485 PyDoc_STRVAR(getcheckinterval_doc,
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
486 "getcheckinterval() -> current check interval; see setcheckinterval()."
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
487 );
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
488
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
489 #ifdef WITH_THREAD
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
490 static PyObject *
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
491 sys_setswitchinterval(PyObject *self, PyObject *args)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
492 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
493 double d;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
494 if (!PyArg_ParseTuple(args, "d:setswitchinterval", &d))
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
495 return NULL;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
496 if (d <= 0.0) {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
497 PyErr_SetString(PyExc_ValueError,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
498 "switch interval must be strictly positive");
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
499 return NULL;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
500 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
501 _PyEval_SetSwitchInterval((unsigned long) (1e6 * d));
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
502 Py_INCREF(Py_None);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
503 return Py_None;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
504 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
505
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
506 PyDoc_STRVAR(setswitchinterval_doc,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
507 "setswitchinterval(n)\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
508 \n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
509 Set the ideal thread switching delay inside the Python interpreter\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
510 The actual frequency of switching threads can be lower if the\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
511 interpreter executes long sequences of uninterruptible code\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
512 (this is implementation-specific and workload-dependent).\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
513 \n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
514 The parameter must represent the desired switching delay in seconds\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
515 A typical value is 0.005 (5 milliseconds)."
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
516 );
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
517
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
518 static PyObject *
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
519 sys_getswitchinterval(PyObject *self, PyObject *args)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
520 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
521 return PyFloat_FromDouble(1e-6 * _PyEval_GetSwitchInterval());
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
522 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
523
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
524 PyDoc_STRVAR(getswitchinterval_doc,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
525 "getswitchinterval() -> current thread switch interval; see setswitchinterval()."
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
526 );
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
527
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
528 #endif /* WITH_THREAD */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
529
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
530 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
531 static PyObject *
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
532 sys_settscdump(PyObject *self, PyObject *args)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
533 {
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
534 int bool;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
535 PyThreadState *tstate = PyThreadState_Get();
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
536
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
537 if (!PyArg_ParseTuple(args, "i:settscdump", &bool))
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
538 return NULL;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
539 if (bool)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
540 tstate->interp->tscdump = 1;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
541 else
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
542 tstate->interp->tscdump = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
543 Py_INCREF(Py_None);
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
544 return Py_None;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
545
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
546 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
547
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
548 PyDoc_STRVAR(settscdump_doc,
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
549 "settscdump(bool)\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
550 \n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
551 If true, tell the Python interpreter to dump VM measurements to\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
552 stderr. If false, turn off dump. The measurements are based on the\n\
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 32344
diff changeset
553 processor's time-stamp counter."
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
554 );
32344
748129e6e108 Remove compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 32301
diff changeset
555 #endif /* TSC */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
556
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
557 static PyObject *
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
558 sys_setrecursionlimit(PyObject *self, PyObject *args)
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
559 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
560 int new_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
561 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
562 return NULL;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
563 if (new_limit <= 0) {
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
564 PyErr_SetString(PyExc_ValueError,
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
565 "recursion limit must be positive");
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
566 return NULL;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
567 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
568 Py_SetRecursionLimit(new_limit);
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
569 Py_INCREF(Py_None);
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
570 return Py_None;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
571 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
572
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
573 PyDoc_STRVAR(setrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
574 "setrecursionlimit(n)\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
575 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
576 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
577 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
578 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
579 dependent."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
580 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
581
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
582 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
583 sys_getrecursionlimit(PyObject *self)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
584 {
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
585 return PyLong_FromLong(Py_GetRecursionLimit());
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
586 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
587
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
588 PyDoc_STRVAR(getrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
589 "getrecursionlimit()\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
590 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
591 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
592 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
593 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
594 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
595
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
596 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
597 PyDoc_STRVAR(getwindowsversion_doc,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
598 "getwindowsversion()\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
599 \n\
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
600 Return information about the running version of Windows as a named tuple.\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
601 The members are named: major, minor, build, platform, service_pack,\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
602 service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
603 backward compatibiliy, only the first 5 items are available by indexing.\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
604 All elements are numbers, except service_pack which is a string. Platform\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
605 may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
606 3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
607 controller, 3 for a server."
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
608 );
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
609
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
610 static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0};
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
611
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
612 static PyStructSequence_Field windows_version_fields[] = {
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
613 {"major", "Major version number"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
614 {"minor", "Minor version number"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
615 {"build", "Build number"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
616 {"platform", "Operating system platform"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
617 {"service_pack", "Latest Service Pack installed on the system"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
618 {"service_pack_major", "Service Pack major version number"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
619 {"service_pack_minor", "Service Pack minor version number"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
620 {"suite_mask", "Bit mask identifying available product suites"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
621 {"product_type", "System product type"},
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
622 {0}
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
623 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
624
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
625 static PyStructSequence_Desc windows_version_desc = {
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
626 "sys.getwindowsversion", /* name */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
627 getwindowsversion_doc, /* doc */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
628 windows_version_fields, /* fields */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
629 5 /* For backward compatibility,
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
630 only the first 5 items are accessible
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
631 via indexing, the rest are name only */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
632 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
633
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
634 static PyObject *
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
635 sys_getwindowsversion(PyObject *self)
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
636 {
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
637 PyObject *version;
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
638 int pos = 0;
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
639 OSVERSIONINFOEX ver;
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
640 ver.dwOSVersionInfoSize = sizeof(ver);
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
641 if (!GetVersionEx((OSVERSIONINFO*) &ver))
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
642 return PyErr_SetFromWindowsErr(0);
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
643
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
644 version = PyStructSequence_New(&WindowsVersionType);
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
645 if (version == NULL)
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
646 return NULL;
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
647
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
648 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMajorVersion));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
649 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
650 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
651 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
652 PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromString(ver.szCSDVersion));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
653 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
654 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
655 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
656 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
657
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
658 return version;
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
659 }
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
660
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
661 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
662
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
663 #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
664 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
665 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
666 {
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
667 int new_val;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
668 PyThreadState *tstate = PyThreadState_GET();
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
669 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
670 return NULL;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
671 if (!tstate)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
672 return NULL;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
673 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
674 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
675 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
676 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
677
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
678 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
679 "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
680 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
681 Set the flags used by the interpreter for dlopen calls, such as when the\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
682 interpreter loads extension modules. Among other things, this will enable\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
683 a lazy resolving of symbols when importing a module, if called as\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
684 sys.setdlopenflags(0). To share symbols across extension modules, call as\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
685 sys.setdlopenflags(ctypes.RTLD_GLOBAL). Symbolic names for the flag modules\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
686 can be either found in the ctypes module, or in the DLFCN module. If DLFCN\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
687 is not available, it can be generated from /usr/include/dlfcn.h using the\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
688 h2py script.");
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
690 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
691 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
692 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
693 PyThreadState *tstate = PyThreadState_GET();
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
694 if (!tstate)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
695 return NULL;
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
696 return PyLong_FromLong(tstate->interp->dlopenflags);
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
697 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
698
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
699 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
700 "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
701 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
702 Return the current value of the flags that are used for dlopen calls.\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
703 The flag constants are defined in the ctypes and DLFCN modules.");
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
704
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
705 #endif /* HAVE_DLOPEN */
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
706
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
707 #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
708 /* 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
709 #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
710
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
711 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
712 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
713 {
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
714 int flag;
12136
9b9abde032b3 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
715 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
716 return NULL;
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
717 mallopt(M_DEBUG, flag);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
718 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
719 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
720 }
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
721 #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
722
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
723 static PyObject *
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
724 sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
725 {
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
726 PyObject *res = NULL;
53954
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
727 static PyObject *str__sizeof__ = NULL, *gc_head_size = NULL;
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
728 static char *kwlist[] = {"object", "default", 0};
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
729 PyObject *o, *dflt = NULL;
48477
e26c724d5e23 Make these files to compile again under Windows.
Thomas Heller <theller@ctypes.org>
parents: 48470
diff changeset
730 PyObject *method;
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
731
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
732 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
733 kwlist, &o, &dflt))
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
734 return NULL;
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
735
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
736 /* Initialize static variable for GC head size */
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
737 if (gc_head_size == NULL) {
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
738 gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head));
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
739 if (gc_head_size == NULL)
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
740 return NULL;
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
741 }
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
742
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
743 /* Make sure the type is initialized. float gets initialized late */
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
744 if (PyType_Ready(Py_TYPE(o)) < 0)
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
745 return NULL;
53954
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
746
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
747 method = _PyObject_LookupSpecial(o, "__sizeof__",
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
748 &str__sizeof__);
54326
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
749 if (method == NULL) {
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
750 if (!PyErr_Occurred())
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
751 PyErr_Format(PyExc_TypeError,
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
752 "Type %.100s doesn't define __sizeof__",
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
753 Py_TYPE(o)->tp_name);
db212869d814 Merged revisions 72907 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 54292
diff changeset
754 }
53954
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
755 else {
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
756 res = PyObject_CallFunctionObjArgs(method, NULL);
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
757 Py_DECREF(method);
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
758 }
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
759
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
760 /* Has a default value been given */
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
761 if ((res == NULL) && (dflt != NULL) &&
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
762 PyErr_ExceptionMatches(PyExc_TypeError))
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
763 {
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
764 PyErr_Clear();
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
765 Py_INCREF(dflt);
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
766 return dflt;
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
767 }
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
768 else if (res == NULL)
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
769 return res;
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
770
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
771 /* add gc_head size */
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
772 if (PyObject_IS_GC(o)) {
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
773 PyObject *tmp = res;
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
774 res = PyNumber_Add(tmp, gc_head_size);
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
775 Py_DECREF(tmp);
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
776 }
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
777 return res;
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
778 }
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
779
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
780 PyDoc_STRVAR(getsizeof_doc,
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
781 "getsizeof(object, default) -> int\n\
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
782 \n\
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
783 Return the size of object in bytes.");
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
784
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
785 static PyObject *
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
786 sys_getrefcount(PyObject *self, PyObject *arg)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
787 {
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
788 return PyLong_FromSsize_t(arg->ob_refcnt);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
789 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
790
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
791 #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
792 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
793 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
794 {
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
795 return PyLong_FromSsize_t(_Py_GetRefTotal());
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
796 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
797 #endif /* 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
798
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
799 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
800 "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
801 \n\
23947
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
802 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
803 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
804 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
805 );
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
806
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
807 #ifdef COUNT_ALLOCS
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
808 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
809 sys_getcounts(PyObject *self)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
810 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
811 extern PyObject *get_counts(void);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
812
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
813 return get_counts();
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
814 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
815 #endif
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
816
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
817 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
818 "_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
819 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
820 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
821 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
822 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
823 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
824 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
825 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
826 purposes only."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
827 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
828
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
829 static PyObject *
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
830 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
831 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
832 PyFrameObject *f = PyThreadState_GET()->frame;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
833 int depth = -1;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
834
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
835 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
836 return NULL;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
837
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
838 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
839 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
840 --depth;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
841 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
842 if (f == NULL) {
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
843 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
844 "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
845 return NULL;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
846 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
847 Py_INCREF(f);
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
848 return (PyObject*)f;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
849 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
850
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
851 PyDoc_STRVAR(current_frames_doc,
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
852 "_current_frames() -> dictionary\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
853 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
854 Return a dictionary mapping each current thread T's thread id to T's\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
855 current stack frame.\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
856 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
857 This function should be used for specialized purposes only."
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
858 );
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
859
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
860 static PyObject *
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
861 sys_current_frames(PyObject *self, PyObject *noargs)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
862 {
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
863 return _PyThread_CurrentFrames();
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
864 }
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
865
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
866 PyDoc_STRVAR(call_tracing_doc,
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
867 "call_tracing(func, args) -> object\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
868 \n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
869 Call func(*args), while tracing is enabled. The tracing state is\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
870 saved, and restored afterwards. This is intended to be called from\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
871 a debugger from a checkpoint, to recursively debug some other code."
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
872 );
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
873
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
874 static PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
875 sys_call_tracing(PyObject *self, PyObject *args)
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
876 {
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
877 PyObject *func, *funcargs;
49537
2c3a6c9dff62 Benjamin Peterson's patch to fix bug 3661, sys.call_tracing segfaults.
Barry Warsaw <barry@python.org>
parents: 49536
diff changeset
878 if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs))
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
879 return NULL;
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
880 return _PyEval_CallTracing(func, funcargs);
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
881 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
882
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
883 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
884 "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
885 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
886 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
887 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
888 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
889 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
890 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
891 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
892 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
893 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
894 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
895 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
896 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
897 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
898 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
899 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
900 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
901 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
902 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
903 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
904 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
905
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
906 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
907 extern "C" {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
908 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
909
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
910 #ifdef Py_TRACE_REFS
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
911 /* 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
912 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
913 #endif
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
914
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
915 #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
916 /* 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
917 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
918 #endif
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
919
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
920 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
921 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
922 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
923
45145
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
924 static PyObject *
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
925 sys_clear_type_cache(PyObject* self, PyObject* args)
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
926 {
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
927 PyType_ClearCache();
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
928 Py_RETURN_NONE;
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
929 }
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
930
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
931 PyDoc_STRVAR(sys_clear_type_cache__doc__,
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
932 "_clear_type_cache() -> None\n\
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
933 Clear the internal type lookup cache.");
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
934
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
935
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
936 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
937 /* Might as well keep this in alphabetic order */
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
938 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
939 callstats_doc},
45145
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
940 {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
941 sys_clear_type_cache__doc__},
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
942 {"_current_frames", sys_current_frames, METH_NOARGS,
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
943 current_frames_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
944 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
945 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_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
946 {"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
947 {"exit", sys_exit, METH_VARARGS, exit_doc},
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
948 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
949 METH_NOARGS, getdefaultencoding_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
950 #ifdef HAVE_DLOPEN
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
951 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
952 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
953 #endif
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
954 #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
955 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
956 #endif
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
957 #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
958 {"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
959 #endif
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
960 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
961 METH_NOARGS, getfilesystemencoding_doc},
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
962 #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
963 {"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
964 #endif
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
965 #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
966 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
967 #endif
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
968 {"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
969 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
970 getrecursionlimit_doc},
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
971 {"getsizeof", (PyCFunction)sys_getsizeof,
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
972 METH_VARARGS | METH_KEYWORDS, getsizeof_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
973 {"_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
974 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
975 {"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
976 getwindowsversion_doc},
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
977 #endif /* MS_WINDOWS */
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
978 {"intern", sys_intern, METH_VARARGS, intern_doc},
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
979 #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
980 {"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
981 #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
982 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
983 setdefaultencoding_doc},
49403
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
984 {"setfilesystemencoding", sys_setfilesystemencoding, METH_VARARGS,
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
985 setfilesystemencoding_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
986 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
987 setcheckinterval_doc},
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
988 {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
989 getcheckinterval_doc},
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
990 #ifdef WITH_THREAD
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
991 {"setswitchinterval", sys_setswitchinterval, METH_VARARGS,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
992 setswitchinterval_doc},
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
993 {"getswitchinterval", sys_getswitchinterval, METH_NOARGS,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
994 getswitchinterval_doc},
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
995 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
996 #ifdef HAVE_DLOPEN
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
997 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
998 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
999 #endif
22119
0859e764509e SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents: 21833
diff changeset
1000 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1001 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_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
1002 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
1003 setrecursionlimit_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
1004 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
1005 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
1006 #endif
22119
0859e764509e SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents: 21833
diff changeset
1007 {"settrace", sys_settrace, METH_O, settrace_doc},
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1008 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1009 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1010 {NULL, NULL} /* sentinel */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1011 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1012
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1013 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1014 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
1015 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1016 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
1017 int i;
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1018 if (list == NULL)
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1019 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
1020 for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41981
diff changeset
1021 PyObject *name = PyUnicode_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
1022 PyImport_Inittab[i].name);
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1023 if (name == NULL)
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1024 break;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1025 PyList_Append(list, name);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1026 Py_DECREF(name);
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1027 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1028 if (PyList_Sort(list) != 0) {
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1029 Py_DECREF(list);
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
1030 list = NULL;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
1031 }
4904
5dc20a9e0506 Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
1032 if (list) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1033 PyObject *v = PyList_AsTuple(list);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1034 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
1035 list = v;
5dc20a9e0506 Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
1036 }
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1037 return list;
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1038 }
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1039
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1040 static PyObject *warnoptions = NULL;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1041
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1042 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1043 PySys_ResetWarnOptions(void)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1044 {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1045 if (warnoptions == NULL || !PyList_Check(warnoptions))
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1046 return;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1047 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
1048 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1049
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1050 void
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1051 PySys_AddWarnOption(const wchar_t *s)
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1052 {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1053 PyObject *str;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1054
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1055 if (warnoptions == NULL || !PyList_Check(warnoptions)) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1056 Py_XDECREF(warnoptions);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1057 warnoptions = PyList_New(0);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1058 if (warnoptions == NULL)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1059 return;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1060 }
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1061 str = PyUnicode_FromWideChar(s, -1);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1062 if (str != NULL) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1063 PyList_Append(warnoptions, str);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1064 Py_DECREF(str);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1065 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1066 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1067
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1068 int
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1069 PySys_HasWarnOptions(void)
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1070 {
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1071 return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0;
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1072 }
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1073
8840
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
1074 /* 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
1075 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
1076 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
1077 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
1078 PyDoc_VAR(sys_doc) =
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1079 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
1080 "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
1081 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
1082 \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
1083 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
1084 \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
1085 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
1086 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
1087 modules -- dictionary of loaded modules\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1088 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1089 displayhook -- called to show results in an interactive session\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1090 excepthook -- called to handle any uncaught exception other than SystemExit\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1091 To customize printing in an interactive session or to install a custom\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1092 top-level exception handler, assign other functions to replace these.\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1093 \n\
48470
3d868254ff7e correct docstring
Benjamin Peterson <benjamin@python.org>
parents: 48467
diff changeset
1094 stdin -- standard input file object; used by input()\n\
40788
e9a6234b26af * Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
Georg Brandl <georg@python.org>
parents: 40737
diff changeset
1095 stdout -- standard output file object; used by print()\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
1096 stderr -- standard error object; used for error messages\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1097 By assigning other file objects (or objects that behave like files)\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1098 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
1099 \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
1100 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
1101 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
1102 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
1103 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
1104 traceback has been printed.\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
1105 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1106 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1107 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1108 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
1109 "\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
1110 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
1111 \n\
44311
303727c58b51 Fixed #1630
Christian Heimes <christian@cheimes.de>
parents: 44160
diff changeset
1112 float_info -- a dict with information about the float implementation.\n\
52215
bb5de24a343f Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents: 51378
diff changeset
1113 int_info -- a struct sequence with information about the int implementation.\n\
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42896
diff changeset
1114 maxsize -- the largest supported length of containers.\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
1115 maxunicode -- the largest supported character\n\
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21712
diff changeset
1116 builtin_module_names -- tuple of module names built into this interpreter\n\
44311
303727c58b51 Fixed #1630
Christian Heimes <christian@cheimes.de>
parents: 44160
diff changeset
1117 subversion -- subversion information of the build as tuple\n\
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1118 version -- the version of this interpreter as a string\n\
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1119 version_info -- version information as a named tuple\n\
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1120 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
1121 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
1122 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
1123 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
1124 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
1125 exec_prefix -- prefix used to find the machine-specific Python library\n\
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1126 float_repr_style -- string indicating the style of repr() output for floats\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1127 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1128 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1129 #ifdef MS_WINDOWS
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1130 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1131 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1132 "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
1133 winver -- [Windows only] version number of the Python DLL\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1134 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1135 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1136 #endif /* MS_WINDOWS */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1137 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1138 "__stdin__ -- the original stdin; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1139 __stdout__ -- the original stdout; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1140 __stderr__ -- the original stderr; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1141 __displayhook__ -- the original displayhook; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1142 __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
1143 \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
1144 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
1145 \n\
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 44086
diff changeset
1146 displayhook() -- print an object to the screen, and save it in builtins._\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1147 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
1148 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
1149 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
1150 getdlopenflags() -- returns flags to be used for dlopen() calls\n\
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1151 getprofile() -- get the global profiling function\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
1152 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
1153 getrecursionlimit() -- return the max recursion depth for the interpreter\n\
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
1154 getsizeof() -- return the size of an object in bytes\n\
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1155 gettrace() -- get the global debug tracing function\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
1156 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
1157 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
1158 setprofile() -- set the global profiling function\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
1159 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
1160 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
1161 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1162 )
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
1163 /* 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
1164
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1165 /* Subversion branch and revision management */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1166 static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1167 static const char headurl[] = "$HeadURL$";
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1168 static int svn_initialized;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1169 static char patchlevel_revision[50]; /* Just the number */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1170 static char branch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1171 static char shortbranch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1172 static const char *svn_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1173
36212
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
1174 static void
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
1175 svnversion_init(void)
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1176 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1177 const char *python, *br_start, *br_end, *br_end2, *svnversion;
36521
30aef3ce2b26 Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1178 Py_ssize_t len;
42703
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1179 int istag = 0;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1180
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1181 if (svn_initialized)
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1182 return;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1183
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1184 python = strstr(headurl, "/python/");
42703
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1185 if (!python) {
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1186 strcpy(branch, "unknown branch");
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1187 strcpy(shortbranch, "unknown");
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1188 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1189 else {
42703
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1190 br_start = python + 8;
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1191 br_end = strchr(br_start, '/');
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1192 assert(br_end);
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1193
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1194 /* Works even for trunk,
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1195 as we are in trunk/Python/sysmodule.c */
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1196 br_end2 = strchr(br_end+1, '/');
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1197
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1198 istag = strncmp(br_start, "tags", 4) == 0;
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1199 if (strncmp(br_start, "trunk", 5) == 0) {
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1200 strcpy(branch, "trunk");
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1201 strcpy(shortbranch, "trunk");
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1202 }
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1203 else if (istag || strncmp(br_start, "branches", 8) == 0) {
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1204 len = br_end2 - br_start;
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1205 strncpy(branch, br_start, len);
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1206 branch[len] = '\0';
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1207
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1208 len = br_end2 - (br_end + 1);
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1209 strncpy(shortbranch, br_end + 1, len);
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1210 shortbranch[len] = '\0';
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1211 }
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1212 else {
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1213 Py_FatalError("bad HeadURL");
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1214 return;
8bad8722f0e6 Patch #1774414: make it possible to use SVK to develop Python.
Collin Winter <collinw@gmail.com>
parents: 42622
diff changeset
1215 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1216 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1217
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1218
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1219 svnversion = _Py_svnversion();
54292
89631f627810 Merged revisions 72871-72872 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53954
diff changeset
1220 if (strcmp(svnversion, "Unversioned directory") != 0 && strcmp(svnversion, "exported") != 0)
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1221 svn_revision = svnversion;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1222 else if (istag) {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1223 len = strlen(_patchlevel_revision);
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41253
diff changeset
1224 assert(len >= 13);
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41253
diff changeset
1225 assert(len < (sizeof(patchlevel_revision) + 13));
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1226 strncpy(patchlevel_revision, _patchlevel_revision + 11,
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1227 len - 13);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1228 patchlevel_revision[len - 13] = '\0';
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1229 svn_revision = patchlevel_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1230 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1231 else
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1232 svn_revision = "";
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1233
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1234 svn_initialized = 1;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1235 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1236
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1237 /* Return svnversion output if available.
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1238 Else return Revision of patchlevel.h if on branch.
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1239 Else return empty string */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1240 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1241 Py_SubversionRevision()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1242 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1243 svnversion_init();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1244 return svn_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1245 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1246
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1247 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1248 Py_SubversionShortBranch()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1249 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1250 svnversion_init();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1251 return shortbranch;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1252 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1253
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1254
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1255 PyDoc_STRVAR(flags__doc__,
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1256 "sys.flags\n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1257 \n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1258 Flags provided through command line arguments or environment vars.");
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1259
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1260 static PyTypeObject FlagsType;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1261
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1262 static PyStructSequence_Field flags_fields[] = {
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1263 {"debug", "-d"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1264 {"division_warning", "-Q"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1265 {"inspect", "-i"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1266 {"interactive", "-i"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1267 {"optimize", "-O or -OO"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1268 {"dont_write_bytecode", "-B"},
46708
74b9c85361f8 Merged revisions 62774-62775,62785,62787-62788 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46478
diff changeset
1269 {"no_user_site", "-s"},
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1270 {"no_site", "-S"},
44699
6f049ca55e06 Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 44674
diff changeset
1271 {"ignore_environment", "-E"},
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1272 {"verbose", "-v"},
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1273 #ifdef RISCOS
44699
6f049ca55e06 Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 44674
diff changeset
1274 {"riscos_wimp", "???"},
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1275 #endif
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1276 /* {"unbuffered", "-u"}, */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1277 /* {"skip_first", "-x"}, */
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1278 {"bytes_warning", "-b"},
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1279 {0}
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1280 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1281
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1282 static PyStructSequence_Desc flags_desc = {
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1283 "sys.flags", /* name */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1284 flags__doc__, /* doc */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1285 flags_fields, /* fields */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1286 #ifdef RISCOS
47489
7a1d4e8233f8 Fix sys.flags sequence behavior and add a test case.
Georg Brandl <georg@python.org>
parents: 47466
diff changeset
1287 12
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1288 #else
47489
7a1d4e8233f8 Fix sys.flags sequence behavior and add a test case.
Georg Brandl <georg@python.org>
parents: 47466
diff changeset
1289 11
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1290 #endif
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1291 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1292
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1293 static PyObject*
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1294 make_flags(void)
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1295 {
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1296 int pos = 0;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1297 PyObject *seq;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1298
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1299 seq = PyStructSequence_New(&FlagsType);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1300 if (seq == NULL)
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1301 return NULL;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1302
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1303 #define SetFlag(flag) \
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1304 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1305
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1306 SetFlag(Py_DebugFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1307 SetFlag(Py_DivisionWarningFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1308 SetFlag(Py_InspectFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1309 SetFlag(Py_InteractiveFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1310 SetFlag(Py_OptimizeFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1311 SetFlag(Py_DontWriteBytecodeFlag);
46708
74b9c85361f8 Merged revisions 62774-62775,62785,62787-62788 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46478
diff changeset
1312 SetFlag(Py_NoUserSiteDirectory);
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1313 SetFlag(Py_NoSiteFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1314 SetFlag(Py_IgnoreEnvironmentFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1315 SetFlag(Py_VerboseFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1316 #ifdef RISCOS
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1317 SetFlag(Py_RISCOSWimpFlag);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1318 #endif
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1319 /* SetFlag(saw_unbuffered_flag); */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1320 /* SetFlag(skipfirstline); */
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1321 SetFlag(Py_BytesWarningFlag);
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1322 #undef SetFlag
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1323
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1324 if (PyErr_Occurred()) {
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1325 return NULL;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1326 }
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1327 return seq;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1328 }
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1329
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1330 PyDoc_STRVAR(version_info__doc__,
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1331 "sys.version_info\n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1332 \n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1333 Version information as a named tuple.");
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1334
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1335 static PyTypeObject VersionInfoType;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1336
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1337 static PyStructSequence_Field version_info_fields[] = {
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1338 {"major", "Major release number"},
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1339 {"minor", "Minor release number"},
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1340 {"micro", "Patch release number"},
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1341 {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1342 {"serial", "Serial release number"},
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1343 {0}
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1344 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1345
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1346 static PyStructSequence_Desc version_info_desc = {
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1347 "sys.version_info", /* name */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1348 version_info__doc__, /* doc */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1349 version_info_fields, /* fields */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1350 5
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1351 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1352
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1353 static PyObject *
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1354 make_version_info(void)
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1355 {
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1356 PyObject *version_info;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1357 char *s;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1358 int pos = 0;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1359
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1360 version_info = PyStructSequence_New(&VersionInfoType);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1361 if (version_info == NULL) {
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1362 return NULL;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1363 }
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1364
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1365 /*
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1366 * These release level checks are mutually exclusive and cover
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1367 * the field, so don't get too fancy with the pre-processor!
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1368 */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1369 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1370 s = "alpha";
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1371 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1372 s = "beta";
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1373 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1374 s = "candidate";
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1375 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1376 s = "final";
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1377 #endif
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1379 #define SetIntItem(flag) \
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1380 PyStructSequence_SET_ITEM(version_info, pos++, PyLong_FromLong(flag))
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1381 #define SetStrItem(flag) \
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1382 PyStructSequence_SET_ITEM(version_info, pos++, PyUnicode_FromString(flag))
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1383
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1384 SetIntItem(PY_MAJOR_VERSION);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1385 SetIntItem(PY_MINOR_VERSION);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1386 SetIntItem(PY_MICRO_VERSION);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1387 SetStrItem(s);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1388 SetIntItem(PY_RELEASE_SERIAL);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1389 #undef SetIntItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1390 #undef SetStrItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1391
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1392 if (PyErr_Occurred()) {
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1393 Py_CLEAR(version_info);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1394 return NULL;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1395 }
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1396 return version_info;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1397 }
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1398
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1399 static struct PyModuleDef sysmodule = {
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1400 PyModuleDef_HEAD_INIT,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1401 "sys",
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1402 sys_doc,
49613
efef5fc45a9a Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents: 49537
diff changeset
1403 -1, /* multiple "initialization" just copies the module dict. */
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1404 sys_methods,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1405 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1406 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1407 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1408 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1409 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1410
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1411 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1412 _PySys_Init(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1413 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1414 PyObject *m, *v, *sysdict;
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1415 char *s;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1416
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1417 m = PyModule_Create(&sysmodule);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36212
diff changeset
1418 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36212
diff changeset
1419 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1420 sysdict = PyModule_GetDict(m);
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1421 #define SET_SYS_FROM_STRING(key, value) \
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1422 v = value; \
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1423 if (v != NULL) \
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1424 PyDict_SetItemString(sysdict, key, v); \
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1425 Py_XDECREF(v)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1426
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1427 /* Check that stdin is not a directory
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1428 Using shell redirection, you can redirect stdin to a directory,
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1429 crashing the Python interpreter. Catch this common mistake here
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1430 and output a useful error message. Note that under MS Windows,
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1431 the shell already prevents that. */
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1432 #if !defined(MS_WINDOWS)
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1433 {
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1434 struct stat sb;
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1435 if (fstat(fileno(stdin), &sb) == 0 &&
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1436 S_ISDIR(sb.st_mode)) {
36910
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1437 /* There's nothing more we can do. */
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1438 /* Py_FatalError() will core dump, so just exit. */
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1439 PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1440 exit(EXIT_FAILURE);
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1441 }
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1442 }
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1443 #endif
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1444
44368
32dd9b7773c3 Fix thoroughly misleading comment
Nick Coghlan <ncoghlan@gmail.com>
parents: 44311
diff changeset
1445 /* stdin/stdout/stderr are now set by pythonrun.c */
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1446
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1447 PyDict_SetItemString(sysdict, "__displayhook__",
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46430
diff changeset
1448 PyDict_GetItemString(sysdict, "displayhook"));
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1449 PyDict_SetItemString(sysdict, "__excepthook__",
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46430
diff changeset
1450 PyDict_GetItemString(sysdict, "excepthook"));
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1451 SET_SYS_FROM_STRING("version",
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1452 PyUnicode_FromString(Py_GetVersion()));
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1453 SET_SYS_FROM_STRING("hexversion",
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1454 PyLong_FromLong(PY_VERSION_HEX));
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1455 svnversion_init();
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1456 SET_SYS_FROM_STRING("subversion",
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1457 Py_BuildValue("(UUU)", "CPython", branch,
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1458 svn_revision));
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1459 SET_SYS_FROM_STRING("dont_write_bytecode",
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46430
diff changeset
1460 PyBool_FromLong(Py_DontWriteBytecodeFlag));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1461 SET_SYS_FROM_STRING("api_version",
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
1462 PyLong_FromLong(PYTHON_API_VERSION));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1463 SET_SYS_FROM_STRING("copyright",
41981
c6a0b75dbec2 Change most sys attributes that were str8 objects into str objects
Walter Dörwald <walter@livinglogic.de>
parents: 41969
diff changeset
1464 PyUnicode_FromString(Py_GetCopyright()));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1465 SET_SYS_FROM_STRING("platform",
41981
c6a0b75dbec2 Change most sys attributes that were str8 objects into str objects
Walter Dörwald <walter@livinglogic.de>
parents: 41969
diff changeset
1466 PyUnicode_FromString(Py_GetPlatform()));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1467 SET_SYS_FROM_STRING("executable",
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1468 PyUnicode_FromWideChar(
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1469 Py_GetProgramFullPath(), -1));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1470 SET_SYS_FROM_STRING("prefix",
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1471 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1472 SET_SYS_FROM_STRING("exec_prefix",
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1473 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42896
diff changeset
1474 SET_SYS_FROM_STRING("maxsize",
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
1475 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
44086
110ff614ec28 Merged revisions 59245-59254 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43855
diff changeset
1476 SET_SYS_FROM_STRING("float_info",
110ff614ec28 Merged revisions 59245-59254 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43855
diff changeset
1477 PyFloat_GetInfo());
52215
bb5de24a343f Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents: 51378
diff changeset
1478 SET_SYS_FROM_STRING("int_info",
bb5de24a343f Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents: 51378
diff changeset
1479 PyLong_GetInfo());
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1480 SET_SYS_FROM_STRING("maxunicode",
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 44098
diff changeset
1481 PyLong_FromLong(PyUnicode_GetMax()));
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1482 SET_SYS_FROM_STRING("builtin_module_names",
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1483 list_builtin_module_names());
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
1484 {
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1485 /* 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
1486 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
1487 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
1488 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
1489
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1490 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
1491 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
1492 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
1493 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
1494 value = "little";
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1495 SET_SYS_FROM_STRING("byteorder",
41981
c6a0b75dbec2 Change most sys attributes that were str8 objects into str objects
Walter Dörwald <walter@livinglogic.de>
parents: 41969
diff changeset
1496 PyUnicode_FromString(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
1497 }
4126
c80c515999b9 Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents: 3877
diff changeset
1498 #ifdef MS_COREDLL
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1499 SET_SYS_FROM_STRING("dllhandle",
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1500 PyLong_FromVoidPtr(PyWin_DLLhModule));
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1501 SET_SYS_FROM_STRING("winver",
41981
c6a0b75dbec2 Change most sys attributes that were str8 objects into str objects
Walter Dörwald <walter@livinglogic.de>
parents: 41969
diff changeset
1502 PyUnicode_FromString(PyWin_DLLVersionString));
3490
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
1503 #endif
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1504 if (warnoptions == NULL) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1505 warnoptions = PyList_New(0);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1506 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1507 else {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1508 Py_INCREF(warnoptions);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1509 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1510 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
1511 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1512 }
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1513
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1514 /* version_info */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1515 if (VersionInfoType.tp_name == 0)
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1516 PyStructSequence_InitType(&VersionInfoType, &version_info_desc);
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1517 SET_SYS_FROM_STRING("version_info", make_version_info());
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1518 /* prevent user from creating new instances */
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1519 VersionInfoType.tp_init = NULL;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1520 VersionInfoType.tp_new = NULL;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1521
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1522 /* flags */
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1523 if (FlagsType.tp_name == 0)
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1524 PyStructSequence_InitType(&FlagsType, &flags_desc);
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1525 SET_SYS_FROM_STRING("flags", make_flags());
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1526 /* prevent user from creating new instances */
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1527 FlagsType.tp_init = NULL;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1528 FlagsType.tp_new = NULL;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1529
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1530
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1531 #if defined(MS_WINDOWS)
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1532 /* getwindowsversion */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1533 if (WindowsVersionType.tp_name == 0)
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1534 PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc);
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1535 /* prevent user from creating new instances */
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1536 WindowsVersionType.tp_init = NULL;
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1537 WindowsVersionType.tp_new = NULL;
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1538 #endif
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1539
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1540 /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1541 #ifndef PY_NO_SHORT_FLOAT_REPR
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1542 SET_SYS_FROM_STRING("float_repr_style",
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1543 PyUnicode_FromString("short"));
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1544 #else
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1545 SET_SYS_FROM_STRING("float_repr_style",
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1546 PyUnicode_FromString("legacy"));
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1547 #endif
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1548
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1549 #undef SET_SYS_FROM_STRING
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1550 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
1551 return NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1552 return m;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1553 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1554
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1555 static PyObject *
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1556 makepathobject(const wchar_t *path, wchar_t delim)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1557 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1558 int i, n;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1559 const wchar_t *p;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1560 PyObject *v, *w;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1561
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1562 n = 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1563 p = path;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1564 while ((p = wcschr(p, delim)) != NULL) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1565 n++;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1566 p++;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1567 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1568 v = PyList_New(n);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1569 if (v == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1570 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1571 for (i = 0; ; i++) {
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1572 p = wcschr(path, delim);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1573 if (p == NULL)
49536
cbc3afc1e40a Apply Martin's patch for bug 3685, Crash while compiling Python 3000 in
Barry Warsaw <barry@python.org>
parents: 49403
diff changeset
1574 p = path + wcslen(path); /* End of string */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1575 w = PyUnicode_FromWideChar(path, (Py_ssize_t)(p - path));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1576 if (w == NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1577 Py_DECREF(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1578 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1579 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1580 PyList_SetItem(v, i, w);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1581 if (*p == '\0')
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1582 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1583 path = p+1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1584 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1585 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1586 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1587
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1588 void
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1589 PySys_SetPath(const wchar_t *path)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1590 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1591 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1592 if ((v = makepathobject(path, DELIM)) == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1593 Py_FatalError("can't create sys.path");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1594 if (PySys_SetObject("path", v) != 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1595 Py_FatalError("can't assign sys.path");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1596 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
1597 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1598
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1599 static PyObject *
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1600 makeargvobject(int argc, wchar_t **argv)
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1601 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1602 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
1603 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
1604 /* Ensure at least one (empty) argument is seen */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1605 static wchar_t *empty_argv[1] = {L""};
596
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1606 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
1607 argc = 1;
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1608 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1609 av = PyList_New(argc);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1610 if (av != NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1611 int i;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1612 for (i = 0; i < argc; i++) {
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1613 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1614 PyObject *v;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1615
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1616 /* argv[0] is the script pathname if known */
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1617 if (i == 0) {
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1618 char* fn = decc$translate_vms(argv[0]);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1619 if ((fn == (char *)0) || fn == (char *)-1)
42099
6727cc9ed09f Make sys.path and sys.argv into lists of strings.
Guido van Rossum <guido@python.org>
parents: 42071
diff changeset
1620 v = PyUnicode_FromString(argv[0]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1621 else
42099
6727cc9ed09f Make sys.path and sys.argv into lists of strings.
Guido van Rossum <guido@python.org>
parents: 42071
diff changeset
1622 v = PyUnicode_FromString(
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1623 decc$translate_vms(argv[0]));
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1624 } else
42099
6727cc9ed09f Make sys.path and sys.argv into lists of strings.
Guido van Rossum <guido@python.org>
parents: 42071
diff changeset
1625 v = PyUnicode_FromString(argv[i]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1626 #else
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1627 PyObject *v = PyUnicode_FromWideChar(argv[i], -1);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1628 #endif
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1629 if (v == NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1630 Py_DECREF(av);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1631 av = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1632 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1633 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1634 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
1635 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1636 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1637 return av;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1638 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1639
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1640 #ifdef HAVE_REALPATH
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1641 static wchar_t*
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1642 _wrealpath(const wchar_t *path, wchar_t *resolved_path)
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1643 {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1644 char cpath[PATH_MAX];
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1645 char cresolved_path[PATH_MAX];
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1646 char *res;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1647 size_t r;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1648 r = wcstombs(cpath, path, PATH_MAX);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1649 if (r == (size_t)-1 || r >= PATH_MAX) {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1650 errno = EINVAL;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1651 return NULL;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1652 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1653 res = realpath(cpath, cresolved_path);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1654 if (res == NULL)
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1655 return NULL;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1656 r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1657 if (r == (size_t)-1 || r >= PATH_MAX) {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1658 errno = EINVAL;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1659 return NULL;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1660 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1661 return resolved_path;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1662 }
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1663 #endif
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1664
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1665 void
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1666 PySys_SetArgv(int argc, wchar_t **argv)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1667 {
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1668 #if defined(HAVE_REALPATH)
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1669 wchar_t fullpath[MAXPATHLEN];
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1670 #elif defined(MS_WINDOWS) && !defined(MS_WINCE)
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1671 wchar_t fullpath[MAX_PATH];
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1672 #endif
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1673 PyObject *av = makeargvobject(argc, argv);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1674 PyObject *path = PySys_GetObject("path");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1675 if (av == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1676 Py_FatalError("no mem for sys.argv");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1677 if (PySys_SetObject("argv", av) != 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1678 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
1679 if (path != NULL) {
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1680 wchar_t *argv0 = argv[0];
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1681 wchar_t *p = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
1682 Py_ssize_t n = 0;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1683 PyObject *a;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1684 extern int _Py_wreadlink(const wchar_t *, wchar_t *, size_t);
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
1685 #ifdef HAVE_READLINK
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1686 wchar_t link[MAXPATHLEN+1];
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1687 wchar_t argv0copy[2*MAXPATHLEN+1];
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
1688 int nr = 0;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1689 if (argc > 0 && argv0 != NULL && wcscmp(argv0, L"-c") != 0)
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1690 nr = _Py_wreadlink(argv0, link, MAXPATHLEN);
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
1691 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
1692 /* 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
1693 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
1694 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
1695 argv0 = link; /* Link to absolute path */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1696 else if (wcschr(link, SEP) == 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
1697 ; /* 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
1698 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
1699 /* Must join(dirname(argv0), link) */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1700 wchar_t *q = wcsrchr(argv0, SEP);
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
1701 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
1702 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
1703 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
1704 /* Must make a copy */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1705 wcscpy(argv0copy, argv0);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1706 q = wcsrchr(argv0copy, SEP);
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1707 wcscpy(q+1, link);
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
1708 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
1709 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1710 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1711 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1712 #endif /* HAVE_READLINK */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1713 #if SEP == '\\' /* Special case for MS filename syntax */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1714 if (argc > 0 && argv0 != NULL && wcscmp(argv0, L"-c") != 0) {
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1715 wchar_t *q;
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1716 #if defined(MS_WINDOWS) && !defined(MS_WINCE)
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1717 /* This code here replaces the first element in argv with the full
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1718 path that it represents. Under CE, there are no relative paths so
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1719 the argument must be the full path anyway. */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1720 wchar_t *ptemp;
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1721 if (GetFullPathNameW(argv0,
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1722 sizeof(fullpath)/sizeof(fullpath[0]),
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1723 fullpath,
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1724 &ptemp)) {
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1725 argv0 = fullpath;
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1726 }
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1727 #endif
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1728 p = wcsrchr(argv0, SEP);
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1729 /* Test for alternate separator */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1730 q = wcsrchr(p ? p : argv0, '/');
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1731 if (q != NULL)
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1732 p = q;
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1733 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
1734 n = p + 1 - argv0;
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1735 if (n > 1 && p[-1] != ':')
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1736 n--; /* Drop trailing separator */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1737 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1738 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1739 #else /* All other filename syntaxes */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1740 if (argc > 0 && argv0 != NULL && wcscmp(argv0, L"-c") != 0) {
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1741 #if defined(HAVE_REALPATH)
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1742 if (_wrealpath(argv0, fullpath)) {
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1743 argv0 = fullpath;
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1744 }
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1745 #endif
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1746 p = wcsrchr(argv0, SEP);
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1747 }
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1748 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
1749 n = p + 1 - argv0;
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1750 #if SEP == '/' /* Special case for Unix filename syntax */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1751 if (n > 1)
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1752 n--; /* Drop trailing separator */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1753 #endif /* Unix */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1754 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1755 #endif /* All others */
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1756 a = PyUnicode_FromWideChar(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
1757 if (a == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1758 Py_FatalError("no mem for sys.path insertion");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1759 if (PyList_Insert(path, 0, a) < 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1760 Py_FatalError("sys.path.insert(0) failed");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1761 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
1762 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1763 Py_DECREF(av);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1764 }
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
1765
60889
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1766 /* Reimplementation of PyFile_WriteString() no calling indirectly
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1767 PyErr_CheckSignals(): avoid the call to PyObject_Str(). */
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1768
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1769 static int
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1770 sys_pyfile_write(const char *text, PyObject *file)
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1771 {
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1772 PyObject *unicode = NULL, *writer = NULL, *args = NULL, *result = NULL;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1773 int err;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1774
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1775 unicode = PyUnicode_FromString(text);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1776 if (unicode == NULL)
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1777 goto error;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1778
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1779 writer = PyObject_GetAttrString(file, "write");
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1780 if (writer == NULL)
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1781 goto error;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1782
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1783 args = PyTuple_Pack(1, unicode);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1784 if (args == NULL)
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1785 goto error;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1786
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1787 result = PyEval_CallObject(writer, args);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1788 if (result == NULL) {
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1789 goto error;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1790 } else {
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1791 err = 0;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1792 goto finally;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1793 }
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1794
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1795 error:
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1796 err = -1;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1797 finally:
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1798 Py_XDECREF(unicode);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1799 Py_XDECREF(writer);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1800 Py_XDECREF(args);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1801 Py_XDECREF(result);
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1802 return err;
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1803 }
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1804
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
1805
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
1806 /* 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
1807 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
1808
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
1809 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
1810 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
1811
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
1812 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
1813 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
1814 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
1815
60889
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1816 PyErr_CheckSignals() is not called to avoid the execution of the Python
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1817 signal handlers: they may raise a new exception whereas mywrite() ignores
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1818 all exceptions.
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1819
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
1820 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
1821 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
1822
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
1823 *** 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
1824
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
1825 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
1826 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
1827 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
1828 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
1829 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
1830 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
1831
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
1832 */
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
1833
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
1834 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1835 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
1836 {
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
1837 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
1838 PyObject *error_type, *error_value, *error_traceback;
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1839 char buffer[1001];
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1840 int written;
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
1841
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1842 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
1843 file = PySys_GetObject(name);
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1844 written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
60889
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1845 if (sys_pyfile_write(buffer, file) != 0) {
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1846 PyErr_Clear();
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1847 fputs(buffer, fp);
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1848 }
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1849 if (written < 0 || (size_t)written >= sizeof(buffer)) {
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1850 const char *truncated = "... truncated";
60889
86fadaebcf66 Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59300
diff changeset
1851 if (sys_pyfile_write(truncated, file) != 0) {
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
1852 PyErr_Clear();
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42013
diff changeset
1853 fputs(truncated, fp);
21091
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1854 }
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
1855 }
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1856 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
1857 }
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
1858
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
1859 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
1860 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
1861 {
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
1862 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
1863
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
1864 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
1865 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
1866 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
1867 }
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
1868
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
1869 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
1870 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
1871 {
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
1872 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
1873
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
1874 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
1875 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
1876 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
1877 }