annotate Python/modsupport.c @ 71221:a8be035f299f 2.7

start out this branch always with filename NULL
author Benjamin Peterson <benjamin@python.org>
date Mon, 04 Jul 2011 22:27:16 -0500
parents 4ee4086dd1b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* 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
6602
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
11 /* 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
12 char *_Py_PackageContext = NULL;
4514a5ea3ec4 Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents: 5925
diff changeset
13
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
14 /* Py_InitModule4() parameters:
2095
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
15 - name is the module name
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
16 - methods is the list of top-level functions
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
17 - doc is the documentation string
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
18 - 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
19 - 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
20 module was compiled
5925
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
21
93304b2e14cb Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
22 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
23 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
24 Errors may still leak memory.
2090
f78b387b54e0 New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
25 */
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
26
2095
0d7e4aa595f7 api version checking
Guido van Rossum <guido@python.org>
parents: 2090
diff changeset
27 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
28 "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
29 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
30
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
31 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
32 Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
33 PyObject *passthrough, int module_api_version)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
35 PyObject *m, *d, *v, *n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
36 PyMethodDef *ml;
66912
4ee4086dd1b7 Merged revisions 87251 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 61463
diff changeset
37 PyInterpreterState *interp = PyThreadState_Get()->interp;
4ee4086dd1b7 Merged revisions 87251 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 61463
diff changeset
38 if (interp->modules == NULL)
4ee4086dd1b7 Merged revisions 87251 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 61463
diff changeset
39 Py_FatalError("Python import machinery not initialized");
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
40 if (module_api_version != PYTHON_API_VERSION) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
41 char message[512];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
42 PyOS_snprintf(message, sizeof(message),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
43 api_version_warning, name,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
44 PYTHON_API_VERSION, name,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
45 module_api_version);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
46 if (PyErr_Warn(PyExc_RuntimeWarning, message))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
47 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
48 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
49 /* Make sure name is fully qualified.
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27533
diff changeset
50
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
51 This is a bit of a hack: when the shared library is loaded,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
52 the module name is "package.module", but the module calls
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
53 Py_InitModule*() with just "module" for the name. The shared
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
54 library loader squirrels away the true name of the module in
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
55 _Py_PackageContext, and Py_InitModule*() will substitute this
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
56 (if the name actually matches).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
57 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
58 if (_Py_PackageContext != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
59 char *p = strrchr(_Py_PackageContext, '.');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
60 if (p != NULL && strcmp(name, p+1) == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
61 name = _Py_PackageContext;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
62 _Py_PackageContext = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
63 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
64 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
65 if ((m = PyImport_AddModule(name)) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
66 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
67 d = PyModule_GetDict(m);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
68 if (methods != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
69 n = PyString_FromString(name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
70 if (n == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
71 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
72 for (ml = methods; ml->ml_name != NULL; ml++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
73 if ((ml->ml_flags & METH_CLASS) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
74 (ml->ml_flags & METH_STATIC)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
75 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
76 "module functions cannot set"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
77 " METH_CLASS or METH_STATIC");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
78 Py_DECREF(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
79 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
80 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
81 v = PyCFunction_NewEx(ml, passthrough, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
82 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
83 Py_DECREF(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
84 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
85 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
86 if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
87 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
88 Py_DECREF(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
89 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
90 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
91 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
92 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
93 Py_DECREF(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
94 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
95 if (doc != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
96 v = PyString_FromString(doc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
97 if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
98 Py_XDECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
99 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
100 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
101 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
102 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
103 return m;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
107 /* 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
108
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
109 static int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
110 countformat(const char *format, int endchar)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
111 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
112 int count = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
113 int level = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
114 while (level > 0 || *format != endchar) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
115 switch (*format) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
116 case '\0':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
117 /* Premature end */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
118 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
119 "unmatched paren in format");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
120 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
121 case '(':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
122 case '[':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
123 case '{':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
124 if (level == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
125 count++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
126 level++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
127 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
128 case ')':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
129 case ']':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
130 case '}':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
131 level--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
132 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
133 case '#':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
134 case '&':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
135 case ',':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
136 case ':':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
137 case ' ':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
138 case '\t':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
139 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
140 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
141 if (level == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
142 count++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
143 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
144 format++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
145 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
146 return count;
817
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
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 /* 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
151 /* 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
152
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
153 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
154 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
155 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
156 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
157
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
158
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
159 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
160 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
161 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
162 PyObject *d;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
163 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
164 int itemfailed = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
165 if (n < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
166 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
167 if ((d = PyDict_New()) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
168 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
169 /* Note that we can't bail immediately on error as this will leak
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
170 refcounts on any 'N' arguments. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
171 for (i = 0; i < n; i+= 2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
172 PyObject *k, *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
173 int err;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
174 k = do_mkvalue(p_format, p_va, flags);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
175 if (k == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
176 itemfailed = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
177 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
178 k = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
179 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
180 v = do_mkvalue(p_format, p_va, flags);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
181 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
182 itemfailed = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
183 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
184 v = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
185 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
186 err = PyDict_SetItem(d, k, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
187 Py_DECREF(k);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
188 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
189 if (err < 0 || itemfailed) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
190 Py_DECREF(d);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
191 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
192 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
193 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
194 if (d != NULL && **p_format != endchar) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
195 Py_DECREF(d);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
196 d = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
197 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
198 "Unmatched paren in format");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
199 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
200 else if (endchar)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
201 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
202 return d;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
203 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
204
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
205 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
206 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
207 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
208 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
209 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
210 int itemfailed = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
211 if (n < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
212 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
213 v = PyList_New(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
214 if (v == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
215 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
216 /* Note that we can't bail immediately on error as this will leak
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
217 refcounts on any 'N' arguments. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
218 for (i = 0; i < n; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
219 PyObject *w = do_mkvalue(p_format, p_va, flags);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
220 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
221 itemfailed = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
222 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
223 w = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
224 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
225 PyList_SET_ITEM(v, i, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
226 }
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
227
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
228 if (itemfailed) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
229 /* do_mkvalue() should have already set an error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
230 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
231 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
232 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
233 if (**p_format != endchar) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
234 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
235 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
236 "Unmatched paren in format");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
237 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
238 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
239 if (endchar)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
240 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
241 return v;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
242 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
243
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
244 #ifdef Py_USING_UNICODE
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
245 static int
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
246 _ustrlen(Py_UNICODE *u)
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
247 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
248 int i = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
249 Py_UNICODE *v = u;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
250 while (*v != 0) { i++; v++; }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
251 return i;
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
252 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
253 #endif
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
254
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
255 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
256 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
257 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
258 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
259 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
260 int itemfailed = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
261 if (n < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
262 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
263 if ((v = PyTuple_New(n)) == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
264 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
265 /* Note that we can't bail immediately on error as this will leak
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
266 refcounts on any 'N' arguments. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
267 for (i = 0; i < n; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
268 PyObject *w = do_mkvalue(p_format, p_va, flags);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
269 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
270 itemfailed = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
271 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
272 w = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
273 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
274 PyTuple_SET_ITEM(v, i, w);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
275 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
276 if (itemfailed) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
277 /* do_mkvalue() should have already set an error */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
278 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
279 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
280 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
281 if (**p_format != endchar) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
282 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
283 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
284 "Unmatched paren in format");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
285 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
286 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
287 if (endchar)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
288 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
289 return v;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
290 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
291
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
292 static PyObject *
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
293 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
294 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
295 for (;;) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
296 switch (*(*p_format)++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
297 case '(':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
298 return do_mktuple(p_format, p_va, ')',
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
299 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
300
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
301 case '[':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
302 return do_mklist(p_format, p_va, ']',
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
303 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
304
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
305 case '{':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
306 return do_mkdict(p_format, p_va, '}',
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
307 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
308
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
309 case 'b':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
310 case 'B':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
311 case 'h':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
312 case 'i':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
313 return PyInt_FromLong((long)va_arg(*p_va, int));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
314
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
315 case 'H':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
316 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
317
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
318 case 'I':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
319 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
320 unsigned int n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
321 n = va_arg(*p_va, unsigned int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
322 if (n > (unsigned long)PyInt_GetMax())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
323 return PyLong_FromUnsignedLong((unsigned long)n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
324 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
325 return PyInt_FromLong(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
326 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
327
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
328 case 'n':
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
329 #if SIZEOF_SIZE_T!=SIZEOF_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
330 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
331 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
332 /* Fall through from 'n' to 'l' if Py_ssize_t is long */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
333 case 'l':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
334 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
335
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
336 case 'k':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
337 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
338 unsigned long n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
339 n = va_arg(*p_va, unsigned long);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
340 if (n > (unsigned long)PyInt_GetMax())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
341 return PyLong_FromUnsignedLong(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
342 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
343 return PyInt_FromLong(n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
344 }
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
345
9949
98e37347378b Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents: 9722
diff changeset
346 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
347 case 'L':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
348 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
349
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
350 case 'K':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
351 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
352 #endif
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
353 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
354 case 'u':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
355 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
356 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
357 Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
358 Py_ssize_t n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
359 if (**p_format == '#') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
360 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
361 if (flags & FLAG_SIZE_T)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
362 n = va_arg(*p_va, Py_ssize_t);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
363 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
364 n = va_arg(*p_va, int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
365 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
366 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
367 n = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
368 if (u == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
369 v = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
370 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
371 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
372 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
373 if (n < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
374 n = _ustrlen(u);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
375 v = PyUnicode_FromUnicode(u, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
376 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
377 return v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
378 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18991
diff changeset
379 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
380 case 'f':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
381 case 'd':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
382 return PyFloat_FromDouble(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
383 (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
384
17032
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
385 #ifndef WITHOUT_COMPLEX
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
386 case 'D':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
387 return PyComplex_FromCComplex(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
388 *((Py_complex *)va_arg(*p_va, Py_complex *)));
17032
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
389 #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
390
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
391 case 'c':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
392 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
393 char p[1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
394 p[0] = (char)va_arg(*p_va, int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
395 return PyString_FromStringAndSize(p, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
396 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
397
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
398 case 's':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
399 case 'z':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
400 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
401 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
402 char *str = va_arg(*p_va, char *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
403 Py_ssize_t n;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
404 if (**p_format == '#') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
405 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
406 if (flags & FLAG_SIZE_T)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
407 n = va_arg(*p_va, Py_ssize_t);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
408 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
409 n = va_arg(*p_va, int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
410 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
411 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
412 n = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
413 if (str == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
414 v = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
415 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
416 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
417 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
418 if (n < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
419 size_t m = strlen(str);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
420 if (m > PY_SSIZE_T_MAX) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
421 PyErr_SetString(PyExc_OverflowError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
422 "string too long for Python string");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
423 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
424 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
425 n = (Py_ssize_t)m;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
426 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
427 v = PyString_FromStringAndSize(str, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
428 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
429 return v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
430 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
431
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
432 case 'N':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
433 case 'S':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
434 case 'O':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
435 if (**p_format == '&') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
436 typedef PyObject *(*converter)(void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
437 converter func = va_arg(*p_va, converter);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
438 void *arg = va_arg(*p_va, void *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
439 ++*p_format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
440 return (*func)(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
441 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
442 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
443 PyObject *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
444 v = va_arg(*p_va, PyObject *);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
445 if (v != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
446 if (*(*p_format - 1) != 'N')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
447 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
448 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
449 else if (!PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
450 /* If a NULL was passed
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
451 * because a call that should
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
452 * have constructed a value
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
453 * failed, that's OK, and we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
454 * pass the error on; but if
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
455 * no error occurred it's not
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
456 * clear that the caller knew
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
457 * what she was doing. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
458 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
459 "NULL object passed to Py_BuildValue");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
460 return v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
461 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
462
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
463 case ':':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
464 case ',':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
465 case ' ':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
466 case '\t':
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
467 break;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
468
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
469 default:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
470 PyErr_SetString(PyExc_SystemError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
471 "bad format char passed to Py_BuildValue");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
472 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
473
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
474 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
475 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
476 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
477
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
478
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
479 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
480 Py_BuildValue(const char *format, ...)
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
481 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
482 va_list va;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
483 PyObject* retval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
484 va_start(va, format);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
485 retval = va_build_value(format, va, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
486 va_end(va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
487 return retval;
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
488 }
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
489
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
490 PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
491 _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
492 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
493 va_list va;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
494 PyObject* retval;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
495 va_start(va, format);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
496 retval = va_build_value(format, va, FLAG_SIZE_T);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
497 va_end(va);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
498 return retval;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
499 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
500
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
501 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
502 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
503 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
504 return va_build_value(format, va, 0);
37702
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
505 }
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
506
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
507 PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
508 _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
509 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
510 return va_build_value(format, va, FLAG_SIZE_T);
37702
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
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
513 static PyObject *
9b22d8b7bcaa Make Py_BuildValue, PyObject_CallFunction and
Martin v. Löwis <martin@v.loewis.de>
parents: 37673
diff changeset
514 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
515 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
516 const char *f = format;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
517 int n = countformat(f, '\0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
518 va_list lva;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
519
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
520 #ifdef VA_LIST_IS_ARRAY
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
521 memcpy(lva, va, sizeof(va_list));
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
522 #else
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
523 #ifdef __va_copy
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
524 __va_copy(lva, va);
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
525 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
526 lva = va;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
527 #endif
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
528 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
529
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
530 if (n < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
531 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
532 if (n == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
533 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
534 return Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
535 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
536 if (n == 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
537 return do_mkvalue(&f, &lva, flags);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
538 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
539 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
540
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
541
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
542 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
543 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
544 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
545 va_list vargs;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
546 PyObject *args;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
547 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
548
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
549 va_start(vargs, format);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
550
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
551 args = Py_VaBuildValue(format, vargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
552 va_end(vargs);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
553
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
554 if (args == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
555 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
556
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
557 res = PyEval_CallObject(obj, args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
558 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
559
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
560 return res;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
561 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
562
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
563
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
564 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
565 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
566 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
567 va_list vargs;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
568 PyObject *meth;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
569 PyObject *args;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
570 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
571
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
572 meth = PyObject_GetAttrString(obj, methodname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
573 if (meth == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
574 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
575
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
576 va_start(vargs, format);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
577
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
578 args = Py_VaBuildValue(format, vargs);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
579 va_end(vargs);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
580
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
581 if (args == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
582 Py_DECREF(meth);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
583 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
584 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
585
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
586 res = PyEval_CallObject(meth, args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
587 Py_DECREF(meth);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
588 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
589
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
590 return res;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
591 }
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
592
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
593 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
594 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
595 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
596 PyObject *dict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
597 if (!PyModule_Check(m)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
598 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
599 "PyModule_AddObject() needs module as first arg");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
600 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
601 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
602 if (!o) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
603 if (!PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
604 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
605 "PyModule_AddObject() needs non-NULL value");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
606 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
607 }
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
608
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
609 dict = PyModule_GetDict(m);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
610 if (dict == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
611 /* Internal error -- modules must have a dict! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
612 PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
613 PyModule_GetName(m));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
614 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
615 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
616 if (PyDict_SetItemString(dict, name, o))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
617 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
618 Py_DECREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
619 return 0;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
620 }
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
621
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
622 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
623 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
624 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
625 PyObject *o = PyInt_FromLong(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
626 if (!o)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
627 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
628 if (PyModule_AddObject(m, name, o) == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
629 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
630 Py_DECREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
631 return -1;
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
634 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
635 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
636 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
637 PyObject *o = PyString_FromString(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
638 if (!o)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
639 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
640 if (PyModule_AddObject(m, name, o) == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
641 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
642 Py_DECREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
643 return -1;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
644 }