annotate Python/sysmodule.c @ 61463:fd25030223b0 legacy-trunk

Untabify C files. Will watch buildbots.
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 09 May 2010 14:46:46 +0000
parents b8750c72b9bc
children c2917ac5d526
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"
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
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
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
27 #include "windows.h"
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 MS_WINDOWS
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 <windows.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 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
43
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
44 #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
45 #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
46 #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
47 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
48
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
49 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
50 PySys_GetObject(char *name)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
52 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
53 PyObject *sd = tstate->interp->sysdict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
54 if (sd == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
55 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
56 return PyDict_GetItemString(sd, name);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 FILE *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
60 PySys_GetFile(char *name, FILE *def)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
62 FILE *fp = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
63 PyObject *v = PySys_GetObject(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
64 if (v != NULL && PyFile_Check(v))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
65 fp = PyFile_AsFile(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
66 if (fp == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
67 fp = def;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
68 return fp;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
72 PySys_SetObject(char *name, PyObject *v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
74 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
75 PyObject *sd = tstate->interp->sysdict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
76 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
77 if (PyDict_GetItemString(sd, name) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
78 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
79 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
80 return PyDict_DelItemString(sd, name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
81 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
82 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
83 return PyDict_SetItemString(sd, name, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
86 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
87 sys_displayhook(PyObject *self, PyObject *o)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
88 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
89 PyObject *outf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
90 PyInterpreterState *interp = PyThreadState_GET()->interp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
91 PyObject *modules = interp->modules;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
92 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
93
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
94 if (builtins == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
95 PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
96 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
97 }
18805
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
98
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
99 /* Print value except if None */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
100 /* After printing, also assign to '_' */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
101 /* Before, set '_' to None to avoid recursion */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
102 if (o == Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
103 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
104 return Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
105 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
106 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
107 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
108 if (Py_FlushLine() != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
109 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
110 outf = PySys_GetObject("stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
111 if (outf == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
112 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
113 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
114 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
115 if (PyFile_WriteObject(o, outf, 0) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
116 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
117 PyFile_SoftSpace(outf, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
118 if (Py_FlushLine() != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
119 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
120 if (PyObject_SetAttrString(builtins, "_", o) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
121 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
122 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
123 return Py_None;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
124 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
125
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
126 PyDoc_STRVAR(displayhook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
127 "displayhook(object) -> None\n"
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
128 "\n"
59298
b8750c72b9bc Revert a nonexistent docstring typo, r42805.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58626
diff changeset
129 "Print an object to sys.stdout and also save it in __builtin__._\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
130 );
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
131
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
132 static PyObject *
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
133 sys_excepthook(PyObject* self, PyObject* args)
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
134 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
135 PyObject *exc, *value, *tb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
136 if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
137 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
138 PyErr_Display(exc, value, tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
139 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
140 return Py_None;
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
141 }
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
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(excepthook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
144 "excepthook(exctype, value, traceback) -> None\n"
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
145 "\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
146 "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
147 );
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
148
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
149 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
150 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
151 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
152 PyThreadState *tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
153 tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
154 return Py_BuildValue(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
155 "(OOO)",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
156 tstate->exc_type != NULL ? tstate->exc_type : Py_None,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
157 tstate->exc_value != NULL ? tstate->exc_value : Py_None,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
158 tstate->exc_traceback != NULL ?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
159 tstate->exc_traceback : Py_None);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
160 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
161
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
162 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
163 "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
164 \n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
165 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
166 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
167 );
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
168
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
169 static PyObject *
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
170 sys_exc_clear(PyObject *self, PyObject *noargs)
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
171 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
172 PyThreadState *tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
173 PyObject *tmp_type, *tmp_value, *tmp_tb;
45983
99355baa748d #2358: add py3k warning to sys.exc_clear().
Georg Brandl <georg@python.org>
parents: 45143
diff changeset
174
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
175 if (PyErr_WarnPy3k("sys.exc_clear() not supported in 3.x; "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
176 "use except clauses", 1) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
177 return NULL;
45983
99355baa748d #2358: add py3k warning to sys.exc_clear().
Georg Brandl <georg@python.org>
parents: 45143
diff changeset
178
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
179 tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
180 tmp_type = tstate->exc_type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
181 tmp_value = tstate->exc_value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
182 tmp_tb = tstate->exc_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
183 tstate->exc_type = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
184 tstate->exc_value = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
185 tstate->exc_traceback = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
186 Py_XDECREF(tmp_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
187 Py_XDECREF(tmp_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
188 Py_XDECREF(tmp_tb);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
189 /* For b/w compatibility */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
190 PySys_SetObject("exc_type", Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
191 PySys_SetObject("exc_value", Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
192 PySys_SetObject("exc_traceback", Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
193 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
194 return Py_None;
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
195 }
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
196
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
197 PyDoc_STRVAR(exc_clear_doc,
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
198 "exc_clear() -> None\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
199 \n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
200 Clear global information on the current exception. Subsequent calls to\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
201 exc_info() will return (None,None,None) until another exception is raised\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
202 in the current thread or the execution stack returns to a frame where\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
203 another exception is being handled."
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
204 );
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
205
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
206 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
207 sys_exit(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
209 PyObject *exit_code = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
210 if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
211 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
212 /* Raise SystemExit so callers may catch it or clean up. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
213 PyErr_SetObject(PyExc_SystemExit, exit_code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
214 return NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
217 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
218 "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
219 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
220 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
221 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
222 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
223 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
224 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
225 );
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
226
20943
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
227 #ifdef Py_USING_UNICODE
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
228
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
229 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
230 sys_getdefaultencoding(PyObject *self)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
231 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
232 return PyString_FromString(PyUnicode_GetDefaultEncoding());
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
233 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
234
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
235 PyDoc_STRVAR(getdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
236 "getdefaultencoding() -> string\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
237 \n\
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
238 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
239 implementation."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
240 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
241
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
242 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
243 sys_setdefaultencoding(PyObject *self, PyObject *args)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
244 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
245 char *encoding;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
246 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
247 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
248 if (PyUnicode_SetDefaultEncoding(encoding))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
249 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
250 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
251 return Py_None;
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
252 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
253
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
254 PyDoc_STRVAR(setdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
255 "setdefaultencoding(encoding)\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
256 \n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
257 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
258 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
259
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
260 static PyObject *
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
261 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
262 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
263 if (Py_FileSystemDefaultEncoding)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
264 return PyString_FromString(Py_FileSystemDefaultEncoding);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
265 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
266 return Py_None;
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
267 }
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
268
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
269 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
270 "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
271 \n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
272 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
273 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
274 );
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
275
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
276 #endif
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
277
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
278 /*
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
279 * 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
280 * 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
281 */
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
282 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
283
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
284 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
285 trace_init(void)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
286 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
287 static char *whatnames[7] = {"call", "exception", "line", "return",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
288 "c_call", "c_exception", "c_return"};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
289 PyObject *name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
290 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
291 for (i = 0; i < 7; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
292 if (whatstrings[i] == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
293 name = PyString_InternFromString(whatnames[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
294 if (name == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
295 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
296 whatstrings[i] = name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
297 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
298 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
299 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
300 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
301
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
302
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
303 static PyObject *
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
304 call_trampoline(PyThreadState *tstate, PyObject* callback,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
305 PyFrameObject *frame, int what, PyObject *arg)
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
306 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
307 PyObject *args = PyTuple_New(3);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
308 PyObject *whatstr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
309 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
310
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
311 if (args == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
312 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
313 Py_INCREF(frame);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
314 whatstr = whatstrings[what];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
315 Py_INCREF(whatstr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
316 if (arg == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
317 arg = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
318 Py_INCREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
319 PyTuple_SET_ITEM(args, 0, (PyObject *)frame);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
320 PyTuple_SET_ITEM(args, 1, whatstr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
321 PyTuple_SET_ITEM(args, 2, arg);
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
322
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
323 /* call the Python-level function */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
324 PyFrame_FastToLocals(frame);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
325 result = PyEval_CallObject(callback, args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
326 PyFrame_LocalsToFast(frame, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
327 if (result == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
328 PyTraceBack_Here(frame);
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
329
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
330 /* cleanup */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
331 Py_DECREF(args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
332 return result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
333 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
334
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
335 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
336 profile_trampoline(PyObject *self, PyFrameObject *frame,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
337 int what, PyObject *arg)
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
338 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
339 PyThreadState *tstate = frame->f_tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
340 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
341
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
342 if (arg == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
343 arg = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
344 result = call_trampoline(tstate, self, frame, what, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
345 if (result == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
346 PyEval_SetProfile(NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
347 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
348 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
349 Py_DECREF(result);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
350 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
351 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
352
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
353 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
354 trace_trampoline(PyObject *self, PyFrameObject *frame,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
355 int what, PyObject *arg)
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
356 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
357 PyThreadState *tstate = frame->f_tstate;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
358 PyObject *callback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
359 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
360
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
361 if (what == PyTrace_CALL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
362 callback = self;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
363 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
364 callback = frame->f_trace;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
365 if (callback == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
366 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
367 result = call_trampoline(tstate, callback, frame, what, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
368 if (result == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
369 PyEval_SetTrace(NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
370 Py_XDECREF(frame->f_trace);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
371 frame->f_trace = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
372 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
373 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
374 if (result != Py_None) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
375 PyObject *temp = frame->f_trace;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
376 frame->f_trace = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
377 Py_XDECREF(temp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
378 frame->f_trace = result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
379 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
380 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
381 Py_DECREF(result);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
382 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
383 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
384 }
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
385
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
386 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
387 sys_settrace(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
388 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
389 if (trace_init() == -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
390 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
391 if (args == Py_None)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
392 PyEval_SetTrace(NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
393 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
394 PyEval_SetTrace(trace_trampoline, args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
395 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
396 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
397 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
398
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
399 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
400 "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
401 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
402 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
403 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
404 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
405
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
406 static PyObject *
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
407 sys_gettrace(PyObject *self, PyObject *args)
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
408 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
409 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
410 PyObject *temp = tstate->c_traceobj;
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
411
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
412 if (temp == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
413 temp = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
414 Py_INCREF(temp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
415 return temp;
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
416 }
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
417
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
418 PyDoc_STRVAR(gettrace_doc,
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
419 "gettrace()\n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
420 \n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
421 Return the global debug tracing function set with sys.settrace.\n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
422 See the debugger chapter in the library manual."
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
423 );
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
424
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
425 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
426 sys_setprofile(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
427 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
428 if (trace_init() == -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
429 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
430 if (args == Py_None)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
431 PyEval_SetProfile(NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
432 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
433 PyEval_SetProfile(profile_trampoline, args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
434 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
435 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
436 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
437
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
438 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
439 "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
440 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
441 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
442 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
443 );
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
444
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
445 static PyObject *
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
446 sys_getprofile(PyObject *self, PyObject *args)
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
447 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
448 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
449 PyObject *temp = tstate->c_profileobj;
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
450
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
451 if (temp == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
452 temp = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
453 Py_INCREF(temp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
454 return temp;
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
455 }
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
456
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
457 PyDoc_STRVAR(getprofile_doc,
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
458 "getprofile()\n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
459 \n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
460 Return the profiling function set with sys.setprofile.\n\
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
461 See the profiler chapter in the library manual."
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
462 );
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
463
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
464 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
465 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
466 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
467 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
468 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
469 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
470 return Py_None;
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
471 }
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
472
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
473 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
474 "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
475 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
476 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
477 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
478 );
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
479
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
480 static PyObject *
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
481 sys_getcheckinterval(PyObject *self, PyObject *args)
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
482 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
483 return PyInt_FromLong(_Py_CheckInterval);
29765
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
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
486 PyDoc_STRVAR(getcheckinterval_doc,
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
487 "getcheckinterval() -> current check interval; see setcheckinterval()."
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
488 );
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
489
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
490 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
491 static PyObject *
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
492 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
493 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
494 int bool;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
495 PyThreadState *tstate = PyThreadState_Get();
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
496
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
497 if (!PyArg_ParseTuple(args, "i:settscdump", &bool))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
498 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
499 if (bool)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
500 tstate->interp->tscdump = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
501 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
502 tstate->interp->tscdump = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
503 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
504 return Py_None;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
505
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
506 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
507
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
508 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
509 "settscdump(bool)\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
510 \n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
511 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
512 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
513 processor's time-stamp counter."
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
514 );
32344
748129e6e108 Remove compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 32301
diff changeset
515 #endif /* TSC */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
516
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
517 static PyObject *
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
518 sys_setrecursionlimit(PyObject *self, PyObject *args)
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
519 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
520 int new_limit;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
521 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
522 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
523 if (new_limit <= 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
524 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
525 "recursion limit must be positive");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
526 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
527 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
528 Py_SetRecursionLimit(new_limit);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
529 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
530 return Py_None;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
531 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
532
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
533 PyDoc_STRVAR(setrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
534 "setrecursionlimit(n)\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
535 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
536 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
537 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
538 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
539 dependent."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
540 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
541
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
542 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
543 sys_getrecursionlimit(PyObject *self)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
544 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
545 return PyInt_FromLong(Py_GetRecursionLimit());
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
546 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
547
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
548 PyDoc_STRVAR(getrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
549 "getrecursionlimit()\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
550 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
551 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
552 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
553 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
554 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
555
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
556 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
557 PyDoc_STRVAR(getwindowsversion_doc,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
558 "getwindowsversion()\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
559 \n\
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
560 Return information about the running version of Windows as a named tuple.\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
561 The members are named: major, minor, build, platform, service_pack,\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
562 service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
563 backward compatibiliy, only the first 5 items are available by indexing.\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
564 All elements are numbers, except service_pack which is a string. Platform\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
565 may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
566 3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n\
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
567 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
568 );
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
569
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
570 static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0};
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
571
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
572 static PyStructSequence_Field windows_version_fields[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
573 {"major", "Major version number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
574 {"minor", "Minor version number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
575 {"build", "Build number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
576 {"platform", "Operating system platform"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
577 {"service_pack", "Latest Service Pack installed on the system"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
578 {"service_pack_major", "Service Pack major version number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
579 {"service_pack_minor", "Service Pack minor version number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
580 {"suite_mask", "Bit mask identifying available product suites"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
581 {"product_type", "System product type"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
582 {0}
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
583 };
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
584
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
585 static PyStructSequence_Desc windows_version_desc = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
586 "sys.getwindowsversion", /* name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
587 getwindowsversion_doc, /* doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
588 windows_version_fields, /* fields */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
589 5 /* For backward compatibility,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
590 only the first 5 items are accessible
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
591 via indexing, the rest are name only */
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
592 };
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
593
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
594 static PyObject *
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
595 sys_getwindowsversion(PyObject *self)
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
596 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
597 PyObject *version;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
598 int pos = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
599 OSVERSIONINFOEX ver;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
600 ver.dwOSVersionInfoSize = sizeof(ver);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
601 if (!GetVersionEx((OSVERSIONINFO*) &ver))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
602 return PyErr_SetFromWindowsErr(0);
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
603
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
604 version = PyStructSequence_New(&WindowsVersionType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
605 if (version == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
606 return NULL;
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
607
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
608 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMajorVersion));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
609 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMinorVersion));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
610 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwBuildNumber));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
611 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwPlatformId));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
612 PyStructSequence_SET_ITEM(version, pos++, PyString_FromString(ver.szCSDVersion));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
613 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMajor));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
614 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMinor));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
615 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wSuiteMask));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
616 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wProductType));
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
617
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
618 return version;
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
619 }
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
620
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
621 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
622
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
623 #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
624 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
625 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
626 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
627 int new_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
628 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
629 if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
630 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
631 if (!tstate)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
632 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
633 tstate->interp->dlopenflags = new_val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
634 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
635 return Py_None;
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
636 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
637
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
638 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
639 "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
640 \n\
54955
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
641 Set the flags used by the interpreter for dlopen calls, such as when the\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
642 interpreter loads extension modules. Among other things, this will enable\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
643 a lazy resolving of symbols when importing a module, if called as\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
644 sys.setdlopenflags(0). To share symbols across extension modules, call as\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
645 sys.setdlopenflags(ctypes.RTLD_GLOBAL). Symbolic names for the flag modules\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
646 can be either found in the ctypes module, or in the DLFCN module. If DLFCN\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
647 is not available, it can be generated from /usr/include/dlfcn.h using the\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
648 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
649
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
650 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
651 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
652 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
653 PyThreadState *tstate = PyThreadState_GET();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
654 if (!tstate)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
655 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
656 return PyInt_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
657 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
658
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
659 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
660 "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
661 \n\
54955
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
662 Return the current value of the flags that are used for dlopen calls.\n\
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
663 The flag constants are defined in the ctypes and DLFCN modules.");
164d64b39ac0 Update docstrings for sys.getdlopenflags() and sys.setdlopenflags().
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 54325
diff changeset
664
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
665 #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
666
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
667 #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
668 /* 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
669 #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
670
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
671 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
672 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
673 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
674 int flag;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
675 if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
676 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
677 mallopt(M_DEBUG, flag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
678 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
679 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
680 }
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
681 #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
682
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
683 static PyObject *
47925
fd054e73e2f2 Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47918
diff changeset
684 sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
47419
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
685 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
686 PyObject *res = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
687 static PyObject *str__sizeof__ = NULL, *gc_head_size = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
688 static char *kwlist[] = {"object", "default", 0};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
689 PyObject *o, *dflt = NULL;
47925
fd054e73e2f2 Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47918
diff changeset
690
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
691 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
692 kwlist, &o, &dflt))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
693 return NULL;
47419
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
694
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
695 /* Initialize static variable for GC head size */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
696 if (gc_head_size == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
697 gc_head_size = PyInt_FromSsize_t(sizeof(PyGC_Head));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
698 if (gc_head_size == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
699 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
700 }
47925
fd054e73e2f2 Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47918
diff changeset
701
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
702 /* Make sure the type is initialized. float gets initialized late */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
703 if (PyType_Ready(Py_TYPE(o)) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
704 return NULL;
47918
68c7964d2534 Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47897
diff changeset
705
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
706 /* Instance of old-style class */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
707 if (PyInstance_Check(o))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
708 res = PyInt_FromSsize_t(PyInstance_Type.tp_basicsize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
709 /* all other objects */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
710 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
711 PyObject *method = _PyObject_LookupSpecial(o, "__sizeof__",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
712 &str__sizeof__);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
713 if (method == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
714 if (!PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
715 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
716 "Type %.100s doesn't define __sizeof__",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
717 Py_TYPE(o)->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
718 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
719 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
720 res = PyObject_CallFunctionObjArgs(method, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
721 Py_DECREF(method);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
722 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
723 }
47925
fd054e73e2f2 Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47918
diff changeset
724
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
725 /* Has a default value been given? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
726 if ((res == NULL) && (dflt != NULL) &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
727 PyErr_ExceptionMatches(PyExc_TypeError))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
728 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
729 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
730 Py_INCREF(dflt);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
731 return dflt;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
732 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
733 else if (res == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
734 return res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
735
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
736 /* add gc_head size */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
737 if (PyObject_IS_GC(o)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
738 PyObject *tmp = res;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
739 res = PyNumber_Add(tmp, gc_head_size);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
740 Py_DECREF(tmp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
741 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
742 return res;
47419
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
743 }
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
744
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
745 PyDoc_STRVAR(getsizeof_doc,
47925
fd054e73e2f2 Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47918
diff changeset
746 "getsizeof(object, default) -> int\n\
47419
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
747 \n\
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
748 Return the size of object in bytes.");
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
749
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
750 static PyObject *
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
751 sys_getrefcount(PyObject *self, PyObject *arg)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
752 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
753 return PyInt_FromSsize_t(arg->ob_refcnt);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
754 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
755
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
756 #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
757 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
758 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
759 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
760 return PyInt_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
761 }
37638
65ecb83ea7dd Ignore the references to the dummy objects used as deleted keys
Armin Rigo <arigo@tunes.org>
parents: 37423
diff changeset
762 #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
763
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
764 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
765 "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
766 \n\
23947
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
767 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
768 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
769 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
770 );
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
771
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
772 #ifdef COUNT_ALLOCS
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
773 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
774 sys_getcounts(PyObject *self)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
775 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
776 extern PyObject *get_counts(void);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
777
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
778 return get_counts();
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
779 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
780 #endif
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
781
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
782 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
783 "_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
784 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
785 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
786 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
787 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
788 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
789 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
790 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
791 purposes only."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
792 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
793
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
794 static PyObject *
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
795 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
796 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
797 PyFrameObject *f = PyThreadState_GET()->frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
798 int depth = -1;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
799
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
800 if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
801 return NULL;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
802
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
803 while (depth > 0 && f != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
804 f = f->f_back;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
805 --depth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
806 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
807 if (f == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
808 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
809 "call stack is not deep enough");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
810 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
811 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
812 Py_INCREF(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
813 return (PyObject*)f;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
814 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
815
39056
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
816 PyDoc_STRVAR(current_frames_doc,
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
817 "_current_frames() -> dictionary\n\
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
818 \n\
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
819 Return a dictionary mapping each current thread T's thread id to T's\n\
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
820 current stack frame.\n\
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
821 \n\
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
822 This function should be used for specialized purposes only."
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
823 );
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
824
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
825 static PyObject *
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
826 sys_current_frames(PyObject *self, PyObject *noargs)
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
827 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
828 return _PyThread_CurrentFrames();
39056
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
829 }
b6fd499e4343 After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents: 38622
diff changeset
830
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
831 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
832 "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
833 \n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
834 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
835 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
836 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
837 );
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
838
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
839 static PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
840 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
841 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
842 PyObject *func, *funcargs;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
843 if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
844 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
845 return _PyEval_CallTracing(func, funcargs);
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
846 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
847
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
848 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
849 "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
850 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
851 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
852 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
853 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
854 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
855 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
856 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
857 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
858 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
859 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
860 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
861 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
862 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
863 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
864 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
865 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
866 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
867 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
868 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
869 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
870
37819
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
871 #ifdef __cplusplus
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
872 extern "C" {
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
873 #endif
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
874
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
875 #ifdef Py_TRACE_REFS
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
876 /* 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
877 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
878 #endif
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
879
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
880 #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
881 /* 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
882 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
883 #endif
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
884
37819
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
885 #ifdef __cplusplus
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
886 }
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
887 #endif
61ac1e322da7 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t
Skip Montanaro <skip@pobox.com>
parents: 37638
diff changeset
888
45143
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
889 static PyObject *
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
890 sys_clear_type_cache(PyObject* self, PyObject* args)
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
891 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
892 PyType_ClearCache();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
893 Py_RETURN_NONE;
45143
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
894 }
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
895
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
896 PyDoc_STRVAR(sys_clear_type_cache__doc__,
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
897 "_clear_type_cache() -> None\n\
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
898 Clear the internal type lookup cache.");
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
899
8fdd6d62ea55 Patch #1953
Christian Heimes <christian@cheimes.de>
parents: 45060
diff changeset
900
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
901 static PyMethodDef sys_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
902 /* Might as well keep this in alphabetic order */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
903 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
904 callstats_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
905 {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
906 sys_clear_type_cache__doc__},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
907 {"_current_frames", sys_current_frames, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
908 current_frames_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
909 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
910 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
911 {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
912 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
913 {"exit", sys_exit, METH_VARARGS, exit_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
914 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
915 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
916 METH_NOARGS, getdefaultencoding_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
917 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
918 #ifdef HAVE_DLOPEN
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
919 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
920 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
921 #endif
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
922 #ifdef COUNT_ALLOCS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
923 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
924 #endif
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
925 #ifdef DYNAMIC_EXECUTION_PROFILE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
926 {"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
927 #endif
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
928 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
929 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
930 METH_NOARGS, getfilesystemencoding_doc},
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
931 #endif
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
932 #ifdef Py_TRACE_REFS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
933 {"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
934 #endif
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
935 #ifdef Py_REF_DEBUG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
936 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
937 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
938 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
939 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
940 getrecursionlimit_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
941 {"getsizeof", (PyCFunction)sys_getsizeof,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
942 METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
943 {"_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
944 #ifdef MS_WINDOWS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
945 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
946 getwindowsversion_doc},
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
947 #endif /* MS_WINDOWS */
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
948 #ifdef USE_MALLOPT
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
949 {"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
950 #endif
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
951 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
952 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
953 setdefaultencoding_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
954 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
955 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
956 setcheckinterval_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
957 {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
958 getcheckinterval_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
959 #ifdef HAVE_DLOPEN
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
960 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
961 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
962 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
963 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
964 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
965 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
966 setrecursionlimit_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
967 #ifdef WITH_TSC
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
968 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
969 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
970 {"settrace", sys_settrace, METH_O, settrace_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
971 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
972 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
973 {NULL, NULL} /* sentinel */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
974 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
975
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
976 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
977 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
978 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
979 PyObject *list = PyList_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
980 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
981 if (list == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
982 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
983 for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
984 PyObject *name = PyString_FromString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
985 PyImport_Inittab[i].name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
986 if (name == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
987 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
988 PyList_Append(list, name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
989 Py_DECREF(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
990 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
991 if (PyList_Sort(list) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
992 Py_DECREF(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
993 list = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
994 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
995 if (list) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
996 PyObject *v = PyList_AsTuple(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
997 Py_DECREF(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
998 list = v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
999 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1000 return list;
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1001 }
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1002
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1003 static PyObject *warnoptions = NULL;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1004
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1005 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1006 PySys_ResetWarnOptions(void)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1007 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1008 if (warnoptions == NULL || !PyList_Check(warnoptions))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1009 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1010 PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1011 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1012
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1013 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1014 PySys_AddWarnOption(char *s)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1015 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1016 PyObject *str;
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1017
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1018 if (warnoptions == NULL || !PyList_Check(warnoptions)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1019 Py_XDECREF(warnoptions);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1020 warnoptions = PyList_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1021 if (warnoptions == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1022 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1023 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1024 str = PyString_FromString(s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1025 if (str != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1026 PyList_Append(warnoptions, str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1027 Py_DECREF(str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1028 }
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1029 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1030
46414
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1031 int
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1032 PySys_HasWarnOptions(void)
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1033 {
46416
39ea2fc4503d Fix a bug in PySys_HasWarnOption() where it was not properly checking the
Brett Cannon <bcannon@gmail.com>
parents: 46414
diff changeset
1034 return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0;
46414
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1035 }
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1036
8840
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
1037 /* 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
1038 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
1039 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
1040 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
1041 PyDoc_VAR(sys_doc) =
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1042 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
1043 "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
1044 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
1045 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1046 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
1047 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1048 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
1049 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
1050 modules -- dictionary of loaded modules\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1051 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1052 displayhook -- called to show results in an interactive session\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1053 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
1054 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
1055 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
1056 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1057 exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1058 Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1059 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1060 stdin -- standard input file object; used by raw_input() and input()\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1061 stdout -- standard output file object; used by the print statement\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1062 stderr -- standard error object; used for error messages\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1063 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
1064 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
1065 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1066 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
1067 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
1068 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
1069 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
1070 traceback has been printed.\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1071 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1072 exc_type -- type of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1073 exc_value -- value of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1074 exc_traceback -- traceback of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1075 The function exc_info() should be used instead of these three,\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1076 because it is thread-safe.\n\
9885
030ee50bd8d1 Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents: 9746
diff changeset
1077 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1078 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1079 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1080 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
1081 "\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
1082 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
1083 \n\
52233
9b358eae532a Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 51365
diff changeset
1084 float_info -- a dict with information about the float inplementation.\n\
9b358eae532a Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 51365
diff changeset
1085 long_info -- a struct sequence with information about the long implementation.\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
1086 maxint -- the largest supported integer (the smallest is -maxint-1)\n\
47194
59ab2cf002fa Patch #2488: Add sys.maxsize.
Martin v. Löwis <martin@v.loewis.de>
parents: 46759
diff changeset
1087 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
1088 maxunicode -- the largest supported character\n\
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21712
diff changeset
1089 builtin_module_names -- tuple of module names built into this interpreter\n\
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1090 version -- the version of this interpreter as a string\n\
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 exec_prefix -- prefix used to find the machine-specific Python library\n\
56715
aacee9749d15 Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents: 54955
diff changeset
1098 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
1099 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1100 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1101 #ifdef MS_WINDOWS
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1102 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1103 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1104 "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
1105 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
1106 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1107 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1108 #endif /* MS_WINDOWS */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1109 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1110 "__stdin__ -- the original stdin; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1111 __stdout__ -- the original stdout; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1112 __stderr__ -- the original stderr; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1113 __displayhook__ -- the original displayhook; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1114 __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
1115 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1116 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
1117 \n\
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
1118 displayhook() -- print an object to the screen, and save it in __builtin__._\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1119 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
1120 exc_info() -- return thread-safe information about the current exception\n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
1121 exc_clear() -- clear the exception state for the current thread\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
1122 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
1123 getdlopenflags() -- returns flags to be used for dlopen() calls\n\
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
1124 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
1125 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
1126 getrecursionlimit() -- return the max recursion depth for the interpreter\n\
47419
88bd07c0a847 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47413
diff changeset
1127 getsizeof() -- return the size of an object in bytes\n\
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 44678
diff changeset
1128 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
1129 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
1130 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
1131 setprofile() -- set the global profiling function\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
1132 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
1133 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
1134 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1135 )
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
1136 /* 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
1137
34483
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1138 static int
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1139 _check_and_flush (FILE *stream)
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1140 {
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1141 int prev_fail = ferror (stream);
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1142 return fflush (stream) || prev_fail ? EOF : 0;
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1143 }
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1144
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1145 /* 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
1146 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
1147 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
1148 static int svn_initialized;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1149 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
1150 static char branch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1151 static char shortbranch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1152 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
1153
36212
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
1154 static void
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
1155 svnversion_init(void)
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1156 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1157 const char *python, *br_start, *br_end, *br_end2, *svnversion;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1158 Py_ssize_t len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1159 int istag;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1160
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1161 if (svn_initialized)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1162 return;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1163
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1164 python = strstr(headurl, "/python/");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1165 if (!python) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1166 /* XXX quick hack to get bzr working */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1167 *patchlevel_revision = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1168 strcpy(branch, "");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1169 strcpy(shortbranch, "unknown");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1170 svn_revision = "";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1171 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1172 /* Py_FatalError("subversion keywords missing"); */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1173 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1174
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1175 br_start = python + 8;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1176 br_end = strchr(br_start, '/');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1177 assert(br_end);
40224
c58d1b969843 Add some asserts. In sysmodule, I think these were to try to silence
Neal Norwitz <nnorwitz@gmail.com>
parents: 39995
diff changeset
1178
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1179 /* Works even for trunk,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1180 as we are in trunk/Python/sysmodule.c */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1181 br_end2 = strchr(br_end+1, '/');
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1182
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1183 istag = strncmp(br_start, "tags", 4) == 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1184 if (strncmp(br_start, "trunk", 5) == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1185 strcpy(branch, "trunk");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1186 strcpy(shortbranch, "trunk");
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1187
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1188 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1189 else if (istag || strncmp(br_start, "branches", 8) == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1190 len = br_end2 - br_start;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1191 strncpy(branch, br_start, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1192 branch[len] = '\0';
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1193
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1194 len = br_end2 - (br_end + 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1195 strncpy(shortbranch, br_end + 1, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1196 shortbranch[len] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1197 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1198 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1199 Py_FatalError("bad HeadURL");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1200 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1201 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1202
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1203
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1204 svnversion = _Py_svnversion();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1205 if (strcmp(svnversion, "Unversioned directory") != 0 && strcmp(svnversion, "exported") != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1206 svn_revision = svnversion;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1207 else if (istag) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1208 len = strlen(_patchlevel_revision);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1209 assert(len >= 13);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1210 assert(len < (sizeof(patchlevel_revision) + 13));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1211 strncpy(patchlevel_revision, _patchlevel_revision + 11,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1212 len - 13);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1213 patchlevel_revision[len - 13] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1214 svn_revision = patchlevel_revision;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1215 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1216 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1217 svn_revision = "";
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1218
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1219 svn_initialized = 1;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1220 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1221
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1222 /* 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
1223 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
1224 Else return empty string */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1225 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1226 Py_SubversionRevision()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1227 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1228 svnversion_init();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1229 return svn_revision;
36207
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
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1232 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1233 Py_SubversionShortBranch()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1234 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1235 svnversion_init();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1236 return shortbranch;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1237 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1238
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1239
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1240 PyDoc_STRVAR(flags__doc__,
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1241 "sys.flags\n\
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1242 \n\
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1243 Flags provided through command line arguments or environment vars.");
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1244
45060
c05ee77b39f2 The previous change was causing a segfault after multiple calls to Py_Initialize() and Py_Finalize().
Christian Heimes <christian@cheimes.de>
parents: 45059
diff changeset
1245 static PyTypeObject FlagsType = {0, 0, 0, 0, 0, 0};
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1246
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1247 static PyStructSequence_Field flags_fields[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1248 {"debug", "-d"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1249 {"py3k_warning", "-3"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1250 {"division_warning", "-Q"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1251 {"division_new", "-Qnew"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1252 {"inspect", "-i"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1253 {"interactive", "-i"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1254 {"optimize", "-O or -OO"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1255 {"dont_write_bytecode", "-B"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1256 {"no_user_site", "-s"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1257 {"no_site", "-S"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1258 {"ignore_environment", "-E"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1259 {"tabcheck", "-t or -tt"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1260 {"verbose", "-v"},
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1261 #ifdef RISCOS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1262 {"riscos_wimp", "???"},
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1263 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1264 /* {"unbuffered", "-u"}, */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1265 {"unicode", "-U"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1266 /* {"skip_first", "-x"}, */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1267 {"bytes_warning", "-b"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1268 {0}
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1269 };
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1270
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1271 static PyStructSequence_Desc flags_desc = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1272 "sys.flags", /* name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1273 flags__doc__, /* doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1274 flags_fields, /* fields */
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1275 #ifdef RISCOS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1276 16
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1277 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1278 15
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1279 #endif
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1280 };
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1281
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1282 static PyObject*
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1283 make_flags(void)
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1284 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1285 int pos = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1286 PyObject *seq;
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1287
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1288 seq = PyStructSequence_New(&FlagsType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1289 if (seq == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1290 return NULL;
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1291
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1292 #define SetFlag(flag) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1293 PyStructSequence_SET_ITEM(seq, pos++, PyInt_FromLong(flag))
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1294
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1295 SetFlag(Py_DebugFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1296 SetFlag(Py_Py3kWarningFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1297 SetFlag(Py_DivisionWarningFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1298 SetFlag(_Py_QnewFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1299 SetFlag(Py_InspectFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1300 SetFlag(Py_InteractiveFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1301 SetFlag(Py_OptimizeFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1302 SetFlag(Py_DontWriteBytecodeFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1303 SetFlag(Py_NoUserSiteDirectory);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1304 SetFlag(Py_NoSiteFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1305 SetFlag(Py_IgnoreEnvironmentFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1306 SetFlag(Py_TabcheckFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1307 SetFlag(Py_VerboseFlag);
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1308 #ifdef RISCOS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1309 SetFlag(Py_RISCOSWimpFlag);
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1310 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1311 /* SetFlag(saw_unbuffered_flag); */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1312 SetFlag(Py_UnicodeFlag);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1313 /* SetFlag(skipfirstline); */
46414
840064802952 Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
1314 SetFlag(Py_BytesWarningFlag);
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1315 #undef SetFlag
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1316
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1317 if (PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1318 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1319 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1320 return seq;
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1321 }
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1322
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1323 PyDoc_STRVAR(version_info__doc__,
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1324 "sys.version_info\n\
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1325 \n\
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1326 Version information as a named tuple.");
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1327
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1328 static PyTypeObject VersionInfoType = {0, 0, 0, 0, 0, 0};
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1329
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1330 static PyStructSequence_Field version_info_fields[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1331 {"major", "Major release number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1332 {"minor", "Minor release number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1333 {"micro", "Patch release number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1334 {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1335 {"serial", "Serial release number"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1336 {0}
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1337 };
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1338
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1339 static PyStructSequence_Desc version_info_desc = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1340 "sys.version_info", /* name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1341 version_info__doc__, /* doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1342 version_info_fields, /* fields */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1343 5
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1344 };
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1345
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1346 static PyObject *
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1347 make_version_info(void)
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1348 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1349 PyObject *version_info;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1350 char *s;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1351 int pos = 0;
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1352
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1353 version_info = PyStructSequence_New(&VersionInfoType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1354 if (version_info == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1355 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1356 }
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1357
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1358 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1359 * These release level checks are mutually exclusive and cover
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1360 * the field, so don't get too fancy with the pre-processor!
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1361 */
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1362 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1363 s = "alpha";
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1364 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1365 s = "beta";
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1366 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1367 s = "candidate";
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1368 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1369 s = "final";
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1370 #endif
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1371
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1372 #define SetIntItem(flag) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1373 PyStructSequence_SET_ITEM(version_info, pos++, PyInt_FromLong(flag))
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1374 #define SetStrItem(flag) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1375 PyStructSequence_SET_ITEM(version_info, pos++, PyString_FromString(flag))
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1376
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1377 SetIntItem(PY_MAJOR_VERSION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1378 SetIntItem(PY_MINOR_VERSION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1379 SetIntItem(PY_MICRO_VERSION);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1380 SetStrItem(s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1381 SetIntItem(PY_RELEASE_SERIAL);
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1382 #undef SetIntItem
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1383 #undef SetStrItem
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1384
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1385 if (PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1386 Py_CLEAR(version_info);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1387 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1388 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1389 return version_info;
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1390 }
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1391
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1392 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1393 _PySys_Init(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1394 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1395 PyObject *m, *v, *sysdict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1396 PyObject *sysin, *sysout, *syserr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1397 char *s;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1398
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1399 m = Py_InitModule3("sys", sys_methods, sys_doc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1400 if (m == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1401 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1402 sysdict = PyModule_GetDict(m);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1403 #define SET_SYS_FROM_STRING(key, value) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1404 v = value; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1405 if (v != NULL) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1406 PyDict_SetItemString(sysdict, key, v); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1407 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
1408
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1409 /* Check that stdin is not a directory
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1410 Using shell redirection, you can redirect stdin to a directory,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1411 crashing the Python interpreter. Catch this common mistake here
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1412 and output a useful error message. Note that under MS Windows,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1413 the shell already prevents that. */
50788
e11c99e1e6e7 Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47925
diff changeset
1414 #if !defined(MS_WINDOWS)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1415 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1416 struct stat sb;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1417 if (fstat(fileno(stdin), &sb) == 0 &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1418 S_ISDIR(sb.st_mode)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1419 /* There's nothing more we can do. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1420 /* Py_FatalError() will core dump, so just exit. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1421 PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1422 exit(EXIT_FAILURE);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1423 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1424 }
50788
e11c99e1e6e7 Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47925
diff changeset
1425 #endif
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1426
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1427 /* Closing the standard FILE* if sys.std* goes aways causes problems
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1428 * for embedded Python usages. Closing them when somebody explicitly
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1429 * invokes .close() might be possible, but the FAQ promises they get
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1430 * never closed. However, we still need to get write errors when
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1431 * writing fails (e.g. because stdout is redirected), so we flush the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1432 * streams and check for errors before the file objects are deleted.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1433 * On OS X, fflush()ing stdin causes an error, so we exempt stdin
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1434 * from that procedure.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1435 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1436 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1437 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1438 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1439 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1440 return NULL;
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1441
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1442 PyDict_SetItemString(sysdict, "stdin", sysin);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1443 PyDict_SetItemString(sysdict, "stdout", sysout);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1444 PyDict_SetItemString(sysdict, "stderr", syserr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1445 /* Make backup copies for cleanup */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1446 PyDict_SetItemString(sysdict, "__stdin__", sysin);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1447 PyDict_SetItemString(sysdict, "__stdout__", sysout);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1448 PyDict_SetItemString(sysdict, "__stderr__", syserr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1449 PyDict_SetItemString(sysdict, "__displayhook__",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1450 PyDict_GetItemString(sysdict, "displayhook"));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1451 PyDict_SetItemString(sysdict, "__excepthook__",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1452 PyDict_GetItemString(sysdict, "excepthook"));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1453 Py_XDECREF(sysin);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1454 Py_XDECREF(sysout);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1455 Py_XDECREF(syserr);
45059
9639a73afa47 Fixed some references leaks in sys.
Christian Heimes <christian@cheimes.de>
parents: 45025
diff changeset
1456
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1457 SET_SYS_FROM_STRING("version",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1458 PyString_FromString(Py_GetVersion()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1459 SET_SYS_FROM_STRING("hexversion",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1460 PyInt_FromLong(PY_VERSION_HEX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1461 svnversion_init();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1462 SET_SYS_FROM_STRING("subversion",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1463 Py_BuildValue("(ssz)", "CPython", branch,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1464 svn_revision));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1465 SET_SYS_FROM_STRING("dont_write_bytecode",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1466 PyBool_FromLong(Py_DontWriteBytecodeFlag));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1467 SET_SYS_FROM_STRING("api_version",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1468 PyInt_FromLong(PYTHON_API_VERSION));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1469 SET_SYS_FROM_STRING("copyright",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1470 PyString_FromString(Py_GetCopyright()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1471 SET_SYS_FROM_STRING("platform",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1472 PyString_FromString(Py_GetPlatform()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1473 SET_SYS_FROM_STRING("executable",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1474 PyString_FromString(Py_GetProgramFullPath()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1475 SET_SYS_FROM_STRING("prefix",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1476 PyString_FromString(Py_GetPrefix()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1477 SET_SYS_FROM_STRING("exec_prefix",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1478 PyString_FromString(Py_GetExecPrefix()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1479 SET_SYS_FROM_STRING("maxsize",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1480 PyInt_FromSsize_t(PY_SSIZE_T_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1481 SET_SYS_FROM_STRING("maxint",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1482 PyInt_FromLong(PyInt_GetMax()));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1483 SET_SYS_FROM_STRING("py3kwarning",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1484 PyBool_FromLong(Py_Py3kWarningFlag));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1485 SET_SYS_FROM_STRING("float_info",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1486 PyFloat_GetInfo());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1487 SET_SYS_FROM_STRING("long_info",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1488 PyLong_GetInfo());
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
1489 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1490 SET_SYS_FROM_STRING("maxunicode",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1491 PyInt_FromLong(PyUnicode_GetMax()));
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
1492 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1493 SET_SYS_FROM_STRING("builtin_module_names",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1494 list_builtin_module_names());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1495 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1496 /* Assumes that longs are at least 2 bytes long.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1497 Should be safe! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1498 unsigned long number = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1499 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
1500
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1501 s = (char *) &number;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1502 if (s[0] == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1503 value = "big";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1504 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1505 value = "little";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1506 SET_SYS_FROM_STRING("byteorder",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1507 PyString_FromString(value));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1508 }
4126
c80c515999b9 Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents: 3877
diff changeset
1509 #ifdef MS_COREDLL
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1510 SET_SYS_FROM_STRING("dllhandle",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1511 PyLong_FromVoidPtr(PyWin_DLLhModule));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1512 SET_SYS_FROM_STRING("winver",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1513 PyString_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
1514 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1515 if (warnoptions == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1516 warnoptions = PyList_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1517 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1518 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1519 Py_INCREF(warnoptions);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1520 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1521 if (warnoptions != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1522 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1523 }
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1524
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1525 /* version_info */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1526 if (VersionInfoType.tp_name == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1527 PyStructSequence_InitType(&VersionInfoType, &version_info_desc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1528 SET_SYS_FROM_STRING("version_info", make_version_info());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1529 /* prevent user from creating new instances */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1530 VersionInfoType.tp_init = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1531 VersionInfoType.tp_new = NULL;
51365
e239e977bb32 Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents: 50788
diff changeset
1532
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1533 /* flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1534 if (FlagsType.tp_name == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1535 PyStructSequence_InitType(&FlagsType, &flags_desc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1536 SET_SYS_FROM_STRING("flags", make_flags());
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1537 /* prevent user from creating new instances */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1538 FlagsType.tp_init = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1539 FlagsType.tp_new = NULL;
44669
9b6d348cec87 Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents: 44566
diff changeset
1540
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
1541
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
1542 #if defined(MS_WINDOWS)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1543 /* getwindowsversion */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1544 if (WindowsVersionType.tp_name == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1545 PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1546 /* prevent user from creating new instances */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1547 WindowsVersionType.tp_init = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1548 WindowsVersionType.tp_new = NULL;
58505
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
1549 #endif
bc2b88beae45 Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents: 56715
diff changeset
1550
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1551 /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
56715
aacee9749d15 Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents: 54955
diff changeset
1552 #ifndef PY_NO_SHORT_FLOAT_REPR
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1553 SET_SYS_FROM_STRING("float_repr_style",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1554 PyString_FromString("short"));
56715
aacee9749d15 Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents: 54955
diff changeset
1555 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1556 SET_SYS_FROM_STRING("float_repr_style",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1557 PyString_FromString("legacy"));
56715
aacee9749d15 Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents: 54955
diff changeset
1558 #endif
aacee9749d15 Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents: 54955
diff changeset
1559
45059
9639a73afa47 Fixed some references leaks in sys.
Christian Heimes <christian@cheimes.de>
parents: 45025
diff changeset
1560 #undef SET_SYS_FROM_STRING
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1561 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1562 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1563 return m;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1564 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1565
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1566 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1567 makepathobject(char *path, int delim)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1568 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1569 int i, n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1570 char *p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1571 PyObject *v, *w;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1572
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1573 n = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1574 p = path;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1575 while ((p = strchr(p, delim)) != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1576 n++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1577 p++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1578 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1579 v = PyList_New(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1580 if (v == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1581 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1582 for (i = 0; ; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1583 p = strchr(path, delim);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1584 if (p == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1585 p = strchr(path, '\0'); /* End of string */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1586 w = PyString_FromStringAndSize(path, (Py_ssize_t) (p - path));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1587 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1588 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1589 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1590 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1591 PyList_SetItem(v, i, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1592 if (*p == '\0')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1593 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1594 path = p+1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1595 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1596 return v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1597 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1598
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1599 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1600 PySys_SetPath(char *path)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1601 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1602 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1603 if ((v = makepathobject(path, DELIM)) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1604 Py_FatalError("can't create sys.path");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1605 if (PySys_SetObject("path", v) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1606 Py_FatalError("can't assign sys.path");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1607 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
1608 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1609
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1610 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1611 makeargvobject(int argc, char **argv)
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1612 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1613 PyObject *av;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1614 if (argc <= 0 || argv == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1615 /* Ensure at least one (empty) argument is seen */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1616 static char *empty_argv[1] = {""};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1617 argv = empty_argv;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1618 argc = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1619 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1620 av = PyList_New(argc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1621 if (av != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1622 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1623 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
1624 #ifdef __VMS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1625 PyObject *v;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1626
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1627 /* argv[0] is the script pathname if known */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1628 if (i == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1629 char* fn = decc$translate_vms(argv[0]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1630 if ((fn == (char *)0) || fn == (char *)-1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1631 v = PyString_FromString(argv[0]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1632 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1633 v = PyString_FromString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1634 decc$translate_vms(argv[0]));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1635 } else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1636 v = PyString_FromString(argv[i]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1637 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1638 PyObject *v = PyString_FromString(argv[i]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1639 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1640 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1641 Py_DECREF(av);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1642 av = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1643 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1644 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1645 PyList_SetItem(av, i, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1646 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1647 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1648 return av;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1649 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1650
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1651 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1652 PySys_SetArgv(int argc, char **argv)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1653 {
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
1654 #if defined(HAVE_REALPATH)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1655 char fullpath[MAXPATHLEN];
50788
e11c99e1e6e7 Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47925
diff changeset
1656 #elif defined(MS_WINDOWS) && !defined(MS_WINCE)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1657 char fullpath[MAX_PATH];
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1658 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1659 PyObject *av = makeargvobject(argc, argv);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1660 PyObject *path = PySys_GetObject("path");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1661 if (av == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1662 Py_FatalError("no mem for sys.argv");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1663 if (PySys_SetObject("argv", av) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1664 Py_FatalError("can't assign sys.argv");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1665 if (path != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1666 char *argv0 = argv[0];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1667 char *p = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1668 Py_ssize_t n = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1669 PyObject *a;
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1670 #ifdef HAVE_READLINK
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1671 char link[MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1672 char argv0copy[2*MAXPATHLEN+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1673 int nr = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1674 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1675 nr = readlink(argv0, link, MAXPATHLEN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1676 if (nr > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1677 /* It's a symlink */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1678 link[nr] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1679 if (link[0] == SEP)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1680 argv0 = link; /* Link to absolute path */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1681 else if (strchr(link, SEP) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1682 ; /* Link without path */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1683 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1684 /* Must join(dirname(argv0), link) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1685 char *q = strrchr(argv0, SEP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1686 if (q == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1687 argv0 = link; /* argv0 without path */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1688 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1689 /* Must make a copy */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1690 strcpy(argv0copy, argv0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1691 q = strrchr(argv0copy, SEP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1692 strcpy(q+1, link);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1693 argv0 = argv0copy;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1694 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1695 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1696 }
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 #endif /* HAVE_READLINK */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1698 #if SEP == '\\' /* Special case for MS filename syntax */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1699 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1700 char *q;
50788
e11c99e1e6e7 Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47925
diff changeset
1701 #if defined(MS_WINDOWS) && !defined(MS_WINCE)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1702 /* This code here replaces the first element in argv with the full
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1703 path that it represents. Under CE, there are no relative paths so
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1704 the argument must be the full path anyway. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1705 char *ptemp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1706 if (GetFullPathName(argv0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1707 sizeof(fullpath),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1708 fullpath,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1709 &ptemp)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1710 argv0 = fullpath;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1711 }
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1712 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1713 p = strrchr(argv0, SEP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1714 /* Test for alternate separator */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1715 q = strrchr(p ? p : argv0, '/');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1716 if (q != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1717 p = q;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1718 if (p != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1719 n = p + 1 - argv0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1720 if (n > 1 && p[-1] != ':')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1721 n--; /* Drop trailing separator */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1722 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1723 }
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1724 #else /* All other filename syntaxes */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1725 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-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
1726 #if defined(HAVE_REALPATH)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1727 if (realpath(argv0, fullpath)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1728 argv0 = fullpath;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1729 }
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
1730 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1731 p = strrchr(argv0, SEP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1732 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1733 if (p != NULL) {
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1734 #ifndef RISCOS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1735 n = p + 1 - argv0;
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1736 #else /* don't include trailing separator */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1737 n = p - argv0;
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1738 #endif /* RISCOS */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1739 #if SEP == '/' /* Special case for Unix filename syntax */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1740 if (n > 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1741 n--; /* Drop trailing separator */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1742 #endif /* Unix */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1743 }
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1744 #endif /* All others */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1745 a = PyString_FromStringAndSize(argv0, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1746 if (a == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1747 Py_FatalError("no mem for sys.path insertion");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1748 if (PyList_Insert(path, 0, a) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1749 Py_FatalError("sys.path.insert(0) failed");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1750 Py_DECREF(a);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1751 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1752 Py_DECREF(av);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1753 }
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
1754
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1755
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1756 /* 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
1757 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
1758
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1759 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
1760 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
1761
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1762 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
1763 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
1764 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
1765
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1766 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
1767 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
1768
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1769 *** 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
1770
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1771 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
1772 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
1773 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
1774 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
1775 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
1776 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
1777
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1778 */
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1779
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1780 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1781 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
1782 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1783 PyObject *file;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1784 PyObject *error_type, *error_value, *error_traceback;
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1785
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1786 PyErr_Fetch(&error_type, &error_value, &error_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1787 file = PySys_GetObject(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1788 if (file == NULL || PyFile_AsFile(file) == fp)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1789 vfprintf(fp, format, va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1790 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1791 char buffer[1001];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1792 const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1793 format, va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1794 if (PyFile_WriteString(buffer, file) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1795 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1796 fputs(buffer, fp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1797 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1798 if (written < 0 || (size_t)written >= sizeof(buffer)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1799 const char *truncated = "... truncated";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1800 if (PyFile_WriteString(truncated, file) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1801 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1802 fputs(truncated, fp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1803 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1804 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1805 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1806 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
1807 }
f94d5ae642a9 New 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 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
1810 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
1811 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1812 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
1813
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1814 va_start(va, format);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1815 mywrite("stdout", stdout, format, va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1816 va_end(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
1817 }
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1818
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1819 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
1820 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
1821 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1822 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
1823
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1824 va_start(va, format);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1825 mywrite("stderr", stderr, format, va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 59298
diff changeset
1826 va_end(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
1827 }