Mercurial > cpython-lru_cache-weakref
annotate Python/modsupport.c @ 31058:bf7df48012cb 2.3
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
comments about why both calls to cyclic gc here can cause problems.
Already fixed on the trunk. Since the calls were introduced in 2.3,
that's the end of it.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Mon, 01 Dec 2003 22:13:12 +0000 |
| parents | 60ce73ea9c92 |
| children | a6879d1733d7 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Module support implementation */ |
| 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 | 5 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
6 #ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
7 typedef extended 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
|
8 #else |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
9 typedef double va_double; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
10 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
11 |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
12 /* 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
|
13 char *_Py_PackageContext = NULL; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
14 |
|
5925
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
15 /* Py_InitModule4() parameters: |
| 2095 | 16 - name is the module name |
| 17 - methods is the list of top-level functions | |
| 18 - doc is the documentation string | |
| 19 - passthrough is passed as self to functions defined in the module | |
| 20 - api_version is the value of PYTHON_API_VERSION at the time the | |
| 21 module was compiled | |
|
5925
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
22 |
|
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
23 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
|
24 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
|
25 Errors may still leak memory. |
|
2090
f78b387b54e0
New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
26 */ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
27 |
| 2095 | 28 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
|
29 "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
|
30 This Python has API version %d, module %.100s has version %d."; |
| 2095 | 31 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
32 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
33 Py_InitModule4(char *name, PyMethodDef *methods, char *doc, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
34 PyObject *passthrough, int module_api_version) |
| 6 | 35 { |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
36 PyObject *m, *d, *v, *n; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
37 PyMethodDef *ml; |
|
13859
94f6ec87930a
Add a test that Py_IsInitialized() in Py_InitModule4(). See
Guido van Rossum <guido@python.org>
parents:
13658
diff
changeset
|
38 if (!Py_IsInitialized()) |
|
94f6ec87930a
Add a test that Py_IsInitialized() in Py_InitModule4(). See
Guido van Rossum <guido@python.org>
parents:
13658
diff
changeset
|
39 Py_FatalError("Interpreter not initialized (version mismatch?)"); |
|
18908
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
40 if (module_api_version != PYTHON_API_VERSION) { |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
41 char message[512]; |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
42 PyOS_snprintf(message, sizeof(message), |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
43 api_version_warning, name, |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
44 PYTHON_API_VERSION, name, |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
45 module_api_version); |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
46 if (PyErr_Warn(PyExc_RuntimeWarning, message)) |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
47 return NULL; |
|
79c676f9b34a
This patch turns the Python API mismatch notice into a standard
Marc-André Lemburg <mal@egenix.com>
parents:
17032
diff
changeset
|
48 } |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
49 /* Make sure name is fully qualified. |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
50 |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
51 This is a bit of a hack: when the shared library is loaded, |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
52 the module name is "package.module", but the module calls |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
53 Py_InitModule*() with just "module" for the name. The shared |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
54 library loader squirrels away the true name of the module in |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
55 _Py_PackageContext, and Py_InitModule*() will substitute this |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
56 (if the name actually matches). |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
57 */ |
|
6602
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
58 if (_Py_PackageContext != NULL) { |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
59 char *p = strrchr(_Py_PackageContext, '.'); |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
60 if (p != NULL && strcmp(name, p+1) == 0) { |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
61 name = _Py_PackageContext; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
62 _Py_PackageContext = NULL; |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
63 } |
|
4514a5ea3ec4
Fix importing of shared libraries from inside packages.
Guido van Rossum <guido@python.org>
parents:
5925
diff
changeset
|
64 } |
|
5925
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
65 if ((m = PyImport_AddModule(name)) == NULL) |
|
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
66 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
67 d = PyModule_GetDict(m); |
|
24834
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
68 if (methods != NULL) { |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
69 n = PyString_FromString(name); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
70 if (n == NULL) |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
71 return NULL; |
|
24834
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
72 for (ml = methods; ml->ml_name != NULL; ml++) { |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
73 if ((ml->ml_flags & METH_CLASS) || |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
74 (ml->ml_flags & METH_STATIC)) { |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
75 PyErr_SetString(PyExc_ValueError, |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
76 "module functions cannot set" |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
77 " METH_CLASS or METH_STATIC"); |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
78 return NULL; |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
79 } |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27533
diff
changeset
|
80 v = PyCFunction_NewEx(ml, passthrough, n); |
|
24834
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
81 if (v == NULL) |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
82 return NULL; |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
83 if (PyDict_SetItemString(d, ml->ml_name, v) != 0) { |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
84 Py_DECREF(v); |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
85 return NULL; |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
86 } |
|
64f4dd770c67
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
Fred Drake <fdrake@acm.org>
parents:
24400
diff
changeset
|
87 Py_DECREF(v); |
|
22613
ddc9543c76a0
Introduce two new flag bits that can be set in a PyMethodDef method
Fred Drake <fdrake@acm.org>
parents:
19343
diff
changeset
|
88 } |
| 6 | 89 } |
|
2090
f78b387b54e0
New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
90 if (doc != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
91 v = PyString_FromString(doc); |
|
18991
360cece76123
Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
Fred Drake <fdrake@acm.org>
parents:
18908
diff
changeset
|
92 if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) { |
|
26664
fe2d422385b1
Fixed potential crash: v can be NULL here, so use Py_XDECREF rather than Py_DECREF
Just van Rossum <just@letterror.com>
parents:
24834
diff
changeset
|
93 Py_XDECREF(v); |
|
5925
93304b2e14cb
Removed fatal errors from Py_Initmodule4() (and thus from
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
94 return NULL; |
|
18991
360cece76123
Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
Fred Drake <fdrake@acm.org>
parents:
18908
diff
changeset
|
95 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
96 Py_DECREF(v); |
|
2090
f78b387b54e0
New newmethodobject() interface takes struct methodlist pointer
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
97 } |
| 86 | 98 return m; |
| 6 | 99 } |
| 100 | |
| 101 | |
|
1211
406860dfaac7
* stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
102 /* 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
|
103 |
|
27533
842d6a24497a
Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents:
26664
diff
changeset
|
104 static int |
|
842d6a24497a
Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents:
26664
diff
changeset
|
105 countformat(char *format, int endchar) |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
106 { |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
107 int count = 0; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
108 int level = 0; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
109 while (level > 0 || *format != endchar) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
110 switch (*format) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
111 case '\0': |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
112 /* Premature end */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
113 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
114 "unmatched paren in format"); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
115 return -1; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
116 case '(': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
117 case '[': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
118 case '{': |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
119 if (level == 0) |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
120 count++; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
121 level++; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
122 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
123 case ')': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
124 case ']': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
125 case '}': |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
126 level--; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
127 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
128 case '#': |
|
2202
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
129 case '&': |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
130 case ',': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
131 case ':': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
132 case ' ': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
133 case '\t': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
134 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
135 default: |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
136 if (level == 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
137 count++; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
138 } |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
139 format++; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
140 } |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
141 return count; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
142 } |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
143 |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
144 |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
145 /* 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
|
146 /* 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
|
147 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
148 static PyObject *do_mktuple(char**, va_list *, int, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
149 static PyObject *do_mklist(char**, va_list *, int, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
150 static PyObject *do_mkdict(char**, va_list *, int, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
151 static PyObject *do_mkvalue(char**, va_list *); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
152 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
153 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
154 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
155 do_mkdict(char **p_format, va_list *p_va, int endchar, int n) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
156 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
157 PyObject *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
158 int i; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
159 if (n < 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
160 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
161 if ((d = PyDict_New()) == NULL) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
162 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
163 for (i = 0; i < n; i+= 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
164 PyObject *k, *v; |
|
6613
2e874a5a912f
Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents:
6602
diff
changeset
|
165 int err; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
166 k = do_mkvalue(p_format, p_va); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
167 if (k == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
168 Py_DECREF(d); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
169 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
170 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
171 v = do_mkvalue(p_format, p_va); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
172 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
173 Py_DECREF(k); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
174 Py_DECREF(d); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
175 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
176 } |
|
6613
2e874a5a912f
Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents:
6602
diff
changeset
|
177 err = PyDict_SetItem(d, k, v); |
|
2e874a5a912f
Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents:
6602
diff
changeset
|
178 Py_DECREF(k); |
|
2e874a5a912f
Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents:
6602
diff
changeset
|
179 Py_DECREF(v); |
|
2e874a5a912f
Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents:
6602
diff
changeset
|
180 if (err < 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
181 Py_DECREF(d); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
182 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
183 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
184 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
185 if (d != NULL && **p_format != endchar) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
186 Py_DECREF(d); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
187 d = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
188 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
189 "Unmatched paren in format"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
190 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
191 else if (endchar) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
192 ++*p_format; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
193 return d; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
194 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
195 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
196 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
197 do_mklist(char **p_format, va_list *p_va, int endchar, int n) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
198 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
199 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
200 int i; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
201 if (n < 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
202 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
203 if ((v = PyList_New(n)) == NULL) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
204 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
205 for (i = 0; i < n; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
206 PyObject *w = do_mkvalue(p_format, p_va); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
207 if (w == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
208 Py_DECREF(v); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
209 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
210 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
211 PyList_SetItem(v, i, w); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
212 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
213 if (v != NULL && **p_format != endchar) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
214 Py_DECREF(v); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
215 v = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
216 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
217 "Unmatched paren in format"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
218 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
219 else if (endchar) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
220 ++*p_format; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
221 return v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
222 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
223 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18991
diff
changeset
|
224 #ifdef Py_USING_UNICODE |
|
12520
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
225 static int |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
226 _ustrlen(Py_UNICODE *u) |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
227 { |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
228 int i = 0; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
229 Py_UNICODE *v = u; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
230 while (*v != 0) { i++; v++; } |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
231 return i; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
232 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18991
diff
changeset
|
233 #endif |
|
12520
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
234 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
235 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
236 do_mktuple(char **p_format, va_list *p_va, int endchar, int n) |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
237 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
238 PyObject *v; |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
239 int i; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
240 if (n < 0) |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
241 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
242 if ((v = PyTuple_New(n)) == NULL) |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
243 return NULL; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
244 for (i = 0; i < n; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
245 PyObject *w = do_mkvalue(p_format, p_va); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
246 if (w == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
247 Py_DECREF(v); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
248 return NULL; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
249 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
250 PyTuple_SetItem(v, i, w); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
251 } |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
252 if (v != NULL && **p_format != endchar) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
253 Py_DECREF(v); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
254 v = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
255 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
256 "Unmatched paren in format"); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
257 } |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
258 else if (endchar) |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
259 ++*p_format; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
260 return v; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
261 } |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
262 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
263 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
264 do_mkvalue(char **p_format, va_list *p_va) |
|
860
39134c99c923
Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents:
817
diff
changeset
|
265 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
266 for (;;) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
267 switch (*(*p_format)++) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
268 case '(': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
269 return do_mktuple(p_format, p_va, ')', |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
270 countformat(*p_format, ')')); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
271 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
272 case '[': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
273 return do_mklist(p_format, p_va, ']', |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
274 countformat(*p_format, ']')); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
275 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
276 case '{': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
277 return do_mkdict(p_format, p_va, '}', |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
278 countformat(*p_format, '}')); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
279 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
280 case 'b': |
|
14588
dcbc084d046e
Cast UCHAR_MAX to int before doing the comparison for overflow of the
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
281 case 'B': |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
282 case 'h': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
283 case 'i': |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
284 return PyInt_FromLong((long)va_arg(*p_va, int)); |
|
13378
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13330
diff
changeset
|
285 |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13330
diff
changeset
|
286 case 'H': |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13330
diff
changeset
|
287 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
|
288 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
289 case 'l': |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
290 return PyInt_FromLong((long)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
|
291 |
|
28658
8836529e9e66
dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
28437
diff
changeset
|
292 case 'k': |
|
8836529e9e66
dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
28437
diff
changeset
|
293 return PyInt_FromLong((long)va_arg(*p_va, unsigned long)); |
|
8836529e9e66
dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
28437
diff
changeset
|
294 |
|
9949
98e37347378b
Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents:
9722
diff
changeset
|
295 #ifdef HAVE_LONG_LONG |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8640
diff
changeset
|
296 case 'L': |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27559
diff
changeset
|
297 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
|
298 |
|
8836529e9e66
dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
28437
diff
changeset
|
299 case 'K': |
|
8836529e9e66
dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
28437
diff
changeset
|
300 return PyLong_FromLongLong((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
|
301 #endif |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18991
diff
changeset
|
302 #ifdef Py_USING_UNICODE |
|
12520
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
303 case 'u': |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
304 { |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
305 PyObject *v; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
306 Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *); |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
307 int n; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
308 if (**p_format == '#') { |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
309 ++*p_format; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
310 n = va_arg(*p_va, int); |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
311 } |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
312 else |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
313 n = -1; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
314 if (u == NULL) { |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
315 v = Py_None; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
316 Py_INCREF(v); |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
317 } |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
318 else { |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
319 if (n < 0) |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
320 n = _ustrlen(u); |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
321 v = PyUnicode_FromUnicode(u, n); |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
322 } |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
323 return v; |
|
b6b7bd20c845
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
9949
diff
changeset
|
324 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18991
diff
changeset
|
325 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
326 case 'f': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
327 case 'd': |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
328 return PyFloat_FromDouble( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
329 (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
|
330 |
|
17032
d5811af8acf3
Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents:
14869
diff
changeset
|
331 #ifndef WITHOUT_COMPLEX |
|
d5811af8acf3
Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents:
14869
diff
changeset
|
332 case 'D': |
|
d5811af8acf3
Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents:
14869
diff
changeset
|
333 return PyComplex_FromCComplex( |
|
d5811af8acf3
Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents:
14869
diff
changeset
|
334 *((Py_complex *)va_arg(*p_va, Py_complex *))); |
|
d5811af8acf3
Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents:
14869
diff
changeset
|
335 #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
|
336 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
337 case 'c': |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
338 { |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
339 char p[1]; |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
340 p[0] = va_arg(*p_va, int); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
341 return PyString_FromStringAndSize(p, 1); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
342 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
343 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
344 case 's': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
345 case 'z': |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
346 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
347 PyObject *v; |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
348 char *str = va_arg(*p_va, char *); |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
349 int n; |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
350 if (**p_format == '#') { |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
351 ++*p_format; |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
352 n = va_arg(*p_va, int); |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
353 } |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
354 else |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
355 n = -1; |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
356 if (str == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
357 v = Py_None; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
358 Py_INCREF(v); |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
359 } |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
360 else { |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
361 if (n < 0) { |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
362 size_t m = strlen(str); |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
363 if (m > INT_MAX) { |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
364 PyErr_SetString(PyExc_OverflowError, |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
365 "string too long for Python string"); |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
366 return NULL; |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
367 } |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
368 n = (int)m; |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12520
diff
changeset
|
369 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
370 v = PyString_FromStringAndSize(str, n); |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
371 } |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
372 return v; |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
373 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
374 |
|
9720
24ca64134594
Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
375 case 'N': |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
376 case 'S': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
377 case 'O': |
|
2202
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
378 if (**p_format == '&') { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
379 typedef PyObject *(*converter)(void *); |
|
2202
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
380 converter func = va_arg(*p_va, converter); |
|
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
381 void *arg = va_arg(*p_va, void *); |
|
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
382 ++*p_format; |
|
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
383 return (*func)(arg); |
|
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
384 } |
|
9894e55468ec
support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents:
2154
diff
changeset
|
385 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
386 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
387 v = va_arg(*p_va, PyObject *); |
|
9722
3955f787e9a1
Oops, forgot a pair of {}'s. (Greg Couch)
Guido van Rossum <guido@python.org>
parents:
9720
diff
changeset
|
388 if (v != NULL) { |
|
9720
24ca64134594
Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
389 if (*(*p_format - 1) != 'N') |
|
24ca64134594
Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
390 Py_INCREF(v); |
|
9722
3955f787e9a1
Oops, forgot a pair of {}'s. (Greg Couch)
Guido van Rossum <guido@python.org>
parents:
9720
diff
changeset
|
391 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
392 else if (!PyErr_Occurred()) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
393 /* If a NULL was passed |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
394 * because a call that should |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
395 * have constructed a value |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
396 * failed, that's OK, and we |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
397 * pass the error on; but if |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
398 * no error occurred it's not |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
399 * clear that the caller knew |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
400 * what she was doing. */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
401 PyErr_SetString(PyExc_SystemError, |
|
8640
8e86a797e596
Two error messages still used the old name of the functio mkvalue() --
Guido van Rossum <guido@python.org>
parents:
6613
diff
changeset
|
402 "NULL object passed to Py_BuildValue"); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
403 return v; |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
404 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
405 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
406 case ':': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
407 case ',': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
408 case ' ': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
409 case '\t': |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
410 break; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
411 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
412 default: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
413 PyErr_SetString(PyExc_SystemError, |
|
8640
8e86a797e596
Two error messages still used the old name of the functio mkvalue() --
Guido van Rossum <guido@python.org>
parents:
6613
diff
changeset
|
414 "bad format char passed to Py_BuildValue"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
415 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
416 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
417 } |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
418 } |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
419 } |
|
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
420 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
421 |
|
27533
842d6a24497a
Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents:
26664
diff
changeset
|
422 PyObject * |
|
842d6a24497a
Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents:
26664
diff
changeset
|
423 Py_BuildValue(char *format, ...) |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
424 { |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
425 va_list va; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
426 PyObject* retval; |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
427 va_start(va, format); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
428 retval = Py_VaBuildValue(format, va); |
|
817
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
429 va_end(va); |
|
aa633f0defa6
Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents:
816
diff
changeset
|
430 return retval; |
|
816
e4a27d84ea36
Added mkvalue() function
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
431 } |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
432 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
433 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
434 Py_VaBuildValue(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
|
435 { |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
436 char *f = format; |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
437 int n = countformat(f, '\0'); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
438 va_list lva; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
439 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
440 #ifdef VA_LIST_IS_ARRAY |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
441 memcpy(lva, va, sizeof(va_list)); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
442 #else |
|
24400
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
23888
diff
changeset
|
443 #ifdef __va_copy |
|
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
23888
diff
changeset
|
444 __va_copy(lva, va); |
|
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
23888
diff
changeset
|
445 #else |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
446 lva = va; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
447 #endif |
|
24400
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
23888
diff
changeset
|
448 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
449 |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
450 if (n < 0) |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
451 return NULL; |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
452 if (n == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
453 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
454 return Py_None; |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
455 } |
|
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
456 if (n == 1) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
457 return do_mkvalue(&f, &lva); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
458 return do_mktuple(&f, &lva, '\0', n); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
459 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
460 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
461 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
462 PyObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
463 PyEval_CallFunction(PyObject *obj, 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
|
464 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
465 va_list vargs; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
466 PyObject *args; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
467 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
|
468 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
469 va_start(vargs, format); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
470 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
471 args = Py_VaBuildValue(format, vargs); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
472 va_end(vargs); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
473 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
474 if (args == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
475 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
476 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
477 res = PyEval_CallObject(obj, args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
478 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
|
479 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
480 return res; |
|
1252
c4cd0d9d8281
* Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents:
1211
diff
changeset
|
481 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
482 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
483 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
484 PyObject * |
|
8898
492363d6bc94
# Fix strange type (methonname instead of methodname).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
485 PyEval_CallMethod(PyObject *obj, char *methodname, 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
|
486 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
487 va_list vargs; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
488 PyObject *meth; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
489 PyObject *args; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
490 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
|
491 |
|
8898
492363d6bc94
# Fix strange type (methonname instead of methodname).
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
492 meth = PyObject_GetAttrString(obj, methodname); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
493 if (meth == NULL) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
494 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
495 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
496 va_start(vargs, format); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
497 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
498 args = Py_VaBuildValue(format, vargs); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
499 va_end(vargs); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
500 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
501 if (args == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
502 Py_DECREF(meth); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
503 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
504 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
505 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
506 res = PyEval_CallObject(meth, args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
507 Py_DECREF(meth); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
508 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
|
509 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
510 return res; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
511 } |
|
14781
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
512 |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
513 int |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
514 PyModule_AddObject(PyObject *m, char *name, PyObject *o) |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
515 { |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
516 PyObject *dict; |
| 29579 | 517 if (!PyModule_Check(m)) { |
|
23888
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
518 PyErr_SetString(PyExc_TypeError, |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
519 "PyModule_AddObject() needs module as first arg"); |
|
14781
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
520 return -1; |
|
23888
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
521 } |
| 29579 | 522 if (!o) { |
| 523 PyErr_SetString(PyExc_TypeError, | |
| 524 "PyModule_AddObject() needs non-NULL value"); | |
| 525 return -1; | |
| 526 } | |
| 527 | |
|
23888
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
528 dict = PyModule_GetDict(m); |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
529 if (dict == NULL) { |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
530 /* Internal error -- modules must have a dict! */ |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
531 PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
532 PyModule_GetName(m)); |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
533 return -1; |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
534 } |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
535 if (PyDict_SetItemString(dict, name, o)) |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
536 return -1; |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
537 Py_DECREF(o); |
|
7b66f0034233
PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents:
22613
diff
changeset
|
538 return 0; |
|
14781
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
539 } |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
540 |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
541 int |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
542 PyModule_AddIntConstant(PyObject *m, char *name, long value) |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
543 { |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
544 return PyModule_AddObject(m, name, PyInt_FromLong(value)); |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
545 } |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
546 |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
547 int |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
548 PyModule_AddStringConstant(PyObject *m, char *name, char *value) |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
549 { |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
550 return PyModule_AddObject(m, name, PyString_FromString(value)); |
|
081671cef7c1
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
14588
diff
changeset
|
551 } |
