annotate Python/modsupport.c @ 37756:7b2e436a4a21 legacy-trunk

Use Py_VISIT in all tp_traverse methods, instead of traversing manually or using a custom, nearly-identical macro. This probably changes how some of these functions are compiled, which may result in fractionally slower (or faster) execution. Considering the nature of traversal, visiting much of the address space in unpredictable patterns, I'd argue the code readability and maintainability is well worth it ;P
author Thomas Wouters <thomas@python.org>
date Sat, 15 Apr 2006 21:47:09 +0000
parents 9b22d8b7bcaa
children 2e3276dc231f
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 /* Module support implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
4 #include "Python.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
6 #define FLAG_SIZE_T 1
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
7 typedef double va_double;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
8
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
9 static PyObject *va_build_value(const char *, va_list, int);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
10 #ifdef HAVE_DECLSPEC_DLL
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
11 PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
12 #endif
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
13
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
14 /* Package context -- the full module name for package imports */
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
15 char *_Py_PackageContext = NULL;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
16
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
17 /* Py_InitModule4() parameters:
2095
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
18 - name is the module name
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
19 - methods is the list of top-level functions
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
20 - doc is the documentation string
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
21 - passthrough is passed as self to functions defined in the module
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
22 - api_version is the value of PYTHON_API_VERSION at the time the
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
23 module was compiled
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
24
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
25 Return value is a borrowed reference to the module object; or NULL
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
26 if an error occurred (in Python 1.4 and before, errors were fatal).
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
27 Errors may still leak memory.
2090
f78b387b54e0 New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
28 */
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
29
2095
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
30 static char api_version_warning[] =
18908
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
31 "Python C API version mismatch for module %.100s:\
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
32 This Python has API version %d, module %.100s has version %d.";
2095
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
33
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
34 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
35 Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
36 PyObject *passthrough, int module_api_version)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 {
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
38 PyObject *m, *d, *v, *n;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
39 PyMethodDef *ml;
13859
94f6ec87930a Add a test that Py_IsInitialized() in Py_InitModule4(). See
Guido van Rossum <guido@python.org>
parents: 13658
diff changeset
40 if (!Py_IsInitialized())
94f6ec87930a Add a test that Py_IsInitialized() in Py_InitModule4(). See
Guido van Rossum <guido@python.org>
parents: 13658
diff changeset
41 Py_FatalError("Interpreter not initialized (version mismatch?)");
18908
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
42 if (module_api_version != PYTHON_API_VERSION) {
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
43 char message[512];
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
44 PyOS_snprintf(message, sizeof(message),
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
45 api_version_warning, name,
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
46 PYTHON_API_VERSION, name,
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
47 module_api_version);
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
48 if (PyErr_Warn(PyExc_RuntimeWarning, message))
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
49 return NULL;
79c676f9b34a This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents: 17032
diff changeset
50 }
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
51 /* Make sure name is fully qualified.
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
52
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
53 This is a bit of a hack: when the shared library is loaded,
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
54 the module name is "package.module", but the module calls
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
55 Py_InitModule*() with just "module" for the name. The shared
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
56 library loader squirrels away the true name of the module in
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
57 _Py_PackageContext, and Py_InitModule*() will substitute this
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
58 (if the name actually matches).
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
59 */
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
60 if (_Py_PackageContext != NULL) {
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
61 char *p = strrchr(_Py_PackageContext, '.');
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
62 if (p != NULL && strcmp(name, p+1) == 0) {
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
63 name = _Py_PackageContext;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
64 _Py_PackageContext = NULL;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
65 }
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
66 }
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
67 if ((m = PyImport_AddModule(name)) == NULL)
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
68 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
69 d = PyModule_GetDict(m);
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
70 if (methods != NULL) {
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
71 n = PyString_FromString(name);
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
72 if (n == NULL)
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
73 return NULL;
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
74 for (ml = methods; ml->ml_name != NULL; ml++) {
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
75 if ((ml->ml_flags & METH_CLASS) ||
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
76 (ml->ml_flags & METH_STATIC)) {
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
77 PyErr_SetString(PyExc_ValueError,
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
78 "module functions cannot set"
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
79 " METH_CLASS or METH_STATIC");
36774
35612a131ac6 Fix more memory leaks. Will backport to 2.4.
Martin v. Löwis <martin@v.loewis.de>
parents: 36521
diff changeset
80 Py_DECREF(n);
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
81 return NULL;
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
82 }
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
83 v = PyCFunction_NewEx(ml, passthrough, n);
36774
35612a131ac6 Fix more memory leaks. Will backport to 2.4.
Martin v. Löwis <martin@v.loewis.de>
parents: 36521
diff changeset
84 if (v == NULL) {
35612a131ac6 Fix more memory leaks. Will backport to 2.4.
Martin v. Löwis <martin@v.loewis.de>
parents: 36521
diff changeset
85 Py_DECREF(n);
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
86 return NULL;
36774
35612a131ac6 Fix more memory leaks. Will backport to 2.4.
Martin v. Löwis <martin@v.loewis.de>
parents: 36521
diff changeset
87 }
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
88 if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
89 Py_DECREF(v);
36774
35612a131ac6 Fix more memory leaks. Will backport to 2.4.
Martin v. Löwis <martin@v.loewis.de>
parents: 36521
diff changeset
90 Py_DECREF(n);
24834
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
91 return NULL;
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
92 }
64f4dd770c67 Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents: 24400
diff changeset
93 Py_DECREF(v);
22613
ddc9543c76a0 Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents: 19343
diff changeset
94 }
35895
fe4c627b2096 Fix a few more memory leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 32656
diff changeset
95 Py_DECREF(n);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
2090
f78b387b54e0 New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
97 if (doc != NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
98 v = PyString_FromString(doc);
18991
360cece76123 Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
Fred Drake <fdrake@acm.org>
parents: 18908
diff changeset
99 if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
26664
fe2d422385b1 Fixed potential crash: v can be NULL here, so use Py_XDECREF rather than Py_DECREF
Just van Rossum <just@letterror.com>
parents: 24834
diff changeset
100 Py_XDECREF(v);
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
101 return NULL;
18991
360cece76123 Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
Fred Drake <fdrake@acm.org>
parents: 18908
diff changeset
102 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
103 Py_DECREF(v);
2090
f78b387b54e0 New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
104 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
105 return m;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
109 /* Helper for mkvalue() to scan the length of a format */
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
110
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
111 static int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
112 countformat(const char *format, int endchar)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
113 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
114 int count = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
115 int level = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
116 while (level > 0 || *format != endchar) {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
117 switch (*format) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
118 case '\0':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
119 /* Premature end */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
120 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
121 "unmatched paren in format");
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
122 return -1;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
123 case '(':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
124 case '[':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
125 case '{':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
126 if (level == 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
127 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
128 level++;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
129 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
130 case ')':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
131 case ']':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
132 case '}':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
133 level--;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
134 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
135 case '#':
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
136 case '&':
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
137 case ',':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
138 case ':':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
139 case ' ':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
140 case '\t':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
141 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
142 default:
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
143 if (level == 0)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
144 count++;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
145 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
146 format++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
147 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
148 return count;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
149 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
150
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
151
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
152 /* Generic function to create a value -- the inverse of getargs() */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
153 /* After an original idea and first implementation by Steven Miale */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
154
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
155 static PyObject *do_mktuple(const char**, va_list *, int, int, int);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
156 static PyObject *do_mklist(const char**, va_list *, int, int, int);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
157 static PyObject *do_mkdict(const char**, va_list *, int, int, int);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
158 static PyObject *do_mkvalue(const char**, va_list *, int);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
159
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
160
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
161 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
162 do_mkdict(const char **p_format, va_list *p_va, int endchar, int n, int flags)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
163 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
164 PyObject *d;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
165 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
166 int itemfailed = 0;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
167 if (n < 0)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
168 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
169 if ((d = PyDict_New()) == NULL)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
170 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
171 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
172 refcounts on any 'N' arguments. */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
173 for (i = 0; i < n; i+= 2) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
174 PyObject *k, *v;
6613
2e874a5a912f Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents: 6602
diff changeset
175 int err;
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
176 k = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
177 if (k == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
178 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
179 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
180 k = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
181 }
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
182 v = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
183 if (v == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
184 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
185 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
186 v = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
187 }
6613
2e874a5a912f Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents: 6602
diff changeset
188 err = PyDict_SetItem(d, k, v);
2e874a5a912f Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents: 6602
diff changeset
189 Py_DECREF(k);
2e874a5a912f Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents: 6602
diff changeset
190 Py_DECREF(v);
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
191 if (err < 0 || itemfailed) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
192 Py_DECREF(d);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
193 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
194 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
195 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
196 if (d != NULL && **p_format != endchar) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
197 Py_DECREF(d);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
198 d = NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
199 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
200 "Unmatched paren in format");
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
201 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
202 else if (endchar)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
203 ++*p_format;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
204 return d;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
205 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
206
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
207 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
208 do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
209 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
210 PyObject *v;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
211 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
212 int itemfailed = 0;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
213 if (n < 0)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
214 return NULL;
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
215 v = PyList_New(n);
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
216 if (v == NULL)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
217 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
218 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
219 refcounts on any 'N' arguments. */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
220 for (i = 0; i < n; i++) {
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
221 PyObject *w = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
222 if (w == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
223 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
224 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
225 w = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
226 }
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
227 PyList_SET_ITEM(v, i, w);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
228 }
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
229
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
230 if (itemfailed) {
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
231 /* do_mkvalue() should have already set an error */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
232 Py_DECREF(v);
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
233 return NULL;
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
234 }
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
235 if (**p_format != endchar) {
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
236 Py_DECREF(v);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
237 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
238 "Unmatched paren in format");
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
239 return NULL;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
240 }
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
241 if (endchar)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
242 ++*p_format;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
243 return v;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
244 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
245
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
246 #ifdef Py_USING_UNICODE
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
247 static int
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
248 _ustrlen(Py_UNICODE *u)
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
249 {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
250 int i = 0;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
251 Py_UNICODE *v = u;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
252 while (*v != 0) { i++; v++; }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
253 return i;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
254 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
255 #endif
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
256
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
257 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
258 do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
259 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
260 PyObject *v;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
261 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
262 int itemfailed = 0;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
263 if (n < 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
264 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
265 if ((v = PyTuple_New(n)) == NULL)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
266 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
267 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
268 refcounts on any 'N' arguments. */
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
269 for (i = 0; i < n; i++) {
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
270 PyObject *w = do_mkvalue(p_format, p_va, flags);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
271 if (w == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
272 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
273 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
274 w = Py_None;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
275 }
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
276 PyTuple_SET_ITEM(v, i, w);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
277 }
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
278 if (itemfailed) {
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
279 /* do_mkvalue() should have already set an error */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
280 Py_DECREF(v);
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
281 return NULL;
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
282 }
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
283 if (**p_format != endchar) {
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
284 Py_DECREF(v);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
285 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
286 "Unmatched paren in format");
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
287 return NULL;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
288 }
37025
03894a7a32ec Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36858
diff changeset
289 if (endchar)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
290 ++*p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
291 return v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
292 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
293
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
294 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
295 do_mkvalue(const char **p_format, va_list *p_va, int flags)
860
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
296 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
297 for (;;) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
298 switch (*(*p_format)++) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
299 case '(':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
300 return do_mktuple(p_format, p_va, ')',
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
301 countformat(*p_format, ')'), flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
302
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
303 case '[':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
304 return do_mklist(p_format, p_va, ']',
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
305 countformat(*p_format, ']'), flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
306
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
307 case '{':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
308 return do_mkdict(p_format, p_va, '}',
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
309 countformat(*p_format, '}'), flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
310
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
311 case 'b':
14588
dcbc084d046e Cast UCHAR_MAX to int before doing the comparison for overflow of the
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
312 case 'B':
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
313 case 'h':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
314 case 'i':
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
315 return PyInt_FromLong((long)va_arg(*p_va, int));
13378
113d833eea7e Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents: 13330
diff changeset
316
113d833eea7e Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents: 13330
diff changeset
317 case 'H':
113d833eea7e Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents: 13330
diff changeset
318 return PyInt_FromLong((long)va_arg(*p_va, unsigned int));
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
319
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
320 case 'I':
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
321 {
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
322 unsigned int n;
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
323 n = va_arg(*p_va, unsigned int);
36115
03dbec0d9504 do_mkvalue(), 'I' and 'k' cases: squash legitimate
Tim Peters <tim.peters@gmail.com>
parents: 35999
diff changeset
324 if (n > (unsigned long)PyInt_GetMax())
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
325 return PyLong_FromUnsignedLong((unsigned long)n);
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
326 else
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
327 return PyInt_FromLong(n);
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
328 }
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
329
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
330 case 'n':
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
331 #if SIZEOF_SIZE_T!=SIZEOF_LONG
36521
30aef3ce2b26 Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
332 return PyInt_FromSsize_t(va_arg(*p_va, Py_ssize_t));
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
333 #endif
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
334 /* Fall through from 'n' to 'l' if Py_ssize_t is long */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
335 case 'l':
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
336 return PyInt_FromLong(va_arg(*p_va, long));
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
337
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
338 case 'k':
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
339 {
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
340 unsigned long n;
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
341 n = va_arg(*p_va, unsigned long);
36115
03dbec0d9504 do_mkvalue(), 'I' and 'k' cases: squash legitimate
Tim Peters <tim.peters@gmail.com>
parents: 35999
diff changeset
342 if (n > (unsigned long)PyInt_GetMax())
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
343 return PyLong_FromUnsignedLong(n);
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
344 else
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
345 return PyInt_FromLong(n);
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
346 }
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
347
9949
98e37347378b Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents: 9722
diff changeset
348 #ifdef HAVE_LONG_LONG
8822
bd47ee068b83 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8640
diff changeset
349 case 'L':
28437
871da703e4c0 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents: 27559
diff changeset
350 return PyLong_FromLongLong((PY_LONG_LONG)va_arg(*p_va, PY_LONG_LONG));
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
351
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
352 case 'K':
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
353 return PyLong_FromUnsignedLongLong((PY_LONG_LONG)va_arg(*p_va, unsigned PY_LONG_LONG));
8822
bd47ee068b83 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8640
diff changeset
354 #endif
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
355 #ifdef Py_USING_UNICODE
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
356 case 'u':
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
357 {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
358 PyObject *v;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
359 Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
360 Py_ssize_t n;
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
361 if (**p_format == '#') {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
362 ++*p_format;
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
363 if (flags & FLAG_SIZE_T)
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
364 n = va_arg(*p_va, Py_ssize_t);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
365 else
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
366 n = va_arg(*p_va, int);
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
367 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
368 else
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
369 n = -1;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
370 if (u == NULL) {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
371 v = Py_None;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
372 Py_INCREF(v);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
373 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
374 else {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
375 if (n < 0)
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
376 n = _ustrlen(u);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
377 v = PyUnicode_FromUnicode(u, n);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
378 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
379 return v;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
380 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
381 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
382 case 'f':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
383 case 'd':
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
384 return PyFloat_FromDouble(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
385 (double)va_arg(*p_va, va_double));
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
386
17032
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
387 #ifndef WITHOUT_COMPLEX
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
388 case 'D':
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
389 return PyComplex_FromCComplex(
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
390 *((Py_complex *)va_arg(*p_va, Py_complex *)));
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
391 #endif /* WITHOUT_COMPLEX */
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
392
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
393 case 'c':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
394 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
395 char p[1];
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
396 p[0] = (char)va_arg(*p_va, int);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397 return PyString_FromStringAndSize(p, 1);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
398 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
399
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
400 case 's':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
401 case 'z':
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
402 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
403 PyObject *v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
404 char *str = va_arg(*p_va, char *);
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
405 Py_ssize_t n;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
406 if (**p_format == '#') {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
407 ++*p_format;
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
408 if (flags & FLAG_SIZE_T)
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
409 n = va_arg(*p_va, Py_ssize_t);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
410 else
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
411 n = va_arg(*p_va, int);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
412 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
413 else
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
414 n = -1;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
415 if (str == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
416 v = Py_None;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
417 Py_INCREF(v);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
418 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
419 else {
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
420 if (n < 0) {
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
421 size_t m = strlen(str);
37673
606818c33e50 Replace INT_MAX with PY_SSIZE_T_MAX.
Martin v. Löwis <martin@v.loewis.de>
parents: 37025
diff changeset
422 if (m > PY_SSIZE_T_MAX) {
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
423 PyErr_SetString(PyExc_OverflowError,
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
424 "string too long for Python string");
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
425 return NULL;
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
426 }
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
427 n = (int)m;
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
428 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
429 v = PyString_FromStringAndSize(str, n);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
430 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
431 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
432 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
433
9720
24ca64134594 Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents: 9044
diff changeset
434 case 'N':
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
435 case 'S':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
436 case 'O':
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
437 if (**p_format == '&') {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13378
diff changeset
438 typedef PyObject *(*converter)(void *);
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
439 converter func = va_arg(*p_va, converter);
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
440 void *arg = va_arg(*p_va, void *);
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
441 ++*p_format;
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
442 return (*func)(arg);
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
443 }
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
444 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
445 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
446 v = va_arg(*p_va, PyObject *);
9722
3955f787e9a1 Oops, forgot a pair of {}'s. (Greg Couch)
Guido van Rossum <guido@python.org>
parents: 9720
diff changeset
447 if (v != NULL) {
9720
24ca64134594 Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents: 9044
diff changeset
448 if (*(*p_format - 1) != 'N')
24ca64134594 Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents: 9044
diff changeset
449 Py_INCREF(v);
9722
3955f787e9a1 Oops, forgot a pair of {}'s. (Greg Couch)
Guido van Rossum <guido@python.org>
parents: 9720
diff changeset
450 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
451 else if (!PyErr_Occurred())
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
452 /* If a NULL was passed
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
453 * because a call that should
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
454 * have constructed a value
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
455 * failed, that's OK, and we
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
456 * pass the error on; but if
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
457 * no error occurred it's not
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
458 * clear that the caller knew
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
459 * what she was doing. */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
460 PyErr_SetString(PyExc_SystemError,
8640
8e86a797e596 Two error messages still used the old name of the functio mkvalue() --
Guido van Rossum <guido@python.org>
parents: 6613
diff changeset
461 "NULL object passed to Py_BuildValue");
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
462 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
463 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
464
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
465 case ':':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
466 case ',':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
467 case ' ':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
468 case '\t':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
469 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
470
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
471 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
472 PyErr_SetString(PyExc_SystemError,
8640
8e86a797e596 Two error messages still used the old name of the functio mkvalue() --
Guido van Rossum <guido@python.org>
parents: 6613
diff changeset
473 "bad format char passed to Py_BuildValue");
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
474 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
475
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
476 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
477 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
478 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
479
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
480
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
481 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
482 Py_BuildValue(const char *format, ...)
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
483 {
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
484 va_list va;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
485 PyObject* retval;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
486 va_start(va, format);
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
487 retval = va_build_value(format, va, 0);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
488 va_end(va);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
489 return retval;
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
490 }
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
491
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
492 PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
493 _Py_BuildValue_SizeT(const char *format, ...)
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
494 {
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
495 va_list va;
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
496 PyObject* retval;
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
497 va_start(va, format);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
498 retval = va_build_value(format, va, FLAG_SIZE_T);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
499 va_end(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
500 return retval;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
501 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
502
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
503 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
504 Py_VaBuildValue(const char *format, va_list va)
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
505 {
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
506 return va_build_value(format, va, 0);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
507 }
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
508
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
509 PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
510 _Py_VaBuildValue_SizeT(const char *format, va_list va)
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
511 {
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
512 return va_build_value(format, va, FLAG_SIZE_T);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
513 }
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
514
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
515 static PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
516 va_build_value(const char *format, va_list va, int flags)
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
517 {
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
518 const char *f = format;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
519 int n = countformat(f, '\0');
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
520 va_list lva;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
521
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
522 #ifdef VA_LIST_IS_ARRAY
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
523 memcpy(lva, va, sizeof(va_list));
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
524 #else
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
525 #ifdef __va_copy
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
526 __va_copy(lva, va);
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
527 #else
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
528 lva = va;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
529 #endif
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
530 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
531
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
532 if (n < 0)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
533 return NULL;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
534 if (n == 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
535 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
536 return Py_None;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
537 }
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
538 if (n == 1)
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
539 return do_mkvalue(&f, &lva, flags);
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
540 return do_mktuple(&f, &lva, '\0', n, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
541 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
542
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
543
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
544 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
545 PyEval_CallFunction(PyObject *obj, const char *format, ...)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
546 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
547 va_list vargs;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
548 PyObject *args;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
549 PyObject *res;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
550
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
551 va_start(vargs, format);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
552
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
553 args = Py_VaBuildValue(format, vargs);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
554 va_end(vargs);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
555
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
556 if (args == NULL)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
557 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
558
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
559 res = PyEval_CallObject(obj, args);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
560 Py_DECREF(args);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
561
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
562 return res;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
563 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
564
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
565
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
566 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
567 PyEval_CallMethod(PyObject *obj, const char *methodname, const char *format, ...)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
568 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
569 va_list vargs;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
570 PyObject *meth;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
571 PyObject *args;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
572 PyObject *res;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
573
8898
492363d6bc94 # Fix strange type (methonname instead of methodname).
Guido van Rossum <guido@python.org>
parents: 8822
diff changeset
574 meth = PyObject_GetAttrString(obj, methodname);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
575 if (meth == NULL)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
576 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
577
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
578 va_start(vargs, format);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
579
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
580 args = Py_VaBuildValue(format, vargs);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
581 va_end(vargs);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
582
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
583 if (args == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
584 Py_DECREF(meth);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
585 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
586 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
587
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
588 res = PyEval_CallObject(meth, args);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
589 Py_DECREF(meth);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
590 Py_DECREF(args);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
591
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
592 return res;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
593 }
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
594
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
595 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
596 PyModule_AddObject(PyObject *m, const char *name, PyObject *o)
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
597 {
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
598 PyObject *dict;
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
599 if (!PyModule_Check(m)) {
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
600 PyErr_SetString(PyExc_TypeError,
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
601 "PyModule_AddObject() needs module as first arg");
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
602 return -1;
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
603 }
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
604 if (!o) {
30771
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
605 if (!PyErr_Occurred())
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
606 PyErr_SetString(PyExc_TypeError,
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
607 "PyModule_AddObject() needs non-NULL value");
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
608 return -1;
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
609 }
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
610
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
611 dict = PyModule_GetDict(m);
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
612 if (dict == NULL) {
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
613 /* Internal error -- modules must have a dict! */
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
614 PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
615 PyModule_GetName(m));
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
616 return -1;
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
617 }
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
618 if (PyDict_SetItemString(dict, name, o))
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
619 return -1;
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
620 Py_DECREF(o);
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
621 return 0;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
622 }
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
623
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
624 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
625 PyModule_AddIntConstant(PyObject *m, const char *name, long value)
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
626 {
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
627 return PyModule_AddObject(m, name, PyInt_FromLong(value));
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
628 }
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
629
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
630 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
631 PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
632 {
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
633 return PyModule_AddObject(m, name, PyString_FromString(value));
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
634 }