annotate Python/sysmodule.c @ 86999:01c4a0af73cf

Issue #19512, #19515: remove shared identifiers, move identifiers where they are used. Move also _Py_IDENTIFIER() defintions to the top in modified files to remove identifiers duplicated in the same file.
author Victor Stinner <victor.stinner@gmail.com>
date Thu, 07 Nov 2013 23:07:29 +0100
parents 954167ce92a3
children f39fac22ca9a
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"
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35673
diff changeset
18 #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
19 #include "frameobject.h"
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
20 #include "pythread.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
21
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
22 #include "osdefs.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
23
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
24 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
25 #define WIN32_LEAN_AND_MEAN
43813
1561763cda72 No need to include windows.h twice
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43777
diff changeset
26 #include <windows.h>
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
27 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
28
4291
1427d61f1307 Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents: 4256
diff changeset
29 #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
30 extern void *PyWin_DLLhModule;
6352
b62a7a59414e Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents: 5955
diff changeset
31 /* 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
32 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
33 #endif
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
34
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
35 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
36 #include <unixlib.h>
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
37 #endif
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
38
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
39 #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
40 #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
41 #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
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
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
44 _Py_IDENTIFIER(_);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
45 _Py_IDENTIFIER(__sizeof__);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
46 _Py_IDENTIFIER(buffer);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
47 _Py_IDENTIFIER(builtins);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
48 _Py_IDENTIFIER(encoding);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
49 _Py_IDENTIFIER(path);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
50 _Py_IDENTIFIER(stdout);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
51 _Py_IDENTIFIER(stderr);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
52 _Py_IDENTIFIER(write);
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
53
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
54 PyObject *
86971
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
55 _PySys_GetObjectId(_Py_Identifier *key)
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
56 {
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
57 PyThreadState *tstate = PyThreadState_GET();
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
58 PyObject *sd = tstate->interp->sysdict;
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
59 if (sd == NULL)
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
60 return NULL;
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
61 return _PyDict_GetItemId(sd, key);
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
62 }
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
63
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
64 PyObject *
42812
a99ec4befda8 Add const to input string parameters
Neal Norwitz <nnorwitz@gmail.com>
parents: 42703
diff changeset
65 PySys_GetObject(const char *name)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
67 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
68 PyObject *sd = tstate->interp->sysdict;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
69 if (sd == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
70 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
71 return PyDict_GetItemString(sd, name);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 int
86971
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
75 _PySys_SetObjectId(_Py_Identifier *key, PyObject *v)
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
76 {
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
77 PyThreadState *tstate = PyThreadState_GET();
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
78 PyObject *sd = tstate->interp->sysdict;
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
79 if (v == NULL) {
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
80 if (_PyDict_GetItemId(sd, key) == NULL)
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
81 return 0;
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
82 else
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
83 return _PyDict_DelItemId(sd, key);
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
84 }
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
85 else
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
86 return _PyDict_SetItemId(sd, key, v);
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
87 }
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
88
5e402c16a74c Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
Victor Stinner <victor.stinner@gmail.com>
parents: 86964
diff changeset
89 int
42812
a99ec4befda8 Add const to input string parameters
Neal Norwitz <nnorwitz@gmail.com>
parents: 42703
diff changeset
90 PySys_SetObject(const char *name, PyObject *v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
92 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
93 PyObject *sd = tstate->interp->sysdict;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
94 if (v == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
95 if (PyDict_GetItemString(sd, name) == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
96 return 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
97 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
98 return PyDict_DelItemString(sd, name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
99 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
100 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
101 return PyDict_SetItemString(sd, name, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
104 /* Write repr(o) to sys.stdout using sys.stdout.encoding and 'backslashreplace'
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
105 error handler. If sys.stdout has a buffer attribute, use
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
106 sys.stdout.buffer.write(encoded), otherwise redecode the string and use
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
107 sys.stdout.write(redecoded).
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
108
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
109 Helper function for sys_displayhook(). */
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
110 static int
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
111 sys_displayhook_unencodable(PyObject *outf, PyObject *o)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
112 {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
113 PyObject *stdout_encoding = NULL;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
114 PyObject *encoded, *escaped_str, *repr_str, *buffer, *result;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
115 char *stdout_encoding_str;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
116 int ret;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
117
72848
81380082d216 Use identifier API for PyObject_GetAttrString.
Martin v. Löwis <martin@v.loewis.de>
parents: 72835
diff changeset
118 stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding);
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
119 if (stdout_encoding == NULL)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
120 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
121 stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
122 if (stdout_encoding_str == NULL)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
123 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
124
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
125 repr_str = PyObject_Repr(o);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
126 if (repr_str == NULL)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
127 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
128 encoded = PyUnicode_AsEncodedString(repr_str,
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
129 stdout_encoding_str,
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
130 "backslashreplace");
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
131 Py_DECREF(repr_str);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
132 if (encoded == NULL)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
133 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
134
72848
81380082d216 Use identifier API for PyObject_GetAttrString.
Martin v. Löwis <martin@v.loewis.de>
parents: 72835
diff changeset
135 buffer = _PyObject_GetAttrId(outf, &PyId_buffer);
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
136 if (buffer) {
72835
5e33219492bc Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents: 72510
diff changeset
137 result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded);
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
138 Py_DECREF(buffer);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
139 Py_DECREF(encoded);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
140 if (result == NULL)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
141 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
142 Py_DECREF(result);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
143 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
144 else {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
145 PyErr_Clear();
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
146 escaped_str = PyUnicode_FromEncodedObject(encoded,
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
147 stdout_encoding_str,
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
148 "strict");
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
149 Py_DECREF(encoded);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
150 if (PyFile_WriteObject(escaped_str, outf, Py_PRINT_RAW) != 0) {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
151 Py_DECREF(escaped_str);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
152 goto error;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
153 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
154 Py_DECREF(escaped_str);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
155 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
156 ret = 0;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
157 goto finally;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
158
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
159 error:
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
160 ret = -1;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
161 finally:
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
162 Py_XDECREF(stdout_encoding);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
163 return ret;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
164 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
165
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
166 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
167 sys_displayhook(PyObject *self, PyObject *o)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
168 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
169 PyObject *outf;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
170 PyInterpreterState *interp = PyThreadState_GET()->interp;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
171 PyObject *modules = interp->modules;
86964
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
172 PyObject *builtins;
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
173 static PyObject *newline = NULL;
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
174 int err;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
175
86964
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
176 builtins = _PyDict_GetItemId(modules, &PyId_builtins);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
177 if (builtins == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
178 PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
179 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
180 }
18805
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
181
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
182 /* Print value except if None */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
183 /* After printing, also assign to '_' */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
184 /* Before, set '_' to None to avoid recursion */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
185 if (o == Py_None) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
186 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
187 return Py_None;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
188 }
72926
db4aa878cea2 Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents: 72925
diff changeset
189 if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
190 return NULL;
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
191 outf = _PySys_GetObjectId(&PyId_stdout);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
192 if (outf == NULL || outf == Py_None) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
193 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
194 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
195 }
66719
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
196 if (PyFile_WriteObject(o, outf, 0) != 0) {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
197 if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError)) {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
198 /* repr(o) is not encodable to sys.stdout.encoding with
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
199 * sys.stdout.errors error handler (which is probably 'strict') */
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
200 PyErr_Clear();
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
201 err = sys_displayhook_unencodable(outf, o);
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
202 if (err)
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
203 return NULL;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
204 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
205 else {
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
206 return NULL;
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
207 }
ba709ad3ff4c Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66556
diff changeset
208 }
86964
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
209 if (newline == NULL) {
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
210 newline = PyUnicode_FromString("\n");
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
211 if (newline == NULL)
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
212 return NULL;
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
213 }
a2f42d57b91d Issue #19512: sys_displayhook() now uses an identifier for "builtins"
Victor Stinner <victor.stinner@gmail.com>
parents: 86715
diff changeset
214 if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
215 return NULL;
72926
db4aa878cea2 Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
Martin v. Löwis <martin@v.loewis.de>
parents: 72925
diff changeset
216 if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
217 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
218 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
219 return Py_None;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
220 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
221
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
222 PyDoc_STRVAR(displayhook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
223 "displayhook(object) -> None\n"
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
224 "\n"
59302
4b413dfa27f9 Merged revisions 78622 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 55611
diff changeset
225 "Print an object to sys.stdout and also save it in builtins._\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
226 );
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
227
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
228 static PyObject *
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
229 sys_excepthook(PyObject* self, PyObject* args)
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
230 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
231 PyObject *exc, *value, *tb;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
232 if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
233 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
234 PyErr_Display(exc, value, tb);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
235 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
236 return Py_None;
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
237 }
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
238
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
239 PyDoc_STRVAR(excepthook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
240 "excepthook(exctype, value, traceback) -> None\n"
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
241 "\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
242 "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
243 );
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
244
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
245 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
246 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
247 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
248 PyThreadState *tstate;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
249 tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
250 return Py_BuildValue(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
251 "(OOO)",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
252 tstate->exc_type != NULL ? tstate->exc_type : Py_None,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
253 tstate->exc_value != NULL ? tstate->exc_value : Py_None,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
254 tstate->exc_traceback != NULL ?
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
255 tstate->exc_traceback : Py_None);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
256 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
257
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
258 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
259 "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
260 \n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
261 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
262 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
263 );
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
264
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
265 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
266 sys_exit(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
268 PyObject *exit_code = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
269 if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
270 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
271 /* Raise SystemExit so callers may catch it or clean up. */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
272 PyErr_SetObject(PyExc_SystemExit, exit_code);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
273 return NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
276 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
277 "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
278 \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
279 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
280 If the status is omitted or None, it defaults to zero (i.e., success).\n\
85412
694e50a79638 #18839: document that sys.exit() will not accept a non-integer numeric value as exit status.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 84785
diff changeset
281 If the status is an integer, 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
282 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
283 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
284 );
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
285
20943
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
286
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
287 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
288 sys_getdefaultencoding(PyObject *self)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
289 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
290 return PyUnicode_FromString(PyUnicode_GetDefaultEncoding());
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
291 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
292
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
293 PyDoc_STRVAR(getdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
294 "getdefaultencoding() -> string\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
295 \n\
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
296 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
297 implementation."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
298 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
299
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
300 static PyObject *
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
301 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
302 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
303 if (Py_FileSystemDefaultEncoding)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
304 return PyUnicode_FromString(Py_FileSystemDefaultEncoding);
69077
a00b9a5688da sys.getfilesystemencoding() raises a RuntimeError if initfsencoding() was not
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68489
diff changeset
305 PyErr_SetString(PyExc_RuntimeError,
a00b9a5688da sys.getfilesystemencoding() raises a RuntimeError if initfsencoding() was not
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68489
diff changeset
306 "filesystem encoding is not initialized");
a00b9a5688da sys.getfilesystemencoding() raises a RuntimeError if initfsencoding() was not
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68489
diff changeset
307 return NULL;
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
308 }
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
309
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
310 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
311 "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
312 \n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
313 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
314 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
315 );
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
316
49403
e822992cf6ce Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents: 48499
diff changeset
317 static PyObject *
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
318 sys_intern(PyObject *self, PyObject *args)
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
319 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
320 PyObject *s;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
321 if (!PyArg_ParseTuple(args, "U:intern", &s))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
322 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
323 if (PyUnicode_CheckExact(s)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
324 Py_INCREF(s);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
325 PyUnicode_InternInPlace(&s);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
326 return s;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
327 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
328 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
329 PyErr_Format(PyExc_TypeError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
330 "can't intern %.400s", s->ob_type->tp_name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
331 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
332 }
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
333 }
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
334
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
335 PyDoc_STRVAR(intern_doc,
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
336 "intern(string) -> string\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
337 \n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
338 ``Intern'' the given string. This enters the string in the (global)\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
339 table of interned strings whose purpose is to speed up dictionary lookups.\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
340 Return the string itself or the previously interned string object with the\n\
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
341 same value.");
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
342
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 40450
diff changeset
343
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
344 /*
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
345 * 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
346 * 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
347 */
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
348 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
349
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
350 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
351 trace_init(void)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
352 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
353 static char *whatnames[7] = {"call", "exception", "line", "return",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
354 "c_call", "c_exception", "c_return"};
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
355 PyObject *name;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
356 int i;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
357 for (i = 0; i < 7; ++i) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
358 if (whatstrings[i] == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
359 name = PyUnicode_InternFromString(whatnames[i]);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
360 if (name == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
361 return -1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
362 whatstrings[i] = name;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
363 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
364 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
365 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
366 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
367
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
368
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
369 static PyObject *
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
370 call_trampoline(PyThreadState *tstate, PyObject* callback,
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
371 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
372 {
86715
4ef4578db38a Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents: 86693
diff changeset
373 PyObject *args;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
374 PyObject *whatstr;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
375 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
376
86715
4ef4578db38a Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents: 86693
diff changeset
377 args = PyTuple_New(3);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
378 if (args == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
379 return NULL;
86715
4ef4578db38a Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents: 86693
diff changeset
380 if (PyFrame_FastToLocalsWithError(frame) < 0)
4ef4578db38a Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents: 86693
diff changeset
381 return NULL;
4ef4578db38a Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
Victor Stinner <victor.stinner@gmail.com>
parents: 86693
diff changeset
382
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
383 Py_INCREF(frame);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
384 whatstr = whatstrings[what];
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
385 Py_INCREF(whatstr);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
386 if (arg == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
387 arg = Py_None;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
388 Py_INCREF(arg);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
389 PyTuple_SET_ITEM(args, 0, (PyObject *)frame);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
390 PyTuple_SET_ITEM(args, 1, whatstr);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
391 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
392
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
393 /* call the Python-level function */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
394 result = PyEval_CallObject(callback, args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
395 PyFrame_LocalsToFast(frame, 1);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
396 if (result == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
397 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
398
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
399 /* cleanup */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
400 Py_DECREF(args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
401 return result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
402 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
403
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
404 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
405 profile_trampoline(PyObject *self, PyFrameObject *frame,
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
406 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
407 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
408 PyThreadState *tstate = frame->f_tstate;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
409 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
410
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
411 if (arg == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
412 arg = Py_None;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
413 result = call_trampoline(tstate, self, frame, what, arg);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
414 if (result == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
415 PyEval_SetProfile(NULL, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
416 return -1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
417 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
418 Py_DECREF(result);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
419 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
420 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
421
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
422 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
423 trace_trampoline(PyObject *self, PyFrameObject *frame,
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
424 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
425 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
426 PyThreadState *tstate = frame->f_tstate;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
427 PyObject *callback;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
428 PyObject *result;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
429
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
430 if (what == PyTrace_CALL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
431 callback = self;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
432 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
433 callback = frame->f_trace;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
434 if (callback == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
435 return 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
436 result = call_trampoline(tstate, callback, frame, what, arg);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
437 if (result == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
438 PyEval_SetTrace(NULL, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
439 Py_XDECREF(frame->f_trace);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
440 frame->f_trace = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
441 return -1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
442 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
443 if (result != Py_None) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
444 PyObject *temp = frame->f_trace;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
445 frame->f_trace = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
446 Py_XDECREF(temp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
447 frame->f_trace = result;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
448 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
449 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
450 Py_DECREF(result);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
451 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
452 return 0;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
453 }
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
454
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
455 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
456 sys_settrace(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
457 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
458 if (trace_init() == -1)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
459 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
460 if (args == Py_None)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
461 PyEval_SetTrace(NULL, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
462 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
463 PyEval_SetTrace(trace_trampoline, args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
464 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
465 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
466 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
467
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
468 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
469 "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
470 \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
471 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
472 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
473 );
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
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
475 static PyObject *
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
476 sys_gettrace(PyObject *self, PyObject *args)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
477 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
478 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
479 PyObject *temp = tstate->c_traceobj;
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
480
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
481 if (temp == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
482 temp = Py_None;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
483 Py_INCREF(temp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
484 return temp;
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
485 }
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
486
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
487 PyDoc_STRVAR(gettrace_doc,
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
488 "gettrace()\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
489 \n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
490 Return the global debug tracing function set with sys.settrace.\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
491 See the debugger chapter in the library manual."
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
492 );
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
493
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
494 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
495 sys_setprofile(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
496 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
497 if (trace_init() == -1)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
498 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
499 if (args == Py_None)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
500 PyEval_SetProfile(NULL, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
501 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
502 PyEval_SetProfile(profile_trampoline, args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
503 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
504 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
505 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
506
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
507 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
508 "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
509 \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
510 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
511 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
512 );
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
513
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
514 static PyObject *
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
515 sys_getprofile(PyObject *self, PyObject *args)
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
516 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
517 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
518 PyObject *temp = tstate->c_profileobj;
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
519
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
520 if (temp == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
521 temp = Py_None;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
522 Py_INCREF(temp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
523 return temp;
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
524 }
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
525
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
526 PyDoc_STRVAR(getprofile_doc,
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
527 "getprofile()\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
528 \n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
529 Return the profiling function set with sys.setprofile.\n\
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
530 See the profiler chapter in the library manual."
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
531 );
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
532
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
533 static int _check_interval = 100;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
534
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
535 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
536 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
537 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
538 if (PyErr_WarnEx(PyExc_DeprecationWarning,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
539 "sys.getcheckinterval() and sys.setcheckinterval() "
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
540 "are deprecated. Use sys.setswitchinterval() "
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
541 "instead.", 1) < 0)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
542 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
543 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval))
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
544 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
545 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
546 return Py_None;
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
547 }
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
548
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
549 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
550 "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
551 \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
552 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
553 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
554 );
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
555
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
556 static PyObject *
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
557 sys_getcheckinterval(PyObject *self, PyObject *args)
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
558 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
559 if (PyErr_WarnEx(PyExc_DeprecationWarning,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
560 "sys.getcheckinterval() and sys.setcheckinterval() "
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
561 "are deprecated. Use sys.getswitchinterval() "
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
562 "instead.", 1) < 0)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
563 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
564 return PyLong_FromLong(_check_interval);
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
565 }
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
566
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
567 PyDoc_STRVAR(getcheckinterval_doc,
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
568 "getcheckinterval() -> current check interval; see setcheckinterval()."
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
569 );
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
570
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
571 #ifdef WITH_THREAD
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
572 static PyObject *
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
573 sys_setswitchinterval(PyObject *self, PyObject *args)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
574 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
575 double d;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
576 if (!PyArg_ParseTuple(args, "d:setswitchinterval", &d))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
577 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
578 if (d <= 0.0) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
579 PyErr_SetString(PyExc_ValueError,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
580 "switch interval must be strictly positive");
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
581 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
582 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
583 _PyEval_SetSwitchInterval((unsigned long) (1e6 * d));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
584 Py_INCREF(Py_None);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
585 return Py_None;
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
586 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
587
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
588 PyDoc_STRVAR(setswitchinterval_doc,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
589 "setswitchinterval(n)\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
590 \n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
591 Set the ideal thread switching delay inside the Python interpreter\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
592 The actual frequency of switching threads can be lower if the\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
593 interpreter executes long sequences of uninterruptible code\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
594 (this is implementation-specific and workload-dependent).\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
595 \n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
596 The parameter must represent the desired switching delay in seconds\n\
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
597 A typical value is 0.005 (5 milliseconds)."
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
598 );
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
599
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
600 static PyObject *
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
601 sys_getswitchinterval(PyObject *self, PyObject *args)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
602 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
603 return PyFloat_FromDouble(1e-6 * _PyEval_GetSwitchInterval());
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
604 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
605
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
606 PyDoc_STRVAR(getswitchinterval_doc,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
607 "getswitchinterval() -> current thread switch interval; see setswitchinterval()."
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
608 );
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
609
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
610 #endif /* WITH_THREAD */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
611
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
612 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
613 static PyObject *
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
614 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
615 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
616 int bool;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
617 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
618
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
619 if (!PyArg_ParseTuple(args, "i:settscdump", &bool))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
620 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
621 if (bool)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
622 tstate->interp->tscdump = 1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
623 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
624 tstate->interp->tscdump = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
625 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
626 return Py_None;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
627
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
628 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
629
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
630 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
631 "settscdump(bool)\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
632 \n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
633 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
634 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
635 processor's time-stamp counter."
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
636 );
32344
748129e6e108 Remove compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 32301
diff changeset
637 #endif /* TSC */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
638
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
639 static PyObject *
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
640 sys_setrecursionlimit(PyObject *self, PyObject *args)
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
641 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
642 int new_limit;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
643 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
644 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
645 if (new_limit <= 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
646 PyErr_SetString(PyExc_ValueError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
647 "recursion limit must be positive");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
648 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
649 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
650 Py_SetRecursionLimit(new_limit);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
651 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
652 return Py_None;
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
653 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
654
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
655 static PyTypeObject Hash_InfoType;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
656
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
657 PyDoc_STRVAR(hash_info_doc,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
658 "hash_info\n\
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
659 \n\
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
660 A struct sequence providing parameters used for computing\n\
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
661 numeric hashes. The attributes are read only.");
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
662
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
663 static PyStructSequence_Field hash_info_fields[] = {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
664 {"width", "width of the type used for hashing, in bits"},
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
665 {"modulus", "prime number giving the modulus on which the hash "
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
666 "function is based"},
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
667 {"inf", "value to be used for hash of a positive infinity"},
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
668 {"nan", "value to be used for hash of a nan"},
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
669 {"imag", "multiplier used for the imaginary part of a complex number"},
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
670 {NULL, NULL}
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
671 };
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
672
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
673 static PyStructSequence_Desc hash_info_desc = {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
674 "sys.hash_info",
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
675 hash_info_doc,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
676 hash_info_fields,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
677 5,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
678 };
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
679
62828
1f37d082a9aa - sysmodule.c (get_hash_info): Define as static function.
Matthias Klose <doko@ubuntu.com>
parents: 62189
diff changeset
680 static PyObject *
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
681 get_hash_info(void)
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
682 {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
683 PyObject *hash_info;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
684 int field = 0;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
685 hash_info = PyStructSequence_New(&Hash_InfoType);
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
686 if (hash_info == NULL)
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
687 return NULL;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
688 PyStructSequence_SET_ITEM(hash_info, field++,
65494
e8969fb822fc make hashes always the size of pointers; introduce Py_hash_t #9778
Benjamin Peterson <benjamin@python.org>
parents: 65389
diff changeset
689 PyLong_FromLong(8*sizeof(Py_hash_t)));
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
690 PyStructSequence_SET_ITEM(hash_info, field++,
65603
be8ae6b17539 follow up to #9778: define and use an unsigned hash type
Benjamin Peterson <benjamin@python.org>
parents: 65575
diff changeset
691 PyLong_FromSsize_t(_PyHASH_MODULUS));
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
692 PyStructSequence_SET_ITEM(hash_info, field++,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
693 PyLong_FromLong(_PyHASH_INF));
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
694 PyStructSequence_SET_ITEM(hash_info, field++,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
695 PyLong_FromLong(_PyHASH_NAN));
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
696 PyStructSequence_SET_ITEM(hash_info, field++,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
697 PyLong_FromLong(_PyHASH_IMAG));
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
698 if (PyErr_Occurred()) {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
699 Py_CLEAR(hash_info);
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
700 return NULL;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
701 }
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
702 return hash_info;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
703 }
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
704
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
705
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
706 PyDoc_STRVAR(setrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
707 "setrecursionlimit(n)\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
708 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
709 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
710 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
711 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
712 dependent."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
713 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
714
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
715 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
716 sys_getrecursionlimit(PyObject *self)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
717 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
718 return PyLong_FromLong(Py_GetRecursionLimit());
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
719 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
720
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
721 PyDoc_STRVAR(getrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
722 "getrecursionlimit()\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
723 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
724 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
725 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
726 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
727 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
728
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
729 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
730 PyDoc_STRVAR(getwindowsversion_doc,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
731 "getwindowsversion()\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
732 \n\
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
733 Return information about the running version of Windows as a named tuple.\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
734 The members are named: major, minor, build, platform, service_pack,\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
735 service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\
68489
81d7f78a633a #11515: Merge with 3.1.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 68276
diff changeset
736 backward compatibility, only the first 5 items are available by indexing.\n\
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
737 All elements are numbers, except service_pack which is a string. Platform\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
738 may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
739 3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n\
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
740 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
741 );
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
742
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
743 static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0};
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
744
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
745 static PyStructSequence_Field windows_version_fields[] = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
746 {"major", "Major version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
747 {"minor", "Minor version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
748 {"build", "Build number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
749 {"platform", "Operating system platform"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
750 {"service_pack", "Latest Service Pack installed on the system"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
751 {"service_pack_major", "Service Pack major version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
752 {"service_pack_minor", "Service Pack minor version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
753 {"suite_mask", "Bit mask identifying available product suites"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
754 {"product_type", "System product type"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
755 {0}
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
756 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
757
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
758 static PyStructSequence_Desc windows_version_desc = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
759 "sys.getwindowsversion", /* name */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
760 getwindowsversion_doc, /* doc */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
761 windows_version_fields, /* fields */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
762 5 /* For backward compatibility,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
763 only the first 5 items are accessible
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
764 via indexing, the rest are name only */
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
765 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
766
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
767 static PyObject *
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
768 sys_getwindowsversion(PyObject *self)
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
769 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
770 PyObject *version;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
771 int pos = 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
772 OSVERSIONINFOEX ver;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
773 ver.dwOSVersionInfoSize = sizeof(ver);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
774 if (!GetVersionEx((OSVERSIONINFO*) &ver))
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
775 return PyErr_SetFromWindowsErr(0);
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
776
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
777 version = PyStructSequence_New(&WindowsVersionType);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
778 if (version == NULL)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
779 return NULL;
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
780
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
781 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMajorVersion));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
782 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
783 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
784 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
785 PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromString(ver.szCSDVersion));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
786 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
787 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
788 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
789 PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
790
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
791 return version;
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
792 }
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
793
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
794 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
795
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
796 #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
797 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
798 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
799 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
800 int new_val;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
801 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
802 if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
803 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
804 if (!tstate)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
805 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
806 tstate->interp->dlopenflags = new_val;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
807 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
808 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
809 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
810
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
811 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
812 "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
813 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
814 Set the flags used by the interpreter for dlopen calls, such as when the\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
815 interpreter loads extension modules. Among other things, this will enable\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
816 a lazy resolving of symbols when importing a module, if called as\n\
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
817 sys.setdlopenflags(0). To share symbols across extension modules, call as\n\
84239
1da78c7d382b #13226: update references from ctypes/DLFCN modules to os module
Andrew Kuchling <amk@amk.ca>
parents: 80777
diff changeset
818 sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules\n\
73243
05e2bdc00c0c Issue #13226: Update sys.setdlopenflags() docstring
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72926
diff changeset
819 can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY).");
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
820
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
821 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
822 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
823 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
824 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
825 if (!tstate)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
826 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
827 return PyLong_FromLong(tstate->interp->dlopenflags);
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
828 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
829
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
830 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
831 "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
832 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
833 Return the current value of the flags that are used for dlopen calls.\n\
84239
1da78c7d382b #13226: update references from ctypes/DLFCN modules to os module
Andrew Kuchling <amk@amk.ca>
parents: 80777
diff changeset
834 The flag constants are defined in the os module.");
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
835
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
836 #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
837
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
838 #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
839 /* 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
840 #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
841
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
842 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
843 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
844 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
845 int flag;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
846 if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
847 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
848 mallopt(M_DEBUG, flag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
849 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
850 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
851 }
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
852 #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
853
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
854 static PyObject *
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
855 sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
856 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
857 PyObject *res = NULL;
74578
7d96679c5d46 use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents: 73243
diff changeset
858 static PyObject *gc_head_size = NULL;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
859 static char *kwlist[] = {"object", "default", 0};
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
860 PyObject *o, *dflt = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
861 PyObject *method;
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
862
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
863 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
864 kwlist, &o, &dflt))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
865 return NULL;
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
866
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
867 /* Initialize static variable for GC head size */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
868 if (gc_head_size == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
869 gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
870 if (gc_head_size == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
871 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
872 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
873
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
874 /* Make sure the type is initialized. float gets initialized late */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
875 if (PyType_Ready(Py_TYPE(o)) < 0)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
876 return NULL;
53954
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
877
74578
7d96679c5d46 use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents: 73243
diff changeset
878 method = _PyObject_LookupSpecial(o, &PyId___sizeof__);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
879 if (method == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
880 if (!PyErr_Occurred())
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
881 PyErr_Format(PyExc_TypeError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
882 "Type %.100s doesn't define __sizeof__",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
883 Py_TYPE(o)->tp_name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
884 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
885 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
886 res = PyObject_CallFunctionObjArgs(method, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
887 Py_DECREF(method);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
888 }
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
889
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
890 /* Has a default value been given */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
891 if ((res == NULL) && (dflt != NULL) &&
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
892 PyErr_ExceptionMatches(PyExc_TypeError))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
893 {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
894 PyErr_Clear();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
895 Py_INCREF(dflt);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
896 return dflt;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
897 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
898 else if (res == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
899 return res;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
900
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
901 /* add gc_head size */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
902 if (PyObject_IS_GC(o)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
903 PyObject *tmp = res;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
904 res = PyNumber_Add(tmp, gc_head_size);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
905 Py_DECREF(tmp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
906 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
907 return res;
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
908 }
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
909
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
910 PyDoc_STRVAR(getsizeof_doc,
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
911 "getsizeof(object, default) -> int\n\
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
912 \n\
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
913 Return the size of object in bytes.");
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
914
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
915 static PyObject *
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
916 sys_getrefcount(PyObject *self, PyObject *arg)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
917 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
918 return PyLong_FromSsize_t(arg->ob_refcnt);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
919 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
920
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
921 #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
922 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
923 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
924 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
925 return PyLong_FromSsize_t(_Py_GetRefTotal());
12965
04c89d77dfdb Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents: 12877
diff changeset
926 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
927 #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
928
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
929 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
930 "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
931 \n\
23947
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
932 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
933 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
934 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
935 );
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
936
80777
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
937 static PyObject *
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
938 sys_getallocatedblocks(PyObject *self)
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
939 {
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
940 return PyLong_FromSsize_t(_Py_GetAllocatedBlocks());
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
941 }
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
942
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
943 PyDoc_STRVAR(getallocatedblocks_doc,
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
944 "getallocatedblocks() -> integer\n\
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
945 \n\
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
946 Return the number of memory blocks currently allocated, regardless of their\n\
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
947 size."
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
948 );
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
949
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
950 #ifdef COUNT_ALLOCS
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
951 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
952 sys_getcounts(PyObject *self)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
953 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
954 extern PyObject *get_counts(void);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
955
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
956 return get_counts();
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
957 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
958 #endif
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
959
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
960 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
961 "_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
962 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
963 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
964 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
965 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
966 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
967 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
968 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
969 purposes only."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
970 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
971
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
972 static PyObject *
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
973 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
974 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
975 PyFrameObject *f = PyThreadState_GET()->frame;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
976 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
977
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
978 if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
979 return NULL;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
980
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
981 while (depth > 0 && f != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
982 f = f->f_back;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
983 --depth;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
984 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
985 if (f == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
986 PyErr_SetString(PyExc_ValueError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
987 "call stack is not deep enough");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
988 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
989 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
990 Py_INCREF(f);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
991 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
992 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
993
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
994 PyDoc_STRVAR(current_frames_doc,
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
995 "_current_frames() -> dictionary\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
996 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
997 Return a dictionary mapping each current thread T's thread id to T's\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
998 current stack frame.\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
999 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1000 This function should be used for specialized purposes only."
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1001 );
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1002
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1003 static PyObject *
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1004 sys_current_frames(PyObject *self, PyObject *noargs)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1005 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1006 return _PyThread_CurrentFrames();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1007 }
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1008
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1009 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
1010 "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
1011 \n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1012 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
1013 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
1014 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
1015 );
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1016
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1017 static PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1018 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
1019 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1020 PyObject *func, *funcargs;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1021 if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1022 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1023 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
1024 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1025
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1026 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
1027 "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
1028 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1029 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
1030 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
1031 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1032 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
1033 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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 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
1041 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
1042 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
1043 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
1044 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
1045 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
1046 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
1047 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
1048
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1049 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1050 extern "C" {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1051 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1052
77577
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1053 static PyObject *
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1054 sys_debugmallocstats(PyObject *self, PyObject *args)
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1055 {
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1056 #ifdef WITH_PYMALLOC
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1057 _PyObject_DebugMallocStats(stderr);
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1058 fputc('\n', stderr);
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1059 #endif
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1060 _PyObject_DebugTypeStats(stderr);
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1061
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1062 Py_RETURN_NONE;
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1063 }
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1064 PyDoc_STRVAR(debugmallocstats_doc,
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1065 "_debugmallocstats()\n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1066 \n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1067 Print summary info to stderr about the state of\n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1068 pymalloc's structures.\n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1069 \n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1070 In Py_DEBUG mode, also perform some expensive internal consistency\n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1071 checks.\n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1072 ");
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1073
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
1074 #ifdef Py_TRACE_REFS
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
1075 /* 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
1076 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1077 #endif
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
1078
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1079 #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
1080 /* 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
1081 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
1082 #endif
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1083
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1084 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1085 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1086 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1087
45145
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1088 static PyObject *
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1089 sys_clear_type_cache(PyObject* self, PyObject* args)
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1090 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1091 PyType_ClearCache();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1092 Py_RETURN_NONE;
45145
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1093 }
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1094
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1095 PyDoc_STRVAR(sys_clear_type_cache__doc__,
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1096 "_clear_type_cache() -> None\n\
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1097 Clear the internal type lookup cache.");
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1098
3d7b84daa34a Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552-60567 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45071
diff changeset
1099
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1100 static PyMethodDef sys_methods[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1101 /* Might as well keep this in alphabetic order */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1102 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1103 callstats_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1104 {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1105 sys_clear_type_cache__doc__},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1106 {"_current_frames", sys_current_frames, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1107 current_frames_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1108 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1109 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1110 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1111 {"exit", sys_exit, METH_VARARGS, exit_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1112 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1113 METH_NOARGS, getdefaultencoding_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
1114 #ifdef HAVE_DLOPEN
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1115 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1116 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
1117 #endif
80777
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
1118 {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS,
c40f4c19d20b Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated.
Antoine Pitrou <solipsis@pitrou.net>
parents: 80520
diff changeset
1119 getallocatedblocks_doc},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1120 #ifdef COUNT_ALLOCS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1121 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1122 #endif
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1123 #ifdef DYNAMIC_EXECUTION_PROFILE
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1124 {"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
1125 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1126 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1127 METH_NOARGS, getfilesystemencoding_doc},
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
1128 #ifdef Py_TRACE_REFS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1129 {"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
1130 #endif
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
1131 #ifdef Py_REF_DEBUG
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1132 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1133 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1134 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1135 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1136 getrecursionlimit_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1137 {"getsizeof", (PyCFunction)sys_getsizeof,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1138 METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1139 {"_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
1140 #ifdef MS_WINDOWS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1141 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1142 getwindowsversion_doc},
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
1143 #endif /* MS_WINDOWS */
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1144 {"intern", sys_intern, METH_VARARGS, intern_doc},
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
1145 #ifdef USE_MALLOPT
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1146 {"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
1147 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1148 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1149 setcheckinterval_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1150 {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1151 getcheckinterval_doc},
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
1152 #ifdef WITH_THREAD
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1153 {"setswitchinterval", sys_setswitchinterval, METH_VARARGS,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1154 setswitchinterval_doc},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1155 {"getswitchinterval", sys_getswitchinterval, METH_NOARGS,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1156 getswitchinterval_doc},
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
1157 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
1158 #ifdef HAVE_DLOPEN
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1159 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1160 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
1161 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1162 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1163 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1164 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1165 setrecursionlimit_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
1166 #ifdef WITH_TSC
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1167 {"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
1168 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1169 {"settrace", sys_settrace, METH_O, settrace_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1170 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1171 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
77577
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1172 {"_debugmallocstats", sys_debugmallocstats, METH_VARARGS,
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1173 debugmallocstats_doc},
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1174 {NULL, NULL} /* sentinel */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1175 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1176
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1177 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1178 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
1179 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1180 PyObject *list = PyList_New(0);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1181 int i;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1182 if (list == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1183 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1184 for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1185 PyObject *name = PyUnicode_FromString(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1186 PyImport_Inittab[i].name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1187 if (name == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1188 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1189 PyList_Append(list, name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1190 Py_DECREF(name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1191 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1192 if (PyList_Sort(list) != 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1193 Py_DECREF(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1194 list = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1195 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1196 if (list) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1197 PyObject *v = PyList_AsTuple(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1198 Py_DECREF(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1199 list = v;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1200 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1201 return list;
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1202 }
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1203
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1204 static PyObject *warnoptions = NULL;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1205
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1206 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1207 PySys_ResetWarnOptions(void)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1208 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1209 if (warnoptions == NULL || !PyList_Check(warnoptions))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1210 return;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1211 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
1212 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1213
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1214 void
61751
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1215 PySys_AddWarnOptionUnicode(PyObject *unicode)
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1216 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1217 if (warnoptions == NULL || !PyList_Check(warnoptions)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1218 Py_XDECREF(warnoptions);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1219 warnoptions = PyList_New(0);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1220 if (warnoptions == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1221 return;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1222 }
61751
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1223 PyList_Append(warnoptions, unicode);
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1224 }
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1225
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1226 void
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1227 PySys_AddWarnOption(const wchar_t *s)
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1228 {
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1229 PyObject *unicode;
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1230 unicode = PyUnicode_FromWideChar(s, -1);
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1231 if (unicode == NULL)
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1232 return;
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1233 PySys_AddWarnOptionUnicode(unicode);
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1234 Py_DECREF(unicode);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1235 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1236
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1237 int
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1238 PySys_HasWarnOptions(void)
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1239 {
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1240 return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0;
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1241 }
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1242
65575
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1243 static PyObject *xoptions = NULL;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1244
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1245 static PyObject *
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1246 get_xoptions(void)
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1247 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1248 if (xoptions == NULL || !PyDict_Check(xoptions)) {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1249 Py_XDECREF(xoptions);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1250 xoptions = PyDict_New();
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1251 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1252 return xoptions;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1253 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1254
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1255 void
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1256 PySys_AddXOption(const wchar_t *s)
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1257 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1258 PyObject *opts;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1259 PyObject *name = NULL, *value = NULL;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1260 const wchar_t *name_end;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1261
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1262 opts = get_xoptions();
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1263 if (opts == NULL)
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1264 goto error;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1265
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1266 name_end = wcschr(s, L'=');
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1267 if (!name_end) {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1268 name = PyUnicode_FromWideChar(s, -1);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1269 value = Py_True;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1270 Py_INCREF(value);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1271 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1272 else {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1273 name = PyUnicode_FromWideChar(s, name_end - s);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1274 value = PyUnicode_FromWideChar(name_end + 1, -1);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1275 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1276 if (name == NULL || value == NULL)
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1277 goto error;
68102
e2f96bd29252 Issue #8914: fix various warnings from the Clang static analyzer v254.
Brett Cannon <bcannon@gmail.com>
parents: 67380
diff changeset
1278 PyDict_SetItem(opts, name, value);
65575
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1279 Py_DECREF(name);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1280 Py_DECREF(value);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1281 return;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1282
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1283 error:
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1284 Py_XDECREF(name);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1285 Py_XDECREF(value);
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1286 /* No return value, therefore clear error state if possible */
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1287 if (_Py_atomic_load_relaxed(&_PyThreadState_Current))
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1288 PyErr_Clear();
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1289 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1290
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1291 PyObject *
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1292 PySys_GetXOptions(void)
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1293 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1294 return get_xoptions();
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1295 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1296
8840
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
1297 /* 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
1298 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
1299 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
1300 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
1301 PyDoc_VAR(sys_doc) =
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1302 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
1303 "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
1304 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
1305 \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
1306 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
1307 \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
1308 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
1309 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
1310 modules -- dictionary of loaded modules\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1311 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1312 displayhook -- called to show results in an interactive session\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1313 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
1314 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
1315 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
1316 \n\
48470
3d868254ff7e correct docstring
Benjamin Peterson <benjamin@python.org>
parents: 48467
diff changeset
1317 stdin -- standard input file object; used by input()\n\
40788
e9a6234b26af * Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
Georg Brandl <georg@python.org>
parents: 40737
diff changeset
1318 stdout -- standard output file object; used by print()\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1319 stderr -- standard error object; used for error messages\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1320 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
1321 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
1322 \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
1323 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
1324 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
1325 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
1326 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
1327 traceback has been printed.\n\
9885
030ee50bd8d1 Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents: 9746
diff changeset
1328 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1329 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1330 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1331 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
1332 "\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
1333 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
1334 \n\
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1335 builtin_module_names -- tuple of module names built into this interpreter\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1336 copyright -- copyright notice pertaining to this interpreter\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1337 exec_prefix -- prefix used to find the machine-specific Python library\n\
74727
8b591a86fc91 Merge branch 3.2
Petri Lehtinen <petri@digip.org>
parents: 74578 74725
diff changeset
1338 executable -- absolute path of the executable binary of the Python interpreter\n\
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1339 float_info -- a struct sequence with information about the float implementation.\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1340 float_repr_style -- string indicating the style of repr() output for floats\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1341 hexversion -- version information encoded as a single integer\n\
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1342 implementation -- Python implementation information.\n\
52215
bb5de24a343f Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents: 51378
diff changeset
1343 int_info -- a struct sequence with information about the int implementation.\n\
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42896
diff changeset
1344 maxsize -- the largest supported length of containers.\n\
72503
606652491366 #13054: sys.maxunicode is now always 0x10FFFF.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69710
diff changeset
1345 maxunicode -- the value of the largest Unicode codepoint\n\
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1346 platform -- platform identifier\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1347 prefix -- prefix used to find the Python library\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1348 thread_info -- a struct sequence with information about the thread implementation.\n\
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1349 version -- the version of this interpreter as a string\n\
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1350 version_info -- version information as a named tuple\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1351 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1352 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1353 #ifdef MS_WINDOWS
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1354 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1355 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1356 "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
1357 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
1358 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1359 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1360 #endif /* MS_WINDOWS */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1361 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1362 "__stdin__ -- the original stdin; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1363 __stdout__ -- the original stdout; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1364 __stderr__ -- the original stderr; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1365 __displayhook__ -- the original displayhook; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1366 __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
1367 \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
1368 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
1369 \n\
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 44086
diff changeset
1370 displayhook() -- print an object to the screen, and save it in builtins._\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1371 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
1372 exc_info() -- return thread-safe information about the current exception\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1373 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
1374 getdlopenflags() -- returns flags to be used for dlopen() calls\n\
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1375 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
1376 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
1377 getrecursionlimit() -- return the max recursion depth for the interpreter\n\
47466
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
1378 getsizeof() -- return the size of an object in bytes\n\
44828
ef7d72d98485 Merged revisions 60124-60142 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44699
diff changeset
1379 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
1380 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
1381 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
1382 setprofile() -- set the global profiling function\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
1383 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
1384 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
1385 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1386 )
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
1387 /* 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
1388
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1389
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1390 PyDoc_STRVAR(flags__doc__,
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1391 "sys.flags\n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1392 \n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1393 Flags provided through command line arguments or environment vars.");
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1394
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1395 static PyTypeObject FlagsType;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1396
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1397 static PyStructSequence_Field flags_fields[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1398 {"debug", "-d"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1399 {"inspect", "-i"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1400 {"interactive", "-i"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1401 {"optimize", "-O or -OO"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1402 {"dont_write_bytecode", "-B"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1403 {"no_user_site", "-s"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1404 {"no_site", "-S"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1405 {"ignore_environment", "-E"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1406 {"verbose", "-v"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1407 /* {"unbuffered", "-u"}, */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1408 /* {"skip_first", "-x"}, */
67193
b7be652daf6e Add sys.flags.quiet attribute for the new -q option, as noted missing by Eric in #1772833.
Georg Brandl <georg@python.org>
parents: 66719
diff changeset
1409 {"bytes_warning", "-b"},
b7be652daf6e Add sys.flags.quiet attribute for the new -q option, as noted missing by Eric in #1772833.
Georg Brandl <georg@python.org>
parents: 66719
diff changeset
1410 {"quiet", "-q"},
75073
4a31f6b11e7a Merge from 3.1: Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 74725 75066
diff changeset
1411 {"hash_randomization", "-R"},
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
1412 {"isolated", "-I"},
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1413 {0}
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1414 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1415
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1416 static PyStructSequence_Desc flags_desc = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1417 "sys.flags", /* name */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1418 flags__doc__, /* doc */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1419 flags_fields, /* fields */
75097
ed76dc34b39d Merge 3.2: Issue #13703 plus some related test suite fixes.
Georg Brandl <georg@python.org>
parents: 74727 75073
diff changeset
1420 13
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1421 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1422
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1423 static PyObject*
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1424 make_flags(void)
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1425 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1426 int pos = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1427 PyObject *seq;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1428
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1429 seq = PyStructSequence_New(&FlagsType);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1430 if (seq == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1431 return NULL;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1432
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1433 #define SetFlag(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1434 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1435
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1436 SetFlag(Py_DebugFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1437 SetFlag(Py_InspectFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1438 SetFlag(Py_InteractiveFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1439 SetFlag(Py_OptimizeFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1440 SetFlag(Py_DontWriteBytecodeFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1441 SetFlag(Py_NoUserSiteDirectory);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1442 SetFlag(Py_NoSiteFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1443 SetFlag(Py_IgnoreEnvironmentFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1444 SetFlag(Py_VerboseFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1445 /* SetFlag(saw_unbuffered_flag); */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1446 /* SetFlag(skipfirstline); */
46430
47d9bbe10897 Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46318
diff changeset
1447 SetFlag(Py_BytesWarningFlag);
67193
b7be652daf6e Add sys.flags.quiet attribute for the new -q option, as noted missing by Eric in #1772833.
Georg Brandl <georg@python.org>
parents: 66719
diff changeset
1448 SetFlag(Py_QuietFlag);
75066
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 69481
diff changeset
1449 SetFlag(Py_HashRandomizationFlag);
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
1450 SetFlag(Py_IsolatedFlag);
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1451 #undef SetFlag
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1452
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1453 if (PyErr_Occurred()) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1454 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1455 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1456 return seq;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1457 }
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1458
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1459 PyDoc_STRVAR(version_info__doc__,
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1460 "sys.version_info\n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1461 \n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1462 Version information as a named tuple.");
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1463
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1464 static PyTypeObject VersionInfoType;
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1465
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1466 static PyStructSequence_Field version_info_fields[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1467 {"major", "Major release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1468 {"minor", "Minor release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1469 {"micro", "Patch release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1470 {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1471 {"serial", "Serial release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1472 {0}
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1473 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1474
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1475 static PyStructSequence_Desc version_info_desc = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1476 "sys.version_info", /* name */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1477 version_info__doc__, /* doc */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1478 version_info_fields, /* fields */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1479 5
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1480 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1481
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1482 static PyObject *
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1483 make_version_info(void)
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1484 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1485 PyObject *version_info;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1486 char *s;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1487 int pos = 0;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1488
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1489 version_info = PyStructSequence_New(&VersionInfoType);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1490 if (version_info == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1491 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1492 }
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1493
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1494 /*
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1495 * These release level checks are mutually exclusive and cover
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1496 * the field, so don't get too fancy with the pre-processor!
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1497 */
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1498 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1499 s = "alpha";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1500 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1501 s = "beta";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1502 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1503 s = "candidate";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1504 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1505 s = "final";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1506 #endif
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1507
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1508 #define SetIntItem(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1509 PyStructSequence_SET_ITEM(version_info, pos++, PyLong_FromLong(flag))
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1510 #define SetStrItem(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1511 PyStructSequence_SET_ITEM(version_info, pos++, PyUnicode_FromString(flag))
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1512
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1513 SetIntItem(PY_MAJOR_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1514 SetIntItem(PY_MINOR_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1515 SetIntItem(PY_MICRO_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1516 SetStrItem(s);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1517 SetIntItem(PY_RELEASE_SERIAL);
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1518 #undef SetIntItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1519 #undef SetStrItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1520
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1521 if (PyErr_Occurred()) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1522 Py_CLEAR(version_info);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1523 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1524 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1525 return version_info;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1526 }
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1527
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1528 /* sys.implementation values */
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1529 #define NAME "cpython"
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1530 const char *_PySys_ImplName = NAME;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1531 #define QUOTE(arg) #arg
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1532 #define STRIFY(name) QUOTE(name)
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1533 #define MAJOR STRIFY(PY_MAJOR_VERSION)
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1534 #define MINOR STRIFY(PY_MINOR_VERSION)
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1535 #define TAG NAME "-" MAJOR MINOR;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1536 const char *_PySys_ImplCacheTag = TAG;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1537 #undef NAME
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1538 #undef QUOTE
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1539 #undef STRIFY
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1540 #undef MAJOR
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1541 #undef MINOR
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1542 #undef TAG
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1543
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1544 static PyObject *
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1545 make_impl_info(PyObject *version_info)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1546 {
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1547 int res;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1548 PyObject *impl_info, *value, *ns;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1549
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1550 impl_info = PyDict_New();
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1551 if (impl_info == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1552 return NULL;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1553
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1554 /* populate the dict */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1555
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1556 value = PyUnicode_FromString(_PySys_ImplName);
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1557 if (value == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1558 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1559 res = PyDict_SetItemString(impl_info, "name", value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1560 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1561 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1562 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1563
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1564 value = PyUnicode_FromString(_PySys_ImplCacheTag);
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1565 if (value == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1566 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1567 res = PyDict_SetItemString(impl_info, "cache_tag", value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1568 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1569 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1570 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1571
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1572 res = PyDict_SetItemString(impl_info, "version", version_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1573 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1574 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1575
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1576 value = PyLong_FromLong(PY_VERSION_HEX);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1577 if (value == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1578 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1579 res = PyDict_SetItemString(impl_info, "hexversion", value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1580 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1581 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1582 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1583
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1584 /* dict ready */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1585
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1586 ns = _PyNamespace_New(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1587 Py_DECREF(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1588 return ns;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1589
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1590 error:
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1591 Py_CLEAR(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1592 return NULL;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1593 }
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1594
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1595 static struct PyModuleDef sysmodule = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1596 PyModuleDef_HEAD_INIT,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1597 "sys",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1598 sys_doc,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1599 -1, /* multiple "initialization" just copies the module dict. */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1600 sys_methods,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1601 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1602 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1603 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1604 NULL
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1605 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1606
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1607 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1608 _PySys_Init(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1609 {
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1610 PyObject *m, *sysdict, *version_info;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1611
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1612 m = PyModule_Create(&sysmodule);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1613 if (m == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1614 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1615 sysdict = PyModule_GetDict(m);
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1616 #define SET_SYS_FROM_STRING_BORROW(key, value) \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1617 do { \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1618 int res; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1619 PyObject *v = (value); \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1620 if (v == NULL) \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1621 return NULL; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1622 res = PyDict_SetItemString(sysdict, key, v); \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1623 if (res < 0) { \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1624 return NULL; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1625 } \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1626 } while (0)
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1627 #define SET_SYS_FROM_STRING(key, value) \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1628 do { \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1629 int res; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1630 PyObject *v = (value); \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1631 if (v == NULL) \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1632 return NULL; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1633 res = PyDict_SetItemString(sysdict, key, v); \
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1634 Py_DECREF(v); \
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1635 if (res < 0) { \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1636 return NULL; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1637 } \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1638 } while (0)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1639
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1640 /* Check that stdin is not a directory
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1641 Using shell redirection, you can redirect stdin to a directory,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1642 crashing the Python interpreter. Catch this common mistake here
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1643 and output a useful error message. Note that under MS Windows,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1644 the shell already prevents that. */
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1645 #if !defined(MS_WINDOWS)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1646 {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1647 struct stat sb;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1648 if (fstat(fileno(stdin), &sb) == 0 &&
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1649 S_ISDIR(sb.st_mode)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1650 /* There's nothing more we can do. */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1651 /* Py_FatalError() will core dump, so just exit. */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1652 PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1653 exit(EXIT_FAILURE);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1654 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1655 }
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1656 #endif
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1657
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1658 /* stdin/stdout/stderr are now set by pythonrun.c */
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1659
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1660 SET_SYS_FROM_STRING_BORROW("__displayhook__",
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1661 PyDict_GetItemString(sysdict, "displayhook"));
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1662 SET_SYS_FROM_STRING_BORROW("__excepthook__",
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1663 PyDict_GetItemString(sysdict, "excepthook"));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1664 SET_SYS_FROM_STRING("version",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1665 PyUnicode_FromString(Py_GetVersion()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1666 SET_SYS_FROM_STRING("hexversion",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1667 PyLong_FromLong(PY_VERSION_HEX));
68274
f57c94073b35 Commit the hg build identification patch from the pymigr repo.
Georg Brandl <georg@python.org>
parents: 62190
diff changeset
1668 SET_SYS_FROM_STRING("_mercurial",
f57c94073b35 Commit the hg build identification patch from the pymigr repo.
Georg Brandl <georg@python.org>
parents: 62190
diff changeset
1669 Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
f57c94073b35 Commit the hg build identification patch from the pymigr repo.
Georg Brandl <georg@python.org>
parents: 62190
diff changeset
1670 _Py_hgversion()));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1671 SET_SYS_FROM_STRING("dont_write_bytecode",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1672 PyBool_FromLong(Py_DontWriteBytecodeFlag));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1673 SET_SYS_FROM_STRING("api_version",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1674 PyLong_FromLong(PYTHON_API_VERSION));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1675 SET_SYS_FROM_STRING("copyright",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1676 PyUnicode_FromString(Py_GetCopyright()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1677 SET_SYS_FROM_STRING("platform",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1678 PyUnicode_FromString(Py_GetPlatform()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1679 SET_SYS_FROM_STRING("executable",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1680 PyUnicode_FromWideChar(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1681 Py_GetProgramFullPath(), -1));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1682 SET_SYS_FROM_STRING("prefix",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1683 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1684 SET_SYS_FROM_STRING("exec_prefix",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1685 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1686 SET_SYS_FROM_STRING("base_prefix",
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1687 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1688 SET_SYS_FROM_STRING("base_exec_prefix",
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1689 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1690 SET_SYS_FROM_STRING("maxsize",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1691 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1692 SET_SYS_FROM_STRING("float_info",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1693 PyFloat_GetInfo());
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1694 SET_SYS_FROM_STRING("int_info",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1695 PyLong_GetInfo());
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
1696 /* initialize hash_info */
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1697 if (Hash_InfoType.tp_name == NULL) {
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1698 if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0)
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1699 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1700 }
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
1701 SET_SYS_FROM_STRING("hash_info",
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
1702 get_hash_info());
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1703 SET_SYS_FROM_STRING("maxunicode",
72503
606652491366 #13054: sys.maxunicode is now always 0x10FFFF.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69710
diff changeset
1704 PyLong_FromLong(0x10FFFF));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1705 SET_SYS_FROM_STRING("builtin_module_names",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1706 list_builtin_module_names());
79803
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1707 #if PY_BIG_ENDIAN
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1708 SET_SYS_FROM_STRING("byteorder",
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1709 PyUnicode_FromString("big"));
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1710 #else
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1711 SET_SYS_FROM_STRING("byteorder",
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1712 PyUnicode_FromString("little"));
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1713 #endif
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
1714
4126
c80c515999b9 Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents: 3877
diff changeset
1715 #ifdef MS_COREDLL
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1716 SET_SYS_FROM_STRING("dllhandle",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1717 PyLong_FromVoidPtr(PyWin_DLLhModule));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1718 SET_SYS_FROM_STRING("winver",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1719 PyUnicode_FromString(PyWin_DLLVersionString));
3490
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
1720 #endif
65389
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1721 #ifdef ABIFLAGS
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1722 SET_SYS_FROM_STRING("abiflags",
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1723 PyUnicode_FromString(ABIFLAGS));
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1724 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1725 if (warnoptions == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1726 warnoptions = PyList_New(0);
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1727 if (warnoptions == NULL)
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1728 return NULL;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1729 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1730 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1731 Py_INCREF(warnoptions);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1732 }
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1733 SET_SYS_FROM_STRING_BORROW("warnoptions", warnoptions);
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1734
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1735 SET_SYS_FROM_STRING_BORROW("_xoptions", get_xoptions());
65575
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1736
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1737 /* version_info */
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1738 if (VersionInfoType.tp_name == NULL) {
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1739 if (PyStructSequence_InitType2(&VersionInfoType,
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1740 &version_info_desc) < 0)
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1741 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1742 }
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1743 version_info = make_version_info();
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1744 SET_SYS_FROM_STRING("version_info", version_info);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1745 /* prevent user from creating new instances */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1746 VersionInfoType.tp_init = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1747 VersionInfoType.tp_new = NULL;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1748
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1749 /* implementation */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1750 SET_SYS_FROM_STRING("implementation", make_impl_info(version_info));
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1751
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1752 /* flags */
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1753 if (FlagsType.tp_name == 0) {
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1754 if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0)
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1755 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1756 }
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1757 SET_SYS_FROM_STRING("flags", make_flags());
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1758 /* prevent user from creating new instances */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1759 FlagsType.tp_init = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1760 FlagsType.tp_new = NULL;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1761
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1762
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1763 #if defined(MS_WINDOWS)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1764 /* getwindowsversion */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1765 if (WindowsVersionType.tp_name == 0)
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1766 if (PyStructSequence_InitType2(&WindowsVersionType,
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1767 &windows_version_desc) < 0)
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1768 return NULL;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1769 /* prevent user from creating new instances */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1770 WindowsVersionType.tp_init = NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1771 WindowsVersionType.tp_new = NULL;
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1772 #endif
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1773
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1774 /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1775 #ifndef PY_NO_SHORT_FLOAT_REPR
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1776 SET_SYS_FROM_STRING("float_repr_style",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1777 PyUnicode_FromString("short"));
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1778 #else
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1779 SET_SYS_FROM_STRING("float_repr_style",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1780 PyUnicode_FromString("legacy"));
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1781 #endif
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1782
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1783 #ifdef WITH_THREAD
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1784 SET_SYS_FROM_STRING("thread_info", PyThread_GetInfo());
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1785 #endif
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1786
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1787 #undef SET_SYS_FROM_STRING
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1788 if (PyErr_Occurred())
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1789 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1790 return m;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1791 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1792
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1793 static PyObject *
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1794 makepathobject(const wchar_t *path, wchar_t delim)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1795 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1796 int i, n;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1797 const wchar_t *p;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1798 PyObject *v, *w;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1799
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1800 n = 1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1801 p = path;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1802 while ((p = wcschr(p, delim)) != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1803 n++;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1804 p++;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1805 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1806 v = PyList_New(n);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1807 if (v == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1808 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1809 for (i = 0; ; i++) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1810 p = wcschr(path, delim);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1811 if (p == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1812 p = path + wcslen(path); /* End of string */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1813 w = PyUnicode_FromWideChar(path, (Py_ssize_t)(p - path));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1814 if (w == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1815 Py_DECREF(v);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1816 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1817 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1818 PyList_SetItem(v, i, w);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1819 if (*p == '\0')
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1820 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1821 path = p+1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1822 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1823 return v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1824 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1825
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1826 void
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1827 PySys_SetPath(const wchar_t *path)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1828 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1829 PyObject *v;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1830 if ((v = makepathobject(path, DELIM)) == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1831 Py_FatalError("can't create sys.path");
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
1832 if (_PySys_SetObjectId(&PyId_path, v) != 0)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1833 Py_FatalError("can't assign sys.path");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1834 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
1835 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1836
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1837 static PyObject *
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1838 makeargvobject(int argc, wchar_t **argv)
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1839 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1840 PyObject *av;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1841 if (argc <= 0 || argv == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1842 /* Ensure at least one (empty) argument is seen */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1843 static wchar_t *empty_argv[1] = {L""};
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1844 argv = empty_argv;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1845 argc = 1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1846 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1847 av = PyList_New(argc);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1848 if (av != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1849 int i;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1850 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
1851 #ifdef __VMS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1852 PyObject *v;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1853
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1854 /* argv[0] is the script pathname if known */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1855 if (i == 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1856 char* fn = decc$translate_vms(argv[0]);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1857 if ((fn == (char *)0) || fn == (char *)-1)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1858 v = PyUnicode_FromString(argv[0]);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1859 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1860 v = PyUnicode_FromString(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1861 decc$translate_vms(argv[0]));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1862 } else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1863 v = PyUnicode_FromString(argv[i]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1864 #else
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1865 PyObject *v = PyUnicode_FromWideChar(argv[i], -1);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1866 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1867 if (v == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1868 Py_DECREF(av);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1869 av = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1870 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1871 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1872 PyList_SetItem(av, i, v);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1873 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1874 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1875 return av;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1876 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1877
64110
212a16f906a6 Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents: 64064
diff changeset
1878 #define _HAVE_SCRIPT_ARGUMENT(argc, argv) \
212a16f906a6 Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents: 64064
diff changeset
1879 (argc > 0 && argv0 != NULL && \
212a16f906a6 Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents: 64064
diff changeset
1880 wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0)
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1881
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1882 static void
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1883 sys_update_path(int argc, wchar_t **argv)
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1884 {
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1885 wchar_t *argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1886 wchar_t *p = NULL;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1887 Py_ssize_t n = 0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1888 PyObject *a;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1889 PyObject *path;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1890 #ifdef HAVE_READLINK
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1891 wchar_t link[MAXPATHLEN+1];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1892 wchar_t argv0copy[2*MAXPATHLEN+1];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1893 int nr = 0;
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1894 #endif
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
1895 #if defined(HAVE_REALPATH)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1896 wchar_t fullpath[MAXPATHLEN];
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1897 #elif defined(MS_WINDOWS) && !defined(MS_WINCE)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1898 wchar_t fullpath[MAX_PATH];
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1899 #endif
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1900
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
1901 path = _PySys_GetObjectId(&PyId_path);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1902 if (path == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1903 return;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1904
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1905 argv0 = argv[0];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1906
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1907 #ifdef HAVE_READLINK
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1908 if (_HAVE_SCRIPT_ARGUMENT(argc, argv))
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1909 nr = _Py_wreadlink(argv0, link, MAXPATHLEN);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1910 if (nr > 0) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1911 /* It's a symlink */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1912 link[nr] = '\0';
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1913 if (link[0] == SEP)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1914 argv0 = link; /* Link to absolute path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1915 else if (wcschr(link, SEP) == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1916 ; /* Link without path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1917 else {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1918 /* Must join(dirname(argv0), link) */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1919 wchar_t *q = wcsrchr(argv0, SEP);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1920 if (q == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1921 argv0 = link; /* argv0 without path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1922 else {
84785
dca92e8a011a Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1923 /* Must make a copy, argv0copy has room for 2 * MAXPATHLEN */
dca92e8a011a Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1924 wcsncpy(argv0copy, argv0, MAXPATHLEN);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1925 q = wcsrchr(argv0copy, SEP);
84785
dca92e8a011a Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1926 wcsncpy(q+1, link, MAXPATHLEN);
dca92e8a011a Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1927 q[MAXPATHLEN + 1] = L'\0';
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1928 argv0 = argv0copy;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1929 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1930 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1931 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1932 #endif /* HAVE_READLINK */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1933 #if SEP == '\\' /* Special case for MS filename syntax */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1934 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1935 wchar_t *q;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1936 #if defined(MS_WINDOWS) && !defined(MS_WINCE)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1937 /* This code here replaces the first element in argv with the full
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1938 path that it represents. Under CE, there are no relative paths so
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1939 the argument must be the full path anyway. */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1940 wchar_t *ptemp;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1941 if (GetFullPathNameW(argv0,
72510
b534b56379cb Use the new Py_ARRAY_LENGTH macro
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72503
diff changeset
1942 Py_ARRAY_LENGTH(fullpath),
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1943 fullpath,
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1944 &ptemp)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1945 argv0 = fullpath;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1946 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1947 #endif
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1948 p = wcsrchr(argv0, SEP);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1949 /* Test for alternate separator */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1950 q = wcsrchr(p ? p : argv0, '/');
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1951 if (q != NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1952 p = q;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1953 if (p != NULL) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1954 n = p + 1 - argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1955 if (n > 1 && p[-1] != ':')
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1956 n--; /* Drop trailing separator */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1957 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1958 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1959 #else /* All other filename syntaxes */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1960 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1961 #if defined(HAVE_REALPATH)
65166
8fd5d06462e6 _Py_wrealpath() requires the size of the output buffer
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65162
diff changeset
1962 if (_Py_wrealpath(argv0, fullpath, PATH_MAX)) {
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1963 argv0 = fullpath;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1964 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1965 #endif
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1966 p = wcsrchr(argv0, SEP);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1967 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1968 if (p != NULL) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1969 n = p + 1 - argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1970 #if SEP == '/' /* Special case for Unix filename syntax */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1971 if (n > 1)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1972 n--; /* Drop trailing separator */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1973 #endif /* Unix */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1974 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1975 #endif /* All others */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1976 a = PyUnicode_FromWideChar(argv0, n);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1977 if (a == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1978 Py_FatalError("no mem for sys.path insertion");
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1979 if (PyList_Insert(path, 0, a) < 0)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1980 Py_FatalError("sys.path.insert(0) failed");
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1981 Py_DECREF(a);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1982 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1983
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1984 void
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1985 PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1986 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1987 PyObject *av = makeargvobject(argc, argv);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1988 if (av == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1989 Py_FatalError("no mem for sys.argv");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1990 if (PySys_SetObject("argv", av) != 0)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1991 Py_FatalError("can't assign sys.argv");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1992 Py_DECREF(av);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1993 if (updatepath)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1994 sys_update_path(argc, argv);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1995 }
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
1996
61791
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
1997 void
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
1998 PySys_SetArgv(int argc, wchar_t **argv)
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
1999 {
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
2000 PySys_SetArgvEx(argc, argv, Py_IsolatedFlag == 0);
61791
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2001 }
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2002
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2003 /* Reimplementation of PyFile_WriteString() no calling indirectly
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2004 PyErr_CheckSignals(): avoid the call to PyObject_Str(). */
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2005
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2006 static int
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2007 sys_pyfile_write_unicode(PyObject *unicode, PyObject *file)
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2008 {
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2009 PyObject *writer = NULL, *args = NULL, *result = NULL;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2010 int err;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2011
62190
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2012 if (file == NULL)
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2013 return -1;
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2014
72848
81380082d216 Use identifier API for PyObject_GetAttrString.
Martin v. Löwis <martin@v.loewis.de>
parents: 72835
diff changeset
2015 writer = _PyObject_GetAttrId(file, &PyId_write);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2016 if (writer == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2017 goto error;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2018
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2019 args = PyTuple_Pack(1, unicode);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2020 if (args == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2021 goto error;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2022
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2023 result = PyEval_CallObject(writer, args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2024 if (result == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2025 goto error;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2026 } else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2027 err = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2028 goto finally;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2029 }
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2030
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2031 error:
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2032 err = -1;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2033 finally:
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2034 Py_XDECREF(writer);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2035 Py_XDECREF(args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2036 Py_XDECREF(result);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2037 return err;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2038 }
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2039
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2040 static int
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2041 sys_pyfile_write(const char *text, PyObject *file)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2042 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2043 PyObject *unicode = NULL;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2044 int err;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2045
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2046 if (file == NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2047 return -1;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2048
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2049 unicode = PyUnicode_FromString(text);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2050 if (unicode == NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2051 return -1;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2052
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2053 err = sys_pyfile_write_unicode(unicode, file);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2054 Py_DECREF(unicode);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2055 return err;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2056 }
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
2057
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2058 /* 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
2059 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
2060
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2061 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
2062 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
2063
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2064 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
2065 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
2066 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
2067
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2068 PyErr_CheckSignals() is not called to avoid the execution of the Python
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2069 signal handlers: they may raise a new exception whereas sys_write()
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2070 ignores all exceptions.
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2071
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
2072 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
2073 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
2074
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2075 *** 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
2076
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2077 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
2078 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
2079 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
2080 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
2081 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
2082 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
2083
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2084 */
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2085
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2086 static void
86974
954167ce92a3 Issue #19512: add some common identifiers to only create common strings once,
Victor Stinner <victor.stinner@gmail.com>
parents: 86971
diff changeset
2087 sys_write(_Py_Identifier *key, 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
2088 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2089 PyObject *file;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2090 PyObject *error_type, *error_value, *error_traceback;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2091 char buffer[1001];
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2092 int written;
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2093
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2094 PyErr_Fetch(&error_type, &error_value, &error_traceback);
86974
954167ce92a3 Issue #19512: add some common identifiers to only create common strings once,
Victor Stinner <victor.stinner@gmail.com>
parents: 86971
diff changeset
2095 file = _PySys_GetObjectId(key);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2096 written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2097 if (sys_pyfile_write(buffer, file) != 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2098 PyErr_Clear();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2099 fputs(buffer, fp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2100 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2101 if (written < 0 || (size_t)written >= sizeof(buffer)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2102 const char *truncated = "... truncated";
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2103 if (sys_pyfile_write(truncated, file) != 0)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2104 fputs(truncated, fp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2105 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2106 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
2107 }
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2108
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2109 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
2110 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
2111 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2112 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
2113
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2114 va_start(va, format);
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
2115 sys_write(&PyId_stdout, stdout, format, va);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2116 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
2117 }
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2118
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
2119 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
2120 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
2121 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2122 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
2123
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2124 va_start(va, format);
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
2125 sys_write(&PyId_stderr, stderr, format, va);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2126 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
2127 }
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2128
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2129 static void
86974
954167ce92a3 Issue #19512: add some common identifiers to only create common strings once,
Victor Stinner <victor.stinner@gmail.com>
parents: 86971
diff changeset
2130 sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2131 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2132 PyObject *file, *message;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2133 PyObject *error_type, *error_value, *error_traceback;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2134 char *utf8;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2135
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2136 PyErr_Fetch(&error_type, &error_value, &error_traceback);
86974
954167ce92a3 Issue #19512: add some common identifiers to only create common strings once,
Victor Stinner <victor.stinner@gmail.com>
parents: 86971
diff changeset
2137 file = _PySys_GetObjectId(key);
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2138 message = PyUnicode_FromFormatV(format, va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2139 if (message != NULL) {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2140 if (sys_pyfile_write_unicode(message, file) != 0) {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2141 PyErr_Clear();
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2142 utf8 = _PyUnicode_AsString(message);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2143 if (utf8 != NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2144 fputs(utf8, fp);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2145 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2146 Py_DECREF(message);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2147 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2148 PyErr_Restore(error_type, error_value, error_traceback);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2149 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2150
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2151 void
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2152 PySys_FormatStdout(const char *format, ...)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2153 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2154 va_list va;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2155
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2156 va_start(va, format);
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
2157 sys_format(&PyId_stdout, stdout, format, va);
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2158 va_end(va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2159 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2160
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2161 void
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2162 PySys_FormatStderr(const char *format, ...)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2163 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2164 va_list va;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2165
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2166 va_start(va, format);
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
2167 sys_format(&PyId_stderr, stderr, format, va);
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2168 va_end(va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2169 }