annotate Python/modsupport.c @ 58664:993f703a61ba

Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done partially before. Also add a comment describing how this might have to work with different versions of the interpreter. ........ r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line Fixed typo ........ r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line #7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such. ........ r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line Add note about usage of STRINGLIB_EMPTY. ........ r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line Fix internal reference. ........ r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines data descriptors do not override the class dictionary if __get__ is not defined Adjust documentation and add a test to verify this behavior. See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for discussion. ........ r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines Do not compile stubs for the sha2 series hashes in the openssl hashlib module when the openssl version is too old to support them. That leads both compiled code bloat and to unittests attempting to test implementations that don't exist for comparison purposes on such platforms. ........ r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line Add two more test_strtod test values. ........ r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line #7762: fix refcount annotation of PyUnicode_Tailmatch(). ........ r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line #7725: fix referencing issue. ........ r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line mention from_float() in error message ........ r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line #7802: fix invalid example (heh). ........ r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines Fix-up ftplib documentation: move exception descriptions to toplevel, not inside a class remove attribution in "versionadded" spell and grammar check docstring of FTP_TLS ........ r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line Minor modification to unittest documentation. ........
author Benjamin Peterson <benjamin@python.org>
date Wed, 03 Feb 2010 02:35:45 +0000
parents 0f9e8d3ecac3
children cab14be0ada1
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
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
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
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
9 static PyObject *va_build_value(const char *, va_list, int);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
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
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
14 /* 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
15
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
16 static int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
17 countformat(const char *format, int endchar)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
18 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
19 int count = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
20 int level = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
21 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
22 switch (*format) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
23 case '\0':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
24 /* Premature end */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
25 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
26 "unmatched paren in format");
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
27 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
28 case '(':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
29 case '[':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
30 case '{':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
31 if (level == 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
32 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
33 level++;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
34 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
35 case ')':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
36 case ']':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
37 case '}':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
38 level--;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
39 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
40 case '#':
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
41 case '&':
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
42 case ',':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
43 case ':':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
44 case ' ':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
45 case '\t':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
46 break;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
47 default:
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
48 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
49 count++;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
50 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
51 format++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
52 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
53 return count;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
54 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
55
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
56
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
57 /* 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
58 /* 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
59
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
60 static PyObject *do_mktuple(const char**, va_list *, int, int, int);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
61 static PyObject *do_mklist(const char**, va_list *, int, int, int);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
62 static PyObject *do_mkdict(const char**, va_list *, int, int, int);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
63 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
64
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
65
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
66 static PyObject *
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
67 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
68 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
69 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
70 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
71 int itemfailed = 0;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
72 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
73 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
74 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
75 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
76 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
77 refcounts on any 'N' arguments. */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
78 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
79 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
80 int err;
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
81 k = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
82 if (k == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
83 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
84 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
85 k = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
86 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
87 v = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
88 if (v == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
89 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
90 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
91 v = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
92 }
6613
2e874a5a912f Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
Guido van Rossum <guido@python.org>
parents: 6602
diff changeset
93 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
94 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
95 Py_DECREF(v);
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
96 if (err < 0 || itemfailed) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
97 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
98 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
99 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
100 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
101 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
102 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
103 d = NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
104 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
105 "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
106 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
107 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
108 ++*p_format;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
109 return d;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
110 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
111
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
112 static PyObject *
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
113 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
114 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
115 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
116 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
117 int itemfailed = 0;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
118 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
119 return NULL;
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
120 v = PyList_New(n);
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
121 if (v == NULL)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
122 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
123 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
124 refcounts on any 'N' arguments. */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
125 for (i = 0; i < n; i++) {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
126 PyObject *w = do_mkvalue(p_format, p_va, flags);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
127 if (w == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
128 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
129 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
130 w = Py_None;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
131 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
132 PyList_SET_ITEM(v, i, w);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
133 }
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
134
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
135 if (itemfailed) {
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
136 /* do_mkvalue() should have already set an error */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
137 Py_DECREF(v);
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
138 return NULL;
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
139 }
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
140 if (**p_format != endchar) {
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
141 Py_DECREF(v);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
142 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
143 "Unmatched paren in format");
36858
7fac5d79d043 Try to cleanup the error handling a bit so there aren't false positives
Neal Norwitz <nnorwitz@gmail.com>
parents: 36774
diff changeset
144 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
145 }
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
146 if (endchar)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
147 ++*p_format;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
148 return v;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
149 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
150
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
151 static int
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
152 _ustrlen(Py_UNICODE *u)
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
153 {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
154 int i = 0;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
155 Py_UNICODE *v = u;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
156 while (*v != 0) { i++; v++; }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
157 return i;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
158 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
159
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
160 static PyObject *
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
161 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
162 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
163 PyObject *v;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
164 int i;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
165 int itemfailed = 0;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
166 if (n < 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
167 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
168 if ((v = PyTuple_New(n)) == NULL)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
169 return NULL;
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
170 /* Note that we can't bail immediately on error as this will leak
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
171 refcounts on any 'N' arguments. */
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
172 for (i = 0; i < n; i++) {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
173 PyObject *w = do_mkvalue(p_format, p_va, flags);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
174 if (w == NULL) {
32656
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
175 itemfailed = 1;
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
176 Py_INCREF(Py_None);
391937571065 This is Pete Shinners' patch from his bug report
Michael W. Hudson <mwh@python.net>
parents: 30968
diff changeset
177 w = Py_None;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
178 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
179 PyTuple_SET_ITEM(v, i, w);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
180 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
181 if (itemfailed) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
182 /* do_mkvalue() should have already set an error */
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
183 Py_DECREF(v);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
184 return NULL;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
185 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
186 if (**p_format != endchar) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
187 Py_DECREF(v);
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");
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
190 return NULL;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
191 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
192 if (endchar)
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
193 ++*p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
194 return v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
195 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
196
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
197 static PyObject *
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
198 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
199 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
200 for (;;) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
201 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
202 case '(':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
203 return do_mktuple(p_format, p_va, ')',
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
204 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
205
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
206 case '[':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
207 return do_mklist(p_format, p_va, ']',
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
208 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
209
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
210 case '{':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
211 return do_mkdict(p_format, p_va, '}',
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
212 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
213
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
214 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
215 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
216 case 'h':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
217 case 'i':
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
218 return PyLong_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
219
113d833eea7e Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents: 13330
diff changeset
220 case 'H':
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
221 return PyLong_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
222
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
223 case 'I':
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
224 {
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
225 unsigned int n;
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
226 n = va_arg(*p_va, unsigned int);
44159
af86b89ce784 Eliminate outdated usages of PyInt_GetMax.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
227 return PyLong_FromUnsignedLong(n);
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
228 }
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
229
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
230 case 'n':
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
231 #if SIZEOF_SIZE_T!=SIZEOF_LONG
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
232 return PyLong_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
233 #endif
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36115
diff changeset
234 /* Fall through from 'n' to 'l' if Py_ssize_t is long */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
235 case 'l':
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
236 return PyLong_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
237
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
238 case 'k':
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
239 {
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
240 unsigned long n;
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
241 n = va_arg(*p_va, unsigned long);
44159
af86b89ce784 Eliminate outdated usages of PyInt_GetMax.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
242 return PyLong_FromUnsignedLong(n);
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
243 }
28658
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
244
9949
98e37347378b Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents: 9722
diff changeset
245 #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
246 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
247 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
248
8836529e9e66 dded missing k and K format specifiers to Py_BuildValue and friends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28437
diff changeset
249 case 'K':
35935
7c8800b81c50 bug #1281408: make Py_BuildValue work with unsigned longs and long longs
Georg Brandl <georg@python.org>
parents: 35895
diff changeset
250 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
251 #endif
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
252 case 'u':
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
253 {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
254 PyObject *v;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
255 Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
256 Py_ssize_t n;
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
257 if (**p_format == '#') {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
258 ++*p_format;
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
259 if (flags & FLAG_SIZE_T)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
260 n = va_arg(*p_va, Py_ssize_t);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
261 else
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
262 n = va_arg(*p_va, int);
12520
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
263 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
264 else
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
265 n = -1;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
266 if (u == NULL) {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
267 v = Py_None;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
268 Py_INCREF(v);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
269 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
270 else {
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
271 if (n < 0)
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
272 n = _ustrlen(u);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
273 v = PyUnicode_FromUnicode(u, n);
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
274 }
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
275 return v;
b6b7bd20c845 Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents: 9949
diff changeset
276 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
277 case 'f':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
278 case 'd':
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
279 return PyFloat_FromDouble(
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
280 (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
281
17032
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
282 case 'D':
d5811af8acf3 Py_BuildValue(): Add "D" conversion to create a Python complex value from
Fred Drake <fdrake@acm.org>
parents: 14869
diff changeset
283 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
284 *((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
285
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
286 case 'c':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
287 {
42139
1f7b66a9ffb0 Revert r56044 (which changed the %c format specifier to accept a
Walter Dörwald <walter@livinglogic.de>
parents: 42119
diff changeset
288 char p[1];
1f7b66a9ffb0 Revert r56044 (which changed the %c format specifier to accept a
Walter Dörwald <walter@livinglogic.de>
parents: 42119
diff changeset
289 p[0] = (char)va_arg(*p_va, int);
52781
2df1517d868c Py_BuildValue's 'c' code should use byte strings #5666
Benjamin Peterson <benjamin@python.org>
parents: 48431
diff changeset
290 return PyBytes_FromStringAndSize(p, 1);
42139
1f7b66a9ffb0 Revert r56044 (which changed the %c format specifier to accept a
Walter Dörwald <walter@livinglogic.de>
parents: 42119
diff changeset
291 }
1f7b66a9ffb0 Revert r56044 (which changed the %c format specifier to accept a
Walter Dörwald <walter@livinglogic.de>
parents: 42119
diff changeset
292 case 'C':
1f7b66a9ffb0 Revert r56044 (which changed the %c format specifier to accept a
Walter Dörwald <walter@livinglogic.de>
parents: 42119
diff changeset
293 {
42119
4db0a0cc57ab Change %c format specifier for PyArg_ParseTuple() so that it accepts
Walter Dörwald <walter@livinglogic.de>
parents: 42060
diff changeset
294 int i = va_arg(*p_va, int);
4db0a0cc57ab Change %c format specifier for PyArg_ParseTuple() so that it accepts
Walter Dörwald <walter@livinglogic.de>
parents: 42060
diff changeset
295 if (i < 0 || i > PyUnicode_GetMax()) {
4db0a0cc57ab Change %c format specifier for PyArg_ParseTuple() so that it accepts
Walter Dörwald <walter@livinglogic.de>
parents: 42060
diff changeset
296 PyErr_SetString(PyExc_OverflowError,
48431
f27206101ff9 Correct a typo during previous checkin.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48430
diff changeset
297 "%c arg not in range(0x110000)");
42119
4db0a0cc57ab Change %c format specifier for PyArg_ParseTuple() so that it accepts
Walter Dörwald <walter@livinglogic.de>
parents: 42060
diff changeset
298 return NULL;
4db0a0cc57ab Change %c format specifier for PyArg_ParseTuple() so that it accepts
Walter Dörwald <walter@livinglogic.de>
parents: 42060
diff changeset
299 }
48430
04817793b962 Issue #3280: like chr() already does, the "%c" format now accepts the full unicode range
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47580
diff changeset
300 return PyUnicode_FromOrdinal(i);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
301 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
302
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
303 case 's':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
304 case 'z':
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
305 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
306 PyObject *v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
307 char *str = va_arg(*p_va, char *);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
308 Py_ssize_t n;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
309 if (**p_format == '#') {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
310 ++*p_format;
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
311 if (flags & FLAG_SIZE_T)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
312 n = va_arg(*p_va, Py_ssize_t);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
313 else
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
314 n = va_arg(*p_va, int);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
315 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
316 else
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
317 n = -1;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
318 if (str == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
319 v = Py_None;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
320 Py_INCREF(v);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
321 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
322 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
323 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
324 size_t m = strlen(str);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
325 if (m > PY_SSIZE_T_MAX) {
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12520
diff changeset
326 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
327 "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
328 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
329 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
330 n = (Py_ssize_t)m;
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
331 }
42305
d0719406b2c6 Change Py_BuildValue to generate Unicode objects for
Martin v. Löwis <martin@v.loewis.de>
parents: 42139
diff changeset
332 v = PyUnicode_FromStringAndSize(str, n);
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
333 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
334 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
335 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
336
41766
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
337 case 'U':
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
338 {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
339 PyObject *v;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
340 char *str = va_arg(*p_va, char *);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
341 Py_ssize_t n;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
342 if (**p_format == '#') {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
343 ++*p_format;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
344 if (flags & FLAG_SIZE_T)
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
345 n = va_arg(*p_va, Py_ssize_t);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
346 else
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
347 n = va_arg(*p_va, int);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
348 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
349 else
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
350 n = -1;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
351 if (str == NULL) {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
352 v = Py_None;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
353 Py_INCREF(v);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
354 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
355 else {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
356 if (n < 0) {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
357 size_t m = strlen(str);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
358 if (m > PY_SSIZE_T_MAX) {
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
359 PyErr_SetString(PyExc_OverflowError,
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
360 "string too long for Python string");
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
361 return NULL;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
362 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
363 n = (Py_ssize_t)m;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
364 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
365 v = PyUnicode_FromStringAndSize(str, n);
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
366 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
367 return v;
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
368 }
d6aa7edf217a Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents: 41611
diff changeset
369
41611
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
370 case 'y':
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
371 {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
372 PyObject *v;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
373 char *str = va_arg(*p_va, char *);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
374 Py_ssize_t n;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
375 if (**p_format == '#') {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
376 ++*p_format;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
377 if (flags & FLAG_SIZE_T)
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
378 n = va_arg(*p_va, Py_ssize_t);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
379 else
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
380 n = va_arg(*p_va, int);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
381 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
382 else
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
383 n = -1;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
384 if (str == NULL) {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
385 v = Py_None;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
386 Py_INCREF(v);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
387 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
388 else {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
389 if (n < 0) {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
390 size_t m = strlen(str);
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
391 if (m > PY_SSIZE_T_MAX) {
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
392 PyErr_SetString(PyExc_OverflowError,
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
393 "string too long for Python bytes");
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
394 return NULL;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
395 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
396 n = (Py_ssize_t)m;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
397 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
398 v = PyBytes_FromStringAndSize(str, n);
41611
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
399 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
400 return v;
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
401 }
c48fe4dc34a9 Change UnicodeDecodeError objects so that the 'object' attribute
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
402
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
403 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
404 case 'S':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
405 case 'O':
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
406 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
407 typedef PyObject *(*converter)(void *);
2202
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
408 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
409 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
410 ++*p_format;
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
411 return (*func)(arg);
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
412 }
9894e55468ec support "O&" taking an object constructor a void*
Guido van Rossum <guido@python.org>
parents: 2154
diff changeset
413 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
414 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
415 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
416 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
417 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
418 Py_INCREF(v);
9722
3955f787e9a1 Oops, forgot a pair of {}'s. (Greg Couch)
Guido van Rossum <guido@python.org>
parents: 9720
diff changeset
419 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
420 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
421 /* 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
422 * 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
423 * 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
424 * 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
425 * 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
426 * 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
427 * 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
428 * 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
429 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
430 "NULL object passed to Py_BuildValue");
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
431 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
432 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
433
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
434 case ':':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
435 case ',':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
436 case ' ':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
437 case '\t':
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
438 break;
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 default:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
441 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
442 "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
443 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
444
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
445 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
446 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
447 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
448
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
449
27533
842d6a24497a Style consistency, so "grep ^function ..." works as expected.
Fred Drake <fdrake@acm.org>
parents: 26664
diff changeset
450 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
451 Py_BuildValue(const char *format, ...)
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
452 {
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
453 va_list va;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
454 PyObject* retval;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
455 va_start(va, format);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
456 retval = va_build_value(format, va, 0);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
457 va_end(va);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
458 return retval;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
459 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
460
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
461 PyObject *
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
462 _Py_BuildValue_SizeT(const char *format, ...)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
463 {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
464 va_list va;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
465 PyObject* retval;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
466 va_start(va, format);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
467 retval = va_build_value(format, va, FLAG_SIZE_T);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
468 va_end(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
469 return retval;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
470 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
471
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
472 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
473 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
474 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
475 return va_build_value(format, va, 0);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
476 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
477
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
478 PyObject *
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
479 _Py_VaBuildValue_SizeT(const char *format, va_list va)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
480 {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
481 return va_build_value(format, va, FLAG_SIZE_T);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
482 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
483
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
484 static PyObject *
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
485 va_build_value(const char *format, va_list va, int flags)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
486 {
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
487 const char *f = format;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
488 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
489 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
490
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
491 #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
492 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
493 #else
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
494 #ifdef __va_copy
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
495 __va_copy(lva, va);
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
496 #else
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
497 lva = va;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
498 #endif
24400
81ca6ca5c307 Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 23888
diff changeset
499 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
500
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
501 if (n < 0)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
502 return NULL;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
503 if (n == 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
504 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
505 return Py_None;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
506 }
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
507 if (n == 1)
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
508 return do_mkvalue(&f, &lva, flags);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36858
diff changeset
509 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
510 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
511
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
512
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
513 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
514 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
515 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
516 va_list vargs;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
517 PyObject *args;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
518 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
519
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
520 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
521
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
522 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
523 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
524
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
525 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
526 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
527
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
528 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
529 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
530
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
531 return res;
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
532 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
533
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
534
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
535 PyObject *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
536 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
537 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
538 va_list vargs;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
539 PyObject *meth;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
540 PyObject *args;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
541 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
542
8898
492363d6bc94 # Fix strange type (methonname instead of methodname).
Guido van Rossum <guido@python.org>
parents: 8822
diff changeset
543 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
544 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
545 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
546
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
547 va_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
548
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
549 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
550 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
551
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
552 if (args == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
553 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
554 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
555 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
556
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
557 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
558 Py_DECREF(meth);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
559 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
560
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
561 return res;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1913
diff changeset
562 }
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
563
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
564 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
565 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
566 {
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
567 PyObject *dict;
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
568 if (!PyModule_Check(m)) {
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
569 PyErr_SetString(PyExc_TypeError,
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
570 "PyModule_AddObject() needs module as first arg");
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
571 return -1;
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
572 }
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
573 if (!o) {
30771
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
574 if (!PyErr_Occurred())
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
575 PyErr_SetString(PyExc_TypeError,
a6879d1733d7 Patch #828384: Don't discard nested exception in AddObject.
Martin v. Löwis <martin@v.loewis.de>
parents: 29579
diff changeset
576 "PyModule_AddObject() needs non-NULL value");
29579
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
577 return -1;
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
578 }
60ce73ea9c92 Better error message
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28658
diff changeset
579
23888
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
580 dict = PyModule_GetDict(m);
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
581 if (dict == NULL) {
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
582 /* Internal error -- modules must have a dict! */
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
583 PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
584 PyModule_GetName(m));
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
585 return -1;
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
586 }
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
587 if (PyDict_SetItemString(dict, name, o))
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
588 return -1;
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
589 Py_DECREF(o);
7b66f0034233 PyModule_AddObject(): Added missing exceptions.
Fred Drake <fdrake@acm.org>
parents: 22613
diff changeset
590 return 0;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
591 }
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_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
595 {
44782
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
596 PyObject *o = PyLong_FromLong(value);
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
597 if (!o)
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
598 return -1;
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
599 if (PyModule_AddObject(m, name, o) == 0)
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
600 return 0;
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
601 Py_DECREF(o);
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
602 return -1;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
603 }
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
604
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
605 int
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35935
diff changeset
606 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
607 {
44782
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
608 PyObject *o = PyUnicode_FromString(value);
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
609 if (!o)
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
610 return -1;
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
611 if (PyModule_AddObject(m, name, o) == 0)
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
612 return 0;
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
613 Py_DECREF(o);
ca2683a67943 Merged revisions 60080-60089,60091-60093 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44159
diff changeset
614 return -1;
14781
081671cef7c1 Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents: 14588
diff changeset
615 }