annotate Python/sysmodule.c @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents adb471b9cba1
children
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
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
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\
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
661 hashes. The attributes are read only.");
61873
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"},
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
670 {"algorithm", "name of the algorithm for hashing of str, bytes and "
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
671 "memoryviews"},
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
672 {"hash_bits", "internal output size of hash algorithm"},
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
673 {"seed_bits", "seed size of hash algorithm"},
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
674 {"cutoff", "small string optimization cutoff"},
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
675 {NULL, NULL}
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
676 };
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
677
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
678 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
679 "sys.hash_info",
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
680 hash_info_doc,
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
681 hash_info_fields,
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
682 9,
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
683 };
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
684
62828
1f37d082a9aa - sysmodule.c (get_hash_info): Define as static function.
Matthias Klose <doko@ubuntu.com>
parents: 62189
diff changeset
685 static PyObject *
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
686 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
687 {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
688 PyObject *hash_info;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
689 int field = 0;
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
690 PyHash_FuncDef *hashfunc;
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
691 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
692 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
693 return NULL;
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
694 hashfunc = PyHash_GetFuncDef();
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
695 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
696 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
697 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
698 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
699 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
700 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
701 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
702 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
703 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
704 PyLong_FromLong(_PyHASH_IMAG));
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
705 PyStructSequence_SET_ITEM(hash_info, field++,
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
706 PyUnicode_FromString(hashfunc->name));
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
707 PyStructSequence_SET_ITEM(hash_info, field++,
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
708 PyLong_FromLong(hashfunc->hash_bits));
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
709 PyStructSequence_SET_ITEM(hash_info, field++,
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
710 PyLong_FromLong(hashfunc->seed_bits));
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
711 PyStructSequence_SET_ITEM(hash_info, field++,
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
712 PyLong_FromLong(Py_HASH_CUTOFF));
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
713 if (PyErr_Occurred()) {
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
714 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
715 return NULL;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
716 }
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
717 return hash_info;
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
718 }
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
719
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
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(setrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
722 "setrecursionlimit(n)\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 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
725 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
726 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
727 dependent."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
728 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
729
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
730 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
731 sys_getrecursionlimit(PyObject *self)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
732 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
733 return PyLong_FromLong(Py_GetRecursionLimit());
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
734 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
735
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
736 PyDoc_STRVAR(getrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
737 "getrecursionlimit()\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
738 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
739 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
740 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
741 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
742 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
743
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
744 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
745 PyDoc_STRVAR(getwindowsversion_doc,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
746 "getwindowsversion()\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
747 \n\
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 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
756 );
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
757
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
758 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
759
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
760 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
761 {"major", "Major version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
762 {"minor", "Minor version number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
763 {"build", "Build number"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
764 {"platform", "Operating system platform"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
765 {"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
766 {"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
767 {"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
768 {"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
769 {"product_type", "System product type"},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
770 {0}
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
771 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
772
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
773 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
774 "sys.getwindowsversion", /* name */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
775 getwindowsversion_doc, /* doc */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
776 windows_version_fields, /* fields */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
777 5 /* For backward compatibility,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
778 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
779 via indexing, the rest are name only */
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
780 };
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
781
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
782 static PyObject *
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
783 sys_getwindowsversion(PyObject *self)
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
784 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
785 PyObject *version;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
786 int pos = 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
787 OSVERSIONINFOEX ver;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
788 ver.dwOSVersionInfoSize = sizeof(ver);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
789 if (!GetVersionEx((OSVERSIONINFO*) &ver))
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
790 return PyErr_SetFromWindowsErr(0);
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
791
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
792 version = PyStructSequence_New(&WindowsVersionType);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
793 if (version == NULL)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
794 return NULL;
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
795
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
796 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
797 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
798 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
799 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
800 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
801 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
802 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
803 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
804 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
805
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
806 return version;
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
807 }
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
808
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
809 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
810
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
811 #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
812 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
813 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
814 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
815 int new_val;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
816 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
817 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
818 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
819 if (!tstate)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
820 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
821 tstate->interp->dlopenflags = new_val;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
822 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
823 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
824 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
825
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
826 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
827 "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
828 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
829 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
830 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
831 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
832 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
833 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
834 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
835
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
836 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
837 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
838 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
839 PyThreadState *tstate = PyThreadState_GET();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
840 if (!tstate)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
841 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
842 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
843 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
844
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
845 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
846 "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
847 \n\
55611
4d38e51e7cdc Merged revisions 74062 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54326
diff changeset
848 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
849 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
850
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
851 #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
852
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
853 #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
854 /* 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
855 #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
856
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
857 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
858 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
859 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
860 int flag;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
861 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
862 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
863 mallopt(M_DEBUG, flag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
864 Py_INCREF(Py_None);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
865 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
866 }
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
867 #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
868
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
869 static PyObject *
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
870 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
871 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
872 PyObject *res = NULL;
74578
7d96679c5d46 use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents: 73243
diff changeset
873 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
874 static char *kwlist[] = {"object", "default", 0};
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
875 PyObject *o, *dflt = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
876 PyObject *method;
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
877
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
878 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
879 kwlist, &o, &dflt))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
880 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
881
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
882 /* 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
883 if (gc_head_size == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
884 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
885 if (gc_head_size == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
886 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
887 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
888
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
889 /* 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
890 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
891 return NULL;
53954
1b15a57e1f02 Merged revisions 72508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53185
diff changeset
892
74578
7d96679c5d46 use the static identifier api for looking up special methods
Benjamin Peterson <benjamin@python.org>
parents: 73243
diff changeset
893 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
894 if (method == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
895 if (!PyErr_Occurred())
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
896 PyErr_Format(PyExc_TypeError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
897 "Type %.100s doesn't define __sizeof__",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
898 Py_TYPE(o)->tp_name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
899 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
900 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
901 res = PyObject_CallFunctionObjArgs(method, NULL);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
902 Py_DECREF(method);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
903 }
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
904
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
905 /* Has a default value been given */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
906 if ((res == NULL) && (dflt != NULL) &&
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
907 PyErr_ExceptionMatches(PyExc_TypeError))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
908 {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
909 PyErr_Clear();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
910 Py_INCREF(dflt);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
911 return dflt;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
912 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
913 else if (res == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
914 return res;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
915
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
916 /* add gc_head size */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
917 if (PyObject_IS_GC(o)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
918 PyObject *tmp = res;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
919 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
920 Py_DECREF(tmp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
921 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
922 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
923 }
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
924
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
925 PyDoc_STRVAR(getsizeof_doc,
48467
c0c06ffaea83 Merged revisions 64842,64853,64856,64945 via svnmerge from
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47580
diff changeset
926 "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
927 \n\
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
928 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
929
58f4b60773fe Merged revisions 63856-63857,63859-63860 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47464
diff changeset
930 static PyObject *
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
931 sys_getrefcount(PyObject *self, PyObject *arg)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
932 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
933 return PyLong_FromSsize_t(arg->ob_refcnt);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
934 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
935
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
936 #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
937 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
938 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
939 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
940 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
941 }
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
942 #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
943
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
944 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
945 "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
946 \n\
23947
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
947 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
948 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
949 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
950 );
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
951
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
952 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
953 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
954 {
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
955 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
956 }
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
957
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
958 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
959 "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
960 \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
961 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
962 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
963 );
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
964
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
965 #ifdef COUNT_ALLOCS
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
966 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
967 sys_getcounts(PyObject *self)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
968 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
969 extern PyObject *get_counts(void);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
970
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
971 return get_counts();
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
972 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
973 #endif
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
974
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
975 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
976 "_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
977 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
978 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
979 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
980 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
981 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
982 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
983 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
984 purposes only."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
985 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
986
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
987 static PyObject *
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
988 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
989 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
990 PyFrameObject *f = PyThreadState_GET()->frame;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
991 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
992
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
993 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
994 return NULL;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
995
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
996 while (depth > 0 && f != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
997 f = f->f_back;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
998 --depth;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
999 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1000 if (f == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1001 PyErr_SetString(PyExc_ValueError,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1002 "call stack is not deep enough");
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1003 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1004 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1005 Py_INCREF(f);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1006 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
1007 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
1008
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1009 PyDoc_STRVAR(current_frames_doc,
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1010 "_current_frames() -> dictionary\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1011 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1012 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
1013 current stack frame.\n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1014 \n\
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1015 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
1016 );
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1017
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1018 static PyObject *
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1019 sys_current_frames(PyObject *self, PyObject *noargs)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1020 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1021 return _PyThread_CurrentFrames();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1022 }
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1023
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1024 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
1025 "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
1026 \n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1027 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
1028 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
1029 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
1030 );
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1031
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1032 static PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1033 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
1034 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1035 PyObject *func, *funcargs;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1036 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
1037 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1038 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
1039 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
1040
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1041 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
1042 "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
1043 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1044 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
1045 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
1046 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
1047 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
1048 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
1049 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
1050 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
1051 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
1052 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
1053 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
1054 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
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
1063
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
1064 #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
1065 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
1066 #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
1067
77577
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1068 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
1069 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
1070 {
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1071 #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
1072 _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
1073 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
1074 #endif
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1075 _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
1076
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1077 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
1078 }
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1079 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
1080 "_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
1081 \n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1082 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
1083 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
1084 \n\
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1085 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
1086 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
1087 ");
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 77339
diff changeset
1088
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
1089 #ifdef Py_TRACE_REFS
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
1090 /* 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
1091 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1092 #endif
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
1093
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1094 #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
1095 /* 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
1096 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
1097 #endif
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1098
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
1099 #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
1100 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1101 #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
1102
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
1103 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
1104 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
1105 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1106 PyType_ClearCache();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1107 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
1108 }
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
1109
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
1110 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
1111 "_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
1112 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
1113
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
1114
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1115 static PyMethodDef sys_methods[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1116 /* 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
1117 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1118 callstats_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1119 {"_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
1120 sys_clear_type_cache__doc__},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1121 {"_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
1122 current_frames_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1123 {"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
1124 {"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
1125 {"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
1126 {"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
1127 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1128 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
1129 #ifdef HAVE_DLOPEN
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1130 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1131 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
1132 #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
1133 {"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
1134 getallocatedblocks_doc},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1135 #ifdef COUNT_ALLOCS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1136 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1137 #endif
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
1138 #ifdef DYNAMIC_EXECUTION_PROFILE
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1139 {"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
1140 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1141 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1142 METH_NOARGS, getfilesystemencoding_doc},
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
1143 #ifdef Py_TRACE_REFS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1144 {"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
1145 #endif
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
1146 #ifdef Py_REF_DEBUG
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1147 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
1148 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1149 {"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
1150 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1151 getrecursionlimit_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1152 {"getsizeof", (PyCFunction)sys_getsizeof,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1153 METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1154 {"_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
1155 #ifdef MS_WINDOWS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1156 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1157 getwindowsversion_doc},
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
1158 #endif /* MS_WINDOWS */
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1159 {"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
1160 #ifdef USE_MALLOPT
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1161 {"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
1162 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1163 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1164 setcheckinterval_doc},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1165 {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1166 getcheckinterval_doc},
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
1167 #ifdef WITH_THREAD
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1168 {"setswitchinterval", sys_setswitchinterval, METH_VARARGS,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1169 setswitchinterval_doc},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1170 {"getswitchinterval", sys_getswitchinterval, METH_NOARGS,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1171 getswitchinterval_doc},
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 55611
diff changeset
1172 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
1173 #ifdef HAVE_DLOPEN
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1174 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1175 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
1176 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1177 {"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
1178 {"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
1179 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1180 setrecursionlimit_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
1181 #ifdef WITH_TSC
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1182 {"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
1183 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1184 {"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
1185 {"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
1186 {"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
1187 {"_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
1188 debugmallocstats_doc},
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1189 {NULL, NULL} /* sentinel */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1190 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1191
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1192 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1193 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
1194 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1195 PyObject *list = PyList_New(0);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1196 int i;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1197 if (list == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1198 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1199 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
1200 PyObject *name = PyUnicode_FromString(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1201 PyImport_Inittab[i].name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1202 if (name == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1203 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1204 PyList_Append(list, name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1205 Py_DECREF(name);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1206 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1207 if (PyList_Sort(list) != 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1208 Py_DECREF(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1209 list = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1210 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1211 if (list) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1212 PyObject *v = PyList_AsTuple(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1213 Py_DECREF(list);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1214 list = v;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1215 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1216 return list;
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1217 }
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
1218
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1219 static PyObject *warnoptions = NULL;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1220
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1221 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1222 PySys_ResetWarnOptions(void)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1223 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1224 if (warnoptions == NULL || !PyList_Check(warnoptions))
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1225 return;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1226 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
1227 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1228
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1229 void
61751
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1230 PySys_AddWarnOptionUnicode(PyObject *unicode)
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1231 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1232 if (warnoptions == NULL || !PyList_Check(warnoptions)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1233 Py_XDECREF(warnoptions);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1234 warnoptions = PyList_New(0);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1235 if (warnoptions == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1236 return;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1237 }
61751
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1238 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
1239 }
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1240
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1241 void
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1242 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
1243 {
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1244 PyObject *unicode;
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1245 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
1246 if (unicode == NULL)
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1247 return;
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1248 PySys_AddWarnOptionUnicode(unicode);
b7f71f60437b Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
1249 Py_DECREF(unicode);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1250 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1251
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
1252 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
1253 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
1254 {
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
1255 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
1256 }
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
1257
65575
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1258 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
1259
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1260 static PyObject *
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1261 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
1262 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1263 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
1264 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
1265 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
1266 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1267 return xoptions;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1268 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1269
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1270 void
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1271 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
1272 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1273 PyObject *opts;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1274 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
1275 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
1276
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1277 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
1278 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
1279 goto error;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1280
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1281 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
1282 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
1283 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
1284 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
1285 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
1286 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1287 else {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1288 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
1289 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
1290 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1291 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
1292 goto error;
68102
e2f96bd29252 Issue #8914: fix various warnings from the Clang static analyzer v254.
Brett Cannon <bcannon@gmail.com>
parents: 67380
diff changeset
1293 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
1294 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
1295 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
1296 return;
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1297
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1298 error:
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1299 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
1300 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
1301 /* 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
1302 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
1303 PyErr_Clear();
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1304 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1305
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1306 PyObject *
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1307 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
1308 {
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1309 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
1310 }
0b5bfba7a907 Issue #10089: Add support for arbitrary -X options on the command-line.
Antoine Pitrou <solipsis@pitrou.net>
parents: 65494
diff changeset
1311
8840
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
1312 /* 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
1313 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
1314 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
1315 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
1316 PyDoc_VAR(sys_doc) =
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1317 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
1318 "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
1319 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
1320 \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
1321 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
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 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
1324 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
1325 modules -- dictionary of loaded modules\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1326 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1327 displayhook -- called to show results in an interactive session\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1328 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
1329 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
1330 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
1331 \n\
48470
3d868254ff7e correct docstring
Benjamin Peterson <benjamin@python.org>
parents: 48467
diff changeset
1332 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
1333 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
1334 stderr -- standard error object; used for error messages\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1335 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
1336 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
1337 \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
1338 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
1339 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
1340 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
1341 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
1342 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
1343 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1344 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1345 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1346 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
1347 "\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
1348 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
1349 \n\
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1350 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
1351 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
1352 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
1353 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
1354 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
1355 float_repr_style -- string indicating the style of repr() output for floats\n\
87288
adb471b9cba1 ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Christian Heimes <christian@cheimes.de>
parents: 87116
diff changeset
1356 hash_info -- a struct sequence with information about the hash algorithm.\n\
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1357 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
1358 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
1359 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
1360 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
1361 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
1362 platform -- platform identifier\n\
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1363 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
1364 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
1365 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
1366 version_info -- version information as a named tuple\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1367 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1368 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1369 #ifdef MS_WINDOWS
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1370 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1371 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1372 "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
1373 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
1374 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1375 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1376 #endif /* MS_WINDOWS */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1377 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1378 "__stdin__ -- the original stdin; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1379 __stdout__ -- the original stdout; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1380 __stderr__ -- the original stderr; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1381 __displayhook__ -- the original displayhook; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1382 __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
1383 \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
1384 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
1385 \n\
44098
0889daf6d0d9 #1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents: 44086
diff changeset
1386 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
1387 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
1388 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
1389 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
1390 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
1391 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
1392 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
1393 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
1394 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
1395 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
1396 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
1397 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
1398 setprofile() -- set the global profiling function\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
1399 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
1400 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
1401 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
1402 )
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
1403 /* 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
1404
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1405
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1406 PyDoc_STRVAR(flags__doc__,
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1407 "sys.flags\n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1408 \n\
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1409 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
1410
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1411 static PyTypeObject FlagsType;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1412
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1413 static PyStructSequence_Field flags_fields[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1414 {"debug", "-d"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1415 {"inspect", "-i"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1416 {"interactive", "-i"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1417 {"optimize", "-O or -OO"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1418 {"dont_write_bytecode", "-B"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1419 {"no_user_site", "-s"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1420 {"no_site", "-S"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1421 {"ignore_environment", "-E"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1422 {"verbose", "-v"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1423 /* {"unbuffered", "-u"}, */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1424 /* {"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
1425 {"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
1426 {"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
1427 {"hash_randomization", "-R"},
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
1428 {"isolated", "-I"},
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1429 {0}
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1430 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1431
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1432 static PyStructSequence_Desc flags_desc = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1433 "sys.flags", /* name */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1434 flags__doc__, /* doc */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1435 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
1436 13
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1437 };
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1438
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1439 static PyObject*
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1440 make_flags(void)
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1441 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1442 int pos = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1443 PyObject *seq;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1444
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1445 seq = PyStructSequence_New(&FlagsType);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1446 if (seq == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1447 return NULL;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1448
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1449 #define SetFlag(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1450 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
1451
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1452 SetFlag(Py_DebugFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1453 SetFlag(Py_InspectFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1454 SetFlag(Py_InteractiveFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1455 SetFlag(Py_OptimizeFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1456 SetFlag(Py_DontWriteBytecodeFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1457 SetFlag(Py_NoUserSiteDirectory);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1458 SetFlag(Py_NoSiteFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1459 SetFlag(Py_IgnoreEnvironmentFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1460 SetFlag(Py_VerboseFlag);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1461 /* SetFlag(saw_unbuffered_flag); */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1462 /* 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
1463 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
1464 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
1465 SetFlag(Py_HashRandomizationFlag);
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
1466 SetFlag(Py_IsolatedFlag);
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1467 #undef SetFlag
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1468
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1469 if (PyErr_Occurred()) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1470 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1471 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1472 return seq;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1473 }
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1474
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1475 PyDoc_STRVAR(version_info__doc__,
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1476 "sys.version_info\n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1477 \n\
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1478 Version information as a named tuple.");
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1479
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1480 static PyTypeObject VersionInfoType;
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 PyStructSequence_Field version_info_fields[] = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1483 {"major", "Major release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1484 {"minor", "Minor release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1485 {"micro", "Patch release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1486 {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1487 {"serial", "Serial release number"},
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1488 {0}
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1489 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1490
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1491 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
1492 "sys.version_info", /* name */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1493 version_info__doc__, /* doc */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1494 version_info_fields, /* fields */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1495 5
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1496 };
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1497
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1498 static PyObject *
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1499 make_version_info(void)
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1500 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1501 PyObject *version_info;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1502 char *s;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1503 int pos = 0;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1504
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1505 version_info = PyStructSequence_New(&VersionInfoType);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1506 if (version_info == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1507 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1508 }
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1509
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1510 /*
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1511 * 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
1512 * 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
1513 */
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1514 #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
1515 s = "alpha";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1516 #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
1517 s = "beta";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1518 #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
1519 s = "candidate";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1520 #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
1521 s = "final";
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1522 #endif
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1523
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1524 #define SetIntItem(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1525 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
1526 #define SetStrItem(flag) \
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1527 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
1528
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1529 SetIntItem(PY_MAJOR_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1530 SetIntItem(PY_MINOR_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1531 SetIntItem(PY_MICRO_VERSION);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1532 SetStrItem(s);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1533 SetIntItem(PY_RELEASE_SERIAL);
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1534 #undef SetIntItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1535 #undef SetStrItem
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1536
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1537 if (PyErr_Occurred()) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1538 Py_CLEAR(version_info);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1539 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1540 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1541 return version_info;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1542 }
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1543
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1544 /* sys.implementation values */
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1545 #define NAME "cpython"
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1546 const char *_PySys_ImplName = NAME;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1547 #define QUOTE(arg) #arg
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1548 #define STRIFY(name) QUOTE(name)
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1549 #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
1550 #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
1551 #define TAG NAME "-" MAJOR MINOR;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1552 const char *_PySys_ImplCacheTag = TAG;
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1553 #undef NAME
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1554 #undef QUOTE
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1555 #undef STRIFY
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1556 #undef MAJOR
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1557 #undef MINOR
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1558 #undef TAG
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1559
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1560 static PyObject *
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1561 make_impl_info(PyObject *version_info)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1562 {
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1563 int res;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1564 PyObject *impl_info, *value, *ns;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1565
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1566 impl_info = PyDict_New();
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1567 if (impl_info == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1568 return NULL;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1569
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1570 /* populate the dict */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1571
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1572 value = PyUnicode_FromString(_PySys_ImplName);
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1573 if (value == NULL)
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 res = PyDict_SetItemString(impl_info, "name", value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1576 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1577 if (res < 0)
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
78029
ee01fd98b5b0 Issue #15242: Have PyImport_GetMagicTag() return a const char *
Brett Cannon <brett@python.org>
parents: 77577
diff changeset
1580 value = PyUnicode_FromString(_PySys_ImplCacheTag);
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1581 if (value == NULL)
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 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
1584 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1585 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1586 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1587
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1588 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
1589 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1590 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1591
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1592 value = PyLong_FromLong(PY_VERSION_HEX);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1593 if (value == NULL)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1594 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1595 res = PyDict_SetItemString(impl_info, "hexversion", value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1596 Py_DECREF(value);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1597 if (res < 0)
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1598 goto error;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1599
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1600 /* dict ready */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1601
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1602 ns = _PyNamespace_New(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1603 Py_DECREF(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1604 return ns;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1605
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1606 error:
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1607 Py_CLEAR(impl_info);
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1608 return NULL;
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1609 }
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1610
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1611 static struct PyModuleDef sysmodule = {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1612 PyModuleDef_HEAD_INIT,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1613 "sys",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1614 sys_doc,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1615 -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
1616 sys_methods,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1617 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1618 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1619 NULL,
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1620 NULL
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1621 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47489
diff changeset
1622
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1623 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1624 _PySys_Init(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1625 {
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1626 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
1627
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1628 m = PyModule_Create(&sysmodule);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1629 if (m == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1630 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1631 sysdict = PyModule_GetDict(m);
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1632 #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
1633 do { \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1634 int res; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1635 PyObject *v = (value); \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1636 if (v == NULL) \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1637 return NULL; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1638 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
1639 if (res < 0) { \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1640 return NULL; \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1641 } \
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1642 } while (0)
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1643 #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
1644 do { \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1645 int res; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1646 PyObject *v = (value); \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1647 if (v == NULL) \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1648 return NULL; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1649 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
1650 Py_DECREF(v); \
84795
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1651 if (res < 0) { \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1652 return NULL; \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1653 } \
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1654 } while (0)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1655
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1656 /* 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
1657 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
1658 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
1659 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
1660 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
1661 #if !defined(MS_WINDOWS)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1662 {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1663 struct stat sb;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1664 if (fstat(fileno(stdin), &sb) == 0 &&
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1665 S_ISDIR(sb.st_mode)) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1666 /* 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
1667 /* 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
1668 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
1669 exit(EXIT_FAILURE);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1670 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1671 }
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1672 #endif
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1673
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1674 /* 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
1675
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1676 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
1677 PyDict_GetItemString(sysdict, "displayhook"));
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1678 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
1679 PyDict_GetItemString(sysdict, "excepthook"));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1680 SET_SYS_FROM_STRING("version",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1681 PyUnicode_FromString(Py_GetVersion()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1682 SET_SYS_FROM_STRING("hexversion",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1683 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
1684 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
1685 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
1686 _Py_hgversion()));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1687 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
1688 PyBool_FromLong(Py_DontWriteBytecodeFlag));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1689 SET_SYS_FROM_STRING("api_version",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1690 PyLong_FromLong(PYTHON_API_VERSION));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1691 SET_SYS_FROM_STRING("copyright",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1692 PyUnicode_FromString(Py_GetCopyright()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1693 SET_SYS_FROM_STRING("platform",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1694 PyUnicode_FromString(Py_GetPlatform()));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1695 SET_SYS_FROM_STRING("executable",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1696 PyUnicode_FromWideChar(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1697 Py_GetProgramFullPath(), -1));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1698 SET_SYS_FROM_STRING("prefix",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1699 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1700 SET_SYS_FROM_STRING("exec_prefix",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1701 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
77154
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1702 SET_SYS_FROM_STRING("base_prefix",
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1703 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
294f8aeb4d4b Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 75097
diff changeset
1704 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
1705 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1706 SET_SYS_FROM_STRING("maxsize",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1707 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
1708 SET_SYS_FROM_STRING("float_info",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1709 PyFloat_GetInfo());
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1710 SET_SYS_FROM_STRING("int_info",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1711 PyLong_GetInfo());
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
1712 /* 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
1713 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
1714 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
1715 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1716 }
61873
0bc8ffe6ba9a Issue #8188: Introduce a new scheme for computing hashes of numbers
Mark Dickinson <dickinsm@gmail.com>
parents: 61790
diff changeset
1717 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
1718 get_hash_info());
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1719 SET_SYS_FROM_STRING("maxunicode",
72503
606652491366 #13054: sys.maxunicode is now always 0x10FFFF.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69710
diff changeset
1720 PyLong_FromLong(0x10FFFF));
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1721 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
1722 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
1723 #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
1724 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
1725 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
1726 #else
d2127cdec10e Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1727 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
1728 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
1729 #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
1730
4126
c80c515999b9 Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents: 3877
diff changeset
1731 #ifdef MS_COREDLL
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1732 SET_SYS_FROM_STRING("dllhandle",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1733 PyLong_FromVoidPtr(PyWin_DLLhModule));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1734 SET_SYS_FROM_STRING("winver",
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1735 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
1736 #endif
65389
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1737 #ifdef ABIFLAGS
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1738 SET_SYS_FROM_STRING("abiflags",
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1739 PyUnicode_FromString(ABIFLAGS));
932f97bfbdc0 First (uncontroversial) part of issue 9807.
Barry Warsaw <barry@python.org>
parents: 65166
diff changeset
1740 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1741 if (warnoptions == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1742 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
1743 if (warnoptions == NULL)
31796b188bec Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
Victor Stinner <victor.stinner@gmail.com>
parents: 84793
diff changeset
1744 return NULL;
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1745 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1746 else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1747 Py_INCREF(warnoptions);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1748 }
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1749 SET_SYS_FROM_STRING_BORROW("warnoptions", warnoptions);
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1750
86693
5eb00460e6e8 Issue #18520: fix reference leak in _PySys_Init()
Victor Stinner <victor.stinner@gmail.com>
parents: 85413
diff changeset
1751 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
1752
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1753 /* version_info */
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1754 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
1755 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
1756 &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
1757 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1758 }
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1759 version_info = make_version_info();
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1760 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
1761 /* prevent user from creating new instances */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1762 VersionInfoType.tp_init = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1763 VersionInfoType.tp_new = NULL;
51378
4cc49d978ec2 Merged revisions 69331 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 50743
diff changeset
1764
77339
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1765 /* implementation */
9c445f4695c1 Eric Snow's implementation of PEP 421.
Barry Warsaw <barry@python.org>
parents: 77154
diff changeset
1766 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
1767
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1768 /* flags */
84793
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1769 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
1770 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
1771 return NULL;
fc718c177ee6 Issue #18520: Add a new PyStructSequence_InitType2() function, same than
Victor Stinner <victor.stinner@gmail.com>
parents: 84786
diff changeset
1772 }
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1773 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
1774 /* prevent user from creating new instances */
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1775 FlagsType.tp_init = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1776 FlagsType.tp_new = NULL;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44587
diff changeset
1777
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1778
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1779 #if defined(MS_WINDOWS)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1780 /* getwindowsversion */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1781 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
1782 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
1783 &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
1784 return NULL;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1785 /* prevent user from creating new instances */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1786 WindowsVersionType.tp_init = NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60889
diff changeset
1787 WindowsVersionType.tp_new = NULL;
58507
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1788 #endif
7379cf70fd60 Merged revisions 77763 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 57181
diff changeset
1789
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1790 /* 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
1791 #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
1792 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
1793 PyUnicode_FromString("short"));
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1794 #else
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1795 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
1796 PyUnicode_FromString("legacy"));
53185
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1797 #endif
97ae7a709c1d Issue #1580: use short float repr where possible.
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
1798
69710
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1799 #ifdef WITH_THREAD
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1800 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
1801 #endif
2b21fcf3d9a9 Issue #11223: Replace threading._info() by sys.thread_info
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69483
diff changeset
1802
45071
f380d991390e Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45026
diff changeset
1803 #undef SET_SYS_FROM_STRING
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1804 if (PyErr_Occurred())
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1805 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1806 return m;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1807 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1808
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1809 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
1810 makepathobject(const wchar_t *path, wchar_t delim)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1811 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1812 int i, n;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1813 const wchar_t *p;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1814 PyObject *v, *w;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1815
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1816 n = 1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1817 p = path;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1818 while ((p = wcschr(p, delim)) != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1819 n++;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1820 p++;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1821 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1822 v = PyList_New(n);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1823 if (v == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1824 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1825 for (i = 0; ; i++) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1826 p = wcschr(path, delim);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1827 if (p == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1828 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
1829 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
1830 if (w == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1831 Py_DECREF(v);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1832 return NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1833 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1834 PyList_SetItem(v, i, w);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1835 if (*p == '\0')
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1836 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1837 path = p+1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1838 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1839 return v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1840 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1841
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1842 void
46318
22a74eaf6b22 Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45145
diff changeset
1843 PySys_SetPath(const wchar_t *path)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1844 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1845 PyObject *v;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1846 if ((v = makepathobject(path, DELIM)) == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1847 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
1848 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
1849 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
1850 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
1851 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1852
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1853 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
1854 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
1855 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1856 PyObject *av;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1857 if (argc <= 0 || argv == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1858 /* 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
1859 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
1860 argv = empty_argv;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1861 argc = 1;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1862 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1863 av = PyList_New(argc);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1864 if (av != NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1865 int i;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1866 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
1867 #ifdef __VMS
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1868 PyObject *v;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1869
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1870 /* 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
1871 if (i == 0) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1872 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
1873 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
1874 v = PyUnicode_FromString(argv[0]);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1875 else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1876 v = PyUnicode_FromString(
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1877 decc$translate_vms(argv[0]));
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1878 } else
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1879 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
1880 #else
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1881 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
1882 #endif
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1883 if (v == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1884 Py_DECREF(av);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1885 av = NULL;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1886 break;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1887 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1888 PyList_SetItem(av, i, v);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1889 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1890 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1891 return av;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1892 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1893
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
1894 #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
1895 (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
1896 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
1897
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1898 static void
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1899 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
1900 {
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1901 wchar_t *argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1902 wchar_t *p = NULL;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1903 Py_ssize_t n = 0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1904 PyObject *a;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1905 PyObject *path;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1906 #ifdef HAVE_READLINK
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1907 wchar_t link[MAXPATHLEN+1];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1908 wchar_t argv0copy[2*MAXPATHLEN+1];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1909 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
1910 #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
1911 #if defined(HAVE_REALPATH)
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
1912 wchar_t fullpath[MAXPATHLEN];
50743
e8154bd322cb Merged revisions 68540 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 49613
diff changeset
1913 #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
1914 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
1915 #endif
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1916
86999
01c4a0af73cf Issue #19512, #19515: remove shared identifiers, move identifiers where they
Victor Stinner <victor.stinner@gmail.com>
parents: 86974
diff changeset
1917 path = _PySys_GetObjectId(&PyId_path);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1918 if (path == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1919 return;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1920
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1921 argv0 = argv[0];
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1922
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1923 #ifdef HAVE_READLINK
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1924 if (_HAVE_SCRIPT_ARGUMENT(argc, argv))
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1925 nr = _Py_wreadlink(argv0, link, MAXPATHLEN);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1926 if (nr > 0) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1927 /* It's a symlink */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1928 link[nr] = '\0';
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1929 if (link[0] == SEP)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1930 argv0 = link; /* Link to absolute path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1931 else if (wcschr(link, SEP) == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1932 ; /* Link without path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1933 else {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1934 /* Must join(dirname(argv0), link) */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1935 wchar_t *q = wcsrchr(argv0, SEP);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1936 if (q == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1937 argv0 = link; /* argv0 without path */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1938 else {
84785
dca92e8a011a Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents: 78029
diff changeset
1939 /* 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
1940 wcsncpy(argv0copy, argv0, MAXPATHLEN);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1941 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
1942 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
1943 q[MAXPATHLEN + 1] = L'\0';
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1944 argv0 = argv0copy;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1945 }
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 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1948 #endif /* HAVE_READLINK */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1949 #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
1950 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1951 wchar_t *q;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1952 #if defined(MS_WINDOWS) && !defined(MS_WINCE)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1953 /* 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
1954 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
1955 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
1956 wchar_t *ptemp;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1957 if (GetFullPathNameW(argv0,
72510
b534b56379cb Use the new Py_ARRAY_LENGTH macro
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72503
diff changeset
1958 Py_ARRAY_LENGTH(fullpath),
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1959 fullpath,
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1960 &ptemp)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1961 argv0 = fullpath;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1962 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1963 #endif
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1964 p = wcsrchr(argv0, SEP);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1965 /* Test for alternate separator */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1966 q = wcsrchr(p ? p : argv0, '/');
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1967 if (q != NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1968 p = q;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1969 if (p != NULL) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1970 n = p + 1 - argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1971 if (n > 1 && p[-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 }
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 #else /* All other filename syntaxes */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1976 if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1977 #if defined(HAVE_REALPATH)
87115
780a0199c7f1 sysmodule.c: fix sys_update_path(), use Py_ARRAY_LENGTH() to get the size of
Victor Stinner <victor.stinner@gmail.com>
parents: 85412
diff changeset
1978 if (_Py_wrealpath(argv0, fullpath, Py_ARRAY_LENGTH(fullpath))) {
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1979 argv0 = fullpath;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1980 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1981 #endif
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1982 p = wcsrchr(argv0, SEP);
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 if (p != NULL) {
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1985 n = p + 1 - argv0;
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1986 #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
1987 if (n > 1)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1988 n--; /* Drop trailing separator */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1989 #endif /* Unix */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1990 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1991 #endif /* All others */
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1992 a = PyUnicode_FromWideChar(argv0, n);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1993 if (a == NULL)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1994 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
1995 if (PyList_Insert(path, 0, a) < 0)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1996 Py_FatalError("sys.path.insert(0) failed");
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1997 Py_DECREF(a);
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1998 }
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
1999
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
2000 void
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
2001 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
2002 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2003 PyObject *av = makeargvobject(argc, argv);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2004 if (av == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2005 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
2006 if (PySys_SetObject("argv", av) != 0)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2007 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
2008 Py_DECREF(av);
65154
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
2009 if (updatepath)
62c58dc912e8 Create a subfunction for PySys_SetArgvEx()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64622
diff changeset
2010 sys_update_path(argc, argv);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2011 }
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
2012
61791
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2013 void
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2014 PySys_SetArgv(int argc, wchar_t **argv)
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2015 {
85081
dd0d751cc7f1 Issue #16400: Add command line option for isolated mode.
Christian Heimes <christian@cheimes.de>
parents: 84795
diff changeset
2016 PySys_SetArgvEx(argc, argv, Py_IsolatedFlag == 0);
61791
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2017 }
9db8c414921f Merged revisions 81400 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61467
diff changeset
2018
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2019 /* Reimplementation of PyFile_WriteString() no calling indirectly
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2020 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
2021
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2022 static int
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2023 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
2024 {
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2025 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
2026 int err;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2027
62190
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2028 if (file == NULL)
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2029 return -1;
7ccc55811413 Merged revisions 81841 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61791
diff changeset
2030
72848
81380082d216 Use identifier API for PyObject_GetAttrString.
Martin v. Löwis <martin@v.loewis.de>
parents: 72835
diff changeset
2031 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
2032 if (writer == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2033 goto error;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2034
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2035 args = PyTuple_Pack(1, unicode);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2036 if (args == NULL)
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2037 goto error;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2038
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2039 result = PyEval_CallObject(writer, args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2040 if (result == NULL) {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2041 goto error;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2042 } else {
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2043 err = 0;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2044 goto finally;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2045 }
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2046
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2047 error:
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2048 err = -1;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2049 finally:
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2050 Py_XDECREF(writer);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2051 Py_XDECREF(args);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2052 Py_XDECREF(result);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2053 return err;
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2054 }
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2055
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2056 static int
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2057 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
2058 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2059 PyObject *unicode = NULL;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2060 int err;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2061
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2062 if (file == NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2063 return -1;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2065 unicode = PyUnicode_FromString(text);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2066 if (unicode == NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2067 return -1;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2068
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2069 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
2070 Py_DECREF(unicode);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2071 return err;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2072 }
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
2073
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 /* 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
2075 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
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 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
2078 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
2079
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 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
2081 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
2082 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
2083
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2084 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
2085 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
2086 ignores all exceptions.
60890
c6b4f4f2b9a8 Merged revisions 80404 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59302
diff changeset
2087
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 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
2089 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
2090
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
2091 *** 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
2092
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 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
2094 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
2095 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
2096 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
2097 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
2098 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
2099
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
2100 */
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
2101
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
2102 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
2103 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
2104 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2105 PyObject *file;
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2106 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
2107 char buffer[1001];
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2108 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
2109
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2110 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
2111 file = _PySys_GetObjectId(key);
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2112 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
2113 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
2114 PyErr_Clear();
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2115 fputs(buffer, fp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2116 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2117 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
2118 const char *truncated = "... truncated";
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2119 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
2120 fputs(truncated, fp);
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2121 }
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2122 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
2123 }
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
2124
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
2125 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
2126 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
2127 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2128 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
2129
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2130 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
2131 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
2132 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
2133 }
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
2134
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
2135 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
2136 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
2137 {
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2138 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
2139
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 60890
diff changeset
2140 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
2141 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
2142 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
2143 }
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2144
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2145 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
2146 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
2147 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2148 PyObject *file, *message;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2149 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
2150 char *utf8;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2151
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2152 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
2153 file = _PySys_GetObjectId(key);
64064
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2154 message = PyUnicode_FromFormatV(format, va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2155 if (message != NULL) {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2156 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
2157 PyErr_Clear();
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2158 utf8 = _PyUnicode_AsString(message);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2159 if (utf8 != NULL)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2160 fputs(utf8, fp);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2161 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2162 Py_DECREF(message);
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 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
2165 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2166
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2167 void
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2168 PySys_FormatStdout(const char *format, ...)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2169 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2170 va_list va;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2171
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2172 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
2173 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
2174 va_end(va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2175 }
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2176
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2177 void
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2178 PySys_FormatStderr(const char *format, ...)
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2179 {
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2180 va_list va;
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2181
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2182 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
2183 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
2184 va_end(va);
5d9bdf5aa07b Issue #9599: Create PySys_FormatStdout() and PySys_FormatStderr()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 62828
diff changeset
2185 }