Mercurial > cpython-lru_cache-weakref
annotate Python/getargs.c @ 28571:5fbdcaef9dda legacy-trunk
PyErr_NormalizeException(): in the type==NULL test, we should simply
return. Setting an exception can mess with the exception state, and
continuing is definitely wrong (since type is dereferenced later on).
Some code that calls this seems to be prepared for a NULL exception
type, so let's be safe rather than sorry and simply assume there's
nothing to normalize in this case.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 10 Apr 2003 20:29:48 +0000 |
| parents | 871da703e4c0 |
| children | 28a2975514cd |
| rev | line source |
|---|---|
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* New getargs implementation */ |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
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:
5317
diff
changeset
|
4 #include "Python.h" |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
4102
9569664ac347
Add needed #include <ctype.h>
Guido van Rossum <guido@python.org>
parents:
4026
diff
changeset
|
6 #include <ctype.h> |
|
9569664ac347
Add needed #include <ctype.h>
Guido van Rossum <guido@python.org>
parents:
4026
diff
changeset
|
7 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
9 int PyArg_Parse(PyObject *, char *, ...); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
10 int PyArg_ParseTuple(PyObject *, char *, ...); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
11 int PyArg_VaParse(PyObject *, char *, va_list); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
13 int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
14 char *, char **, ...); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
17 static int vgetargs1(PyObject *, char *, va_list *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
18 static void seterror(int, char *, int *, char *, char *); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
19 static char *convertitem(PyObject *, char **, va_list *, int *, char *, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
20 size_t); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
21 static char *converttuple(PyObject *, char **, va_list *, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
22 int *, char *, size_t, int); |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
23 static char *convertsimple(PyObject *, char **, va_list *, char *, size_t); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
24 static int convertbuffer(PyObject *, void **p, char **); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
26 static int vgetargskeywords(PyObject *, PyObject *, |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
27 char *, char **, va_list *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
28 static char *skipitem(char **, va_list *); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
20629
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
30 int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
31 PyArg_Parse(PyObject *args, char *format, ...) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 int retval; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 va_list va; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 va_start(va, format); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
37 retval = vgetargs1(args, format, &va, 1); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 va_end(va); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 return retval; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
20629
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
43 int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
44 PyArg_ParseTuple(PyObject *args, char *format, ...) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 int retval; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 va_list va; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 va_start(va, format); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
50 retval = vgetargs1(args, format, &va, 0); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 va_end(va); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 return retval; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
57 PyArg_VaParse(PyObject *args, char *format, va_list va) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
59 va_list lva; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
60 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
61 #ifdef VA_LIST_IS_ARRAY |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
62 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:
2004
diff
changeset
|
63 #else |
|
24400
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
22801
diff
changeset
|
64 #ifdef __va_copy |
|
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
22801
diff
changeset
|
65 __va_copy(lva, va); |
|
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
22801
diff
changeset
|
66 #else |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
67 lva = va; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
68 #endif |
|
24400
81ca6ca5c307
Patch #554716: Use __va_copy where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
22801
diff
changeset
|
69 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
70 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2004
diff
changeset
|
71 return vgetargs1(args, format, &lva, 0); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
76 vgetargs1(PyObject *args, char *format, va_list *p_va, int compat) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 char msgbuf[256]; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 int levels[32]; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 char *fname = NULL; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 char *message = NULL; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 int min = -1; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 int max = 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 int level = 0; |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
85 int endfmt = 0; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 char *formatsave = format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 int i, len; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 char *msg; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
16582
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16264
diff
changeset
|
90 assert(compat || (args != (PyObject*)NULL)); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16264
diff
changeset
|
91 |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
92 while (endfmt == 0) { |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 int c = *format++; |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
94 switch (c) { |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
95 case '(': |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 if (level == 0) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 max++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 level++; |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
99 break; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
100 case ')': |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 if (level == 0) |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
102 Py_FatalError("excess ')' in getargs format"); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 else |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 level--; |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
105 break; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
106 case '\0': |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
107 endfmt = 1; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
108 break; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
109 case ':': |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
110 fname = format; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
111 endfmt = 1; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 break; |
|
17997
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
113 case ';': |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
114 message = format; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
115 endfmt = 1; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
116 break; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
117 default: |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
118 if (level == 0) { |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
119 if (c == 'O') |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
120 max++; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
121 else if (isalpha(c)) { |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
122 if (c != 'e') /* skip encoded */ |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
123 max++; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
124 } else if (c == '|') |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
125 min = max; |
|
27f2422ea335
Change cascaded if stmts to switch stmt in vgetargs1().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17996
diff
changeset
|
126 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 break; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 if (level != 0) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
132 Py_FatalError(/* '(' */ "missing ')' in getargs format"); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 if (min < 0) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 min = max; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 format = formatsave; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 if (compat) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 if (max == 0) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 if (args == NULL) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 return 1; |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
143 PyOS_snprintf(msgbuf, sizeof(msgbuf), |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
144 "%.200s%s takes no arguments", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
145 fname==NULL ? "function" : fname, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
146 fname==NULL ? "" : "()"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
147 PyErr_SetString(PyExc_TypeError, msgbuf); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 else if (min == 1 && max == 1) { |
|
2004
7f8719a36662
prevent core dump for old getargs() with NULL arg
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
151 if (args == NULL) { |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
152 PyOS_snprintf(msgbuf, sizeof(msgbuf), |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
153 "%.200s%s takes at least one argument", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
154 fname==NULL ? "function" : fname, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
155 fname==NULL ? "" : "()"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
156 PyErr_SetString(PyExc_TypeError, msgbuf); |
|
2004
7f8719a36662
prevent core dump for old getargs() with NULL arg
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
157 return 0; |
|
7f8719a36662
prevent core dump for old getargs() with NULL arg
Guido van Rossum <guido@python.org>
parents:
1913
diff
changeset
|
158 } |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
159 msg = convertitem(args, &format, p_va, levels, msgbuf, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
160 sizeof(msgbuf)); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 if (msg == NULL) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 return 1; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 seterror(levels[0], msg, levels+1, fname, message); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
167 PyErr_SetString(PyExc_SystemError, |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 "old style getargs format uses new features"); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
173 if (!PyTuple_Check(args)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
174 PyErr_SetString(PyExc_SystemError, |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 "new style getargs format but argument is not a tuple"); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 |
|
17856
2807949e0ba5
vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17817
diff
changeset
|
179 len = PyTuple_GET_SIZE(args); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 if (len < min || max < len) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 if (message == NULL) { |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
183 PyOS_snprintf(msgbuf, sizeof(msgbuf), |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
184 "%.150s%s takes %s %d argument%s " |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
185 "(%d given)", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
186 fname==NULL ? "function" : fname, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
187 fname==NULL ? "" : "()", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
188 min==max ? "exactly" |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
189 : len < min ? "at least" : "at most", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
190 len < min ? min : max, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
191 (len < min ? min : max) == 1 ? "" : "s", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
192 len); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 message = msgbuf; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
195 PyErr_SetString(PyExc_TypeError, message); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 for (i = 0; i < len; i++) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 if (*format == '|') |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 format++; |
|
17856
2807949e0ba5
vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17817
diff
changeset
|
202 msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
203 levels, msgbuf, sizeof(msgbuf)); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 if (msg) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 seterror(i+1, msg, levels, fname, message); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 return 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 } |
|
6805
93e480dedcf0
Add explicit check for correct next character in format at end of
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
209 |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7120
diff
changeset
|
210 if (*format != '\0' && !isalpha((int)(*format)) && |
|
6923
74ad26825060
Oops -- '(' is also a legal start character of a new format...
Guido van Rossum <guido@python.org>
parents:
6805
diff
changeset
|
211 *format != '(' && |
|
6805
93e480dedcf0
Add explicit check for correct next character in format at end of
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
212 *format != '|' && *format != ':' && *format != ';') { |
|
93e480dedcf0
Add explicit check for correct next character in format at end of
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
213 PyErr_Format(PyExc_SystemError, |
|
7120
0efed4d3323b
Protect PyErr_Format format string argument from overflow (ironically,
Guido van Rossum <guido@python.org>
parents:
6923
diff
changeset
|
214 "bad format string: %.200s", formatsave); |
|
6805
93e480dedcf0
Add explicit check for correct next character in format at end of
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
215 return 0; |
|
93e480dedcf0
Add explicit check for correct next character in format at end of
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
216 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 return 1; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
224 seterror(int iarg, char *msg, int *levels, char *fname, char *message) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 { |
|
21066
225c7dd17e37
Fixes for possible buffer overflows in sprintf() usages.
Marc-André Lemburg <mal@egenix.com>
parents:
20723
diff
changeset
|
226 char buf[512]; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 int i; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 char *p = buf; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
230 if (PyErr_Occurred()) |
|
2210
e734c7235727
don't overwrite error already set (e.g. from O&)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
231 return; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 else if (message == NULL) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 if (fname != NULL) { |
|
21092
53270d281bf0
Use PyOS_snprintf() at some cost even though it was correct before.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21074
diff
changeset
|
234 PyOS_snprintf(p, sizeof(buf), "%.200s() ", fname); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 p += strlen(p); |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 } |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
237 if (iarg != 0) { |
|
21145
87fa6e9bd77e
mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
Tim Peters <tim.peters@gmail.com>
parents:
21100
diff
changeset
|
238 PyOS_snprintf(p, sizeof(buf) - (p - buf), |
|
21092
53270d281bf0
Use PyOS_snprintf() at some cost even though it was correct before.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21074
diff
changeset
|
239 "argument %d", iarg); |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
240 i = 0; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 p += strlen(p); |
|
21066
225c7dd17e37
Fixes for possible buffer overflows in sprintf() usages.
Marc-André Lemburg <mal@egenix.com>
parents:
20723
diff
changeset
|
242 while (levels[i] > 0 && (int)(p-buf) < 220) { |
|
21092
53270d281bf0
Use PyOS_snprintf() at some cost even though it was correct before.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21074
diff
changeset
|
243 PyOS_snprintf(p, sizeof(buf) - (buf - p), |
|
53270d281bf0
Use PyOS_snprintf() at some cost even though it was correct before.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21074
diff
changeset
|
244 ", item %d", levels[i]-1); |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
245 p += strlen(p); |
|
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
246 i++; |
|
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
247 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 } |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
249 else { |
|
21145
87fa6e9bd77e
mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
Tim Peters <tim.peters@gmail.com>
parents:
21100
diff
changeset
|
250 PyOS_snprintf(p, sizeof(buf) - (p - buf), "argument"); |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
251 p += strlen(p); |
|
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
252 } |
|
21145
87fa6e9bd77e
mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
Tim Peters <tim.peters@gmail.com>
parents:
21100
diff
changeset
|
253 PyOS_snprintf(p, sizeof(buf) - (p - buf), " %.256s", msg); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 message = buf; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
256 PyErr_SetString(PyExc_TypeError, message); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 /* Convert a tuple argument. |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 On entry, *p_format points to the character _after_ the opening '('. |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 On successful exit, *p_format points to the closing ')'. |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 If successful: |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 *p_format and *p_va are updated, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 *levels and *msgbuf are untouched, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 and NULL is returned. |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 If the argument is invalid: |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 *p_format is unchanged, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 *p_va is undefined, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 *levels is a 0-terminated list of item numbers, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 *msgbuf contains an error message, whose format is: |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
272 "must be <typename1>, not <typename2>", where: |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 <typename1> is the name of the expected type, and |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 <typename2> is the name of the actual type, |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 and msgbuf is returned. |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 */ |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
279 converttuple(PyObject *arg, char **p_format, va_list *p_va, int *levels, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
280 char *msgbuf, size_t bufsize, int toplevel) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 int level = 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 int n = 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 char *format = *p_format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 int i; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 for (;;) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 int c = *format++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 if (c == '(') { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 if (level == 0) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 n++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 level++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 else if (c == ')') { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 if (level == 0) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 break; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 level--; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 else if (c == ':' || c == ';' || c == '\0') |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 break; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 else if (level == 0 && isalpha(c)) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 n++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
305 if (!PySequence_Check(arg) || PyString_Check(arg)) { |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 levels[0] = 0; |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
307 PyOS_snprintf(msgbuf, bufsize, |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
308 toplevel ? "expected %d arguments, not %.50s" : |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
309 "must be %d-item sequence, not %.50s", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
310 n, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
311 arg == Py_None ? "None" : arg->ob_type->tp_name); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 return msgbuf; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13447
diff
changeset
|
315 if ((i = PySequence_Size(arg)) != n) { |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 levels[0] = 0; |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
317 PyOS_snprintf(msgbuf, bufsize, |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
318 toplevel ? "expected %d arguments, not %d" : |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
319 "must be sequence of length %d, not %d", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
320 n, i); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 return msgbuf; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 } |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
323 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 format = *p_format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 for (i = 0; i < n; i++) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 char *msg; |
|
10220
0ef1071cb7fe
Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
Guido van Rossum <guido@python.org>
parents:
9949
diff
changeset
|
327 PyObject *item; |
|
0ef1071cb7fe
Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
Guido van Rossum <guido@python.org>
parents:
9949
diff
changeset
|
328 item = PySequence_GetItem(arg, i); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
329 msg = convertitem(item, &format, p_va, levels+1, msgbuf, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
330 bufsize); |
|
10220
0ef1071cb7fe
Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
Guido van Rossum <guido@python.org>
parents:
9949
diff
changeset
|
331 /* PySequence_GetItem calls tp->sq_item, which INCREFs */ |
|
0ef1071cb7fe
Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
Guido van Rossum <guido@python.org>
parents:
9949
diff
changeset
|
332 Py_XDECREF(item); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 if (msg != NULL) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 levels[0] = i+1; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 return msg; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 } |
|
15899
152814f6cd11
This patch makes sure that the function name always appears in the error
Ka-Ping Yee <ping@zesty.ca>
parents:
15502
diff
changeset
|
338 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 *p_format = format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 return NULL; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 /* Convert a single item. */ |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
347 convertitem(PyObject *arg, char **p_format, va_list *p_va, int *levels, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
348 char *msgbuf, size_t bufsize) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 char *msg; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 char *format = *p_format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 if (*format == '(' /* ')' */) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 format++; |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
355 msg = converttuple(arg, &format, p_va, levels, msgbuf, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
356 bufsize, 0); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 if (msg == NULL) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 format++; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 else { |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
361 msg = convertsimple(arg, &format, p_va, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 if (msg != NULL) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 levels[0] = 0; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 if (msg == NULL) |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 *p_format = format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 return msg; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
372 #define UNICODE_DEFAULT_ENCODING(arg) \ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
373 _PyUnicode_AsDefaultEncodedString(arg, NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
374 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
375 /* Format an error message generated by convertsimple(). */ |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 static char * |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
378 converterr(char *expected, PyObject *arg, char *msgbuf, size_t bufsize) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
379 { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
380 assert(expected != NULL); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
381 assert(arg != NULL); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
382 PyOS_snprintf(msgbuf, bufsize, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
383 "must be %.50s, not %.50s", expected, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
384 arg == Py_None ? "None" : arg->ob_type->tp_name); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
385 return msgbuf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
386 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
387 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
388 #define CONV_UNICODE "(unicode conversion error)" |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
389 |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
390 /* explicitly check for float arguments when integers are expected. For now |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
391 * signal a warning. Returns true if an exception was raised. */ |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
392 static int |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
393 float_argument_error(PyObject *arg) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
394 { |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
395 if (PyFloat_Check(arg) && |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
396 PyErr_Warn(PyExc_DeprecationWarning, |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
397 "integer argument expected, got float" )) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
398 return 1; |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
399 else |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
400 return 0; |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
401 } |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
402 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
403 /* Convert a non-tuple argument. Return NULL if conversion went OK, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
404 or a string with a message describing the failure. The message is |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
405 formatted as "must be <desired type>, not <actual type>". |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
406 When failing, an exception may or may not have been raised. |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
407 Don't call if a tuple is expected. |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
408 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
409 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
410 static char * |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
411 convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
412 size_t bufsize) |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 char *format = *p_format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 char c = *format++; |
|
26321
680360e68a06
Wrap uargs declaration in a #ifdef Py_USING_UNICODE, so that
Walter Dörwald <walter@livinglogic.de>
parents:
24400
diff
changeset
|
416 #ifdef Py_USING_UNICODE |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
417 PyObject *uarg; |
|
26321
680360e68a06
Wrap uargs declaration in a #ifdef Py_USING_UNICODE, so that
Walter Dörwald <walter@livinglogic.de>
parents:
24400
diff
changeset
|
418 #endif |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 switch (c) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
422 case 'b': { /* unsigned byte -- very short int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
423 char *p = va_arg(*p_va, char *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
424 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
425 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
426 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
427 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
428 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
429 return converterr("integer<b>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
430 else if (ival < 0) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
431 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
432 "unsigned byte integer is less than minimum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
433 return converterr("integer<b>", arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
435 else if (ival > UCHAR_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
436 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
437 "unsigned byte integer is greater than maximum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
438 return converterr("integer<b>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
439 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
440 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
441 *p = (unsigned char) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
442 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
443 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
445 case 'B': {/* byte sized bitfield - both signed and unsigned |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
446 values allowed */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
447 char *p = va_arg(*p_va, char *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
448 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
449 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
450 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
451 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
452 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
453 return converterr("integer<b>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
454 else if (ival < SCHAR_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
455 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
456 "byte-sized integer bitfield is less than minimum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
457 return converterr("integer<B>", arg, msgbuf, bufsize); |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
458 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
459 else if (ival > (int)UCHAR_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
460 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
461 "byte-sized integer bitfield is greater than maximum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
462 return converterr("integer<B>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
463 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
464 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
465 *p = (unsigned char) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
466 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
467 } |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
468 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
469 case 'h': {/* signed short int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
470 short *p = va_arg(*p_va, short *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
471 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
472 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
473 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
474 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
475 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
476 return converterr("integer<h>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
477 else if (ival < SHRT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
478 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
479 "signed short integer is less than minimum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
480 return converterr("integer<h>", arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
482 else if (ival > SHRT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
483 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
484 "signed short integer is greater than maximum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
485 return converterr("integer<h>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
486 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
487 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
488 *p = (short) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
489 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
490 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
492 case 'H': { /* short int sized bitfield, both signed and |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
493 unsigned allowed */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
494 unsigned short *p = va_arg(*p_va, unsigned short *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
495 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
496 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
497 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
498 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
499 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
500 return converterr("integer<H>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
501 else if (ival < SHRT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
502 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
503 "short integer bitfield is less than minimum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
504 return converterr("integer<H>", arg, msgbuf, bufsize); |
|
13378
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
505 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
506 else if (ival > USHRT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
507 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
508 "short integer bitfield is greater than maximum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
509 return converterr("integer<H>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
510 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
511 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
512 *p = (unsigned short) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
513 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
514 } |
|
13378
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
515 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
516 case 'i': {/* signed int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
517 int *p = va_arg(*p_va, int *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
518 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
519 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
520 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
521 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
522 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
523 return converterr("integer<i>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
524 else if (ival > INT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
525 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
526 "signed integer is greater than maximum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
527 return converterr("integer<i>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
528 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
529 else if (ival < INT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
530 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
531 "signed integer is less than minimum"); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
532 return converterr("integer<i>", arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
534 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
535 *p = ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
536 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
537 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
538 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
539 case 'l': {/* long int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
540 long *p = va_arg(*p_va, long *); |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
541 long ival; |
|
27685
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
542 if (float_argument_error(arg)) |
|
9e47f9ed49f6
If a float is passed where a int is expected, issue a DeprecationWarning
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
27363
diff
changeset
|
543 return NULL; |
|
27363
eb1e529fdfdf
Raise a TypeError if a float is passed when an integer is specified.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
26321
diff
changeset
|
544 ival = PyInt_AsLong(arg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
545 if (ival == -1 && PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
546 return converterr("integer<l>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
547 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
548 *p = ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
549 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
550 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
551 |
|
9949
98e37347378b
Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents:
9306
diff
changeset
|
552 #ifdef HAVE_LONG_LONG |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
553 case 'L': {/* PY_LONG_LONG */ |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
554 PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * ); |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
555 PY_LONG_LONG ival = PyLong_AsLongLong( arg ); |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
556 if( ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) { |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
557 return converterr("long<L>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
558 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
559 *p = ival; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
560 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
561 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
562 } |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
563 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
564 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
565 case 'f': {/* float */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
566 float *p = va_arg(*p_va, float *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
567 double dval = PyFloat_AsDouble(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
568 if (PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
569 return converterr("float<f>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
570 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
571 *p = (float) dval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
572 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
573 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
574 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
575 case 'd': {/* double */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
576 double *p = va_arg(*p_va, double *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
577 double dval = PyFloat_AsDouble(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
578 if (PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
579 return converterr("float<d>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
580 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
581 *p = dval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
582 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
583 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3323
diff
changeset
|
585 #ifndef WITHOUT_COMPLEX |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
586 case 'D': {/* complex double */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
587 Py_complex *p = va_arg(*p_va, Py_complex *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
588 Py_complex cval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
589 cval = PyComplex_AsCComplex(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
590 if (PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
591 return converterr("complex<D>", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
592 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
593 *p = cval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
594 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
595 } |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3323
diff
changeset
|
596 #endif /* WITHOUT_COMPLEX */ |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2210
diff
changeset
|
597 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
598 case 'c': {/* char */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
599 char *p = va_arg(*p_va, char *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
600 if (PyString_Check(arg) && PyString_Size(arg) == 1) |
|
20357
92d56ae63ed3
One more place where PyString_AsString() was used after a
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20356
diff
changeset
|
601 *p = PyString_AS_STRING(arg)[0]; |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
602 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
603 return converterr("char", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
604 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
605 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
607 case 's': {/* string */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
608 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
609 void **p = (void **)va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
610 int *q = va_arg(*p_va, int *); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
611 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
612 if (PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
613 *p = PyString_AS_STRING(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
614 *q = PyString_GET_SIZE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
615 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
616 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
617 else if (PyUnicode_Check(arg)) { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
618 uarg = UNICODE_DEFAULT_ENCODING(arg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
619 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
620 return converterr(CONV_UNICODE, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
621 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
622 *p = PyString_AS_STRING(uarg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
623 *q = PyString_GET_SIZE(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
624 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
625 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
626 else { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
627 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
628 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
629 if (count < 0) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
630 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
631 *q = count; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
633 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
634 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
635 char **p = va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
636 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
637 if (PyString_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
638 *p = PyString_AS_STRING(arg); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
639 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
640 else if (PyUnicode_Check(arg)) { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
641 uarg = UNICODE_DEFAULT_ENCODING(arg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
642 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
643 return converterr(CONV_UNICODE, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
644 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
645 *p = PyString_AS_STRING(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
646 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
647 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
648 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
649 return converterr("string", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
650 if ((int)strlen(*p) != PyString_Size(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
651 return converterr("string without null bytes", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
652 arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
653 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
654 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
655 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
656 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
657 case 'z': {/* string, may be NULL (None) */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
658 if (*format == '#') { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
659 void **p = (void **)va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
660 int *q = va_arg(*p_va, int *); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
661 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
662 if (arg == Py_None) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
663 *p = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
664 *q = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
665 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
666 else if (PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
667 *p = PyString_AS_STRING(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
668 *q = PyString_GET_SIZE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
669 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
670 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
671 else if (PyUnicode_Check(arg)) { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
672 uarg = UNICODE_DEFAULT_ENCODING(arg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
673 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
674 return converterr(CONV_UNICODE, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
675 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
676 *p = PyString_AS_STRING(uarg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
677 *q = PyString_GET_SIZE(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
678 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
679 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
680 else { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
681 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
682 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
683 if (count < 0) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
684 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
685 *q = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
686 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
687 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
688 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
689 char **p = va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
690 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
691 if (arg == Py_None) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
692 *p = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
693 else if (PyString_Check(arg)) |
|
20356
c0d662966272
Use AS_STRING() following the check and avoid an extra call.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19820
diff
changeset
|
694 *p = PyString_AS_STRING(arg); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
695 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
696 else if (PyUnicode_Check(arg)) { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
697 uarg = UNICODE_DEFAULT_ENCODING(arg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
698 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
699 return converterr(CONV_UNICODE, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
700 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
701 *p = PyString_AS_STRING(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
702 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
703 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
704 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
705 return converterr("string or None", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
706 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
707 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
708 int *q = va_arg(*p_va, int *); |
| 12612 | 709 if (arg == Py_None) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
710 *q = 0; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
711 else |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
712 *q = PyString_Size(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
713 format++; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
715 else if (*p != NULL && |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
716 (int)strlen(*p) != PyString_Size(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
717 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
718 "string without null bytes or None", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
719 arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
721 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
722 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
724 case 'e': {/* encoded string */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
725 char **buffer; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
726 const char *encoding; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
727 PyObject *s; |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
728 int size, recode_strings; |
| 12051 | 729 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
730 /* Get 'e' parameter: the encoding name */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
731 encoding = (const char *)va_arg(*p_va, const char *); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
732 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
733 if (encoding == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
734 encoding = PyUnicode_GetDefaultEncoding(); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
735 #endif |
| 12051 | 736 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
737 /* Get output buffer parameter: |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
738 's' (recode all objects via Unicode) or |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
739 't' (only recode non-string objects) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
740 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
741 if (*format == 's') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
742 recode_strings = 1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
743 else if (*format == 't') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
744 recode_strings = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
745 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
746 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
747 "(unknown parser marker combination)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
748 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
749 buffer = (char **)va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
750 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
751 if (buffer == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
752 return converterr("(buffer is NULL)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
753 arg, msgbuf, bufsize); |
| 12051 | 754 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
755 /* Encode object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
756 if (!recode_strings && PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
757 s = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
758 Py_INCREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
759 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
760 else { |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
761 #ifdef Py_USING_UNICODE |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
762 PyObject *u; |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
763 |
| 12051 | 764 /* Convert object to Unicode */ |
| 765 u = PyUnicode_FromObject(arg); | |
| 766 if (u == NULL) | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
767 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
768 "string or unicode or text buffer", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
769 arg, msgbuf, bufsize); |
| 12051 | 770 |
| 771 /* Encode object; use default error handling */ | |
| 772 s = PyUnicode_AsEncodedString(u, | |
| 773 encoding, | |
| 774 NULL); | |
| 775 Py_DECREF(u); | |
| 776 if (s == NULL) | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
777 return converterr("(encoding failed)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
778 arg, msgbuf, bufsize); |
| 12051 | 779 if (!PyString_Check(s)) { |
| 780 Py_DECREF(s); | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
781 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
782 "(encoder failed to return a string)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
783 arg, msgbuf, bufsize); |
| 12051 | 784 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
785 #else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
786 return converterr("string<e>", arg, msgbuf, bufsize); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
787 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
788 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
789 size = PyString_GET_SIZE(s); |
| 12051 | 790 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
791 /* Write output; output is guaranteed to be 0-terminated */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
792 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
793 /* Using buffer length parameter '#': |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
794 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
795 - if *buffer is NULL, a new buffer of the |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
796 needed size is allocated and the data |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
797 copied into it; *buffer is updated to point |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
798 to the new buffer; the caller is |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
799 responsible for PyMem_Free()ing it after |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
800 usage |
| 12051 | 801 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
802 - if *buffer is not NULL, the data is |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
803 copied to *buffer; *buffer_len has to be |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
804 set to the size of the buffer on input; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
805 buffer overflow is signalled with an error; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
806 buffer has to provide enough room for the |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
807 encoded string plus the trailing 0-byte |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
808 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
809 - in both cases, *buffer_len is updated to |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
810 the size of the buffer /excluding/ the |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
811 trailing 0-byte |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
812 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
813 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
814 int *buffer_len = va_arg(*p_va, int *); |
| 12051 | 815 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
816 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
817 if (buffer_len == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
818 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
819 "(buffer_len is NULL)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
820 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
821 if (*buffer == NULL) { |
| 12051 | 822 *buffer = PyMem_NEW(char, size + 1); |
| 823 if (*buffer == NULL) { | |
| 824 Py_DECREF(s); | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
825 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
826 "(memory error)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
827 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
828 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
829 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
830 if (size + 1 > *buffer_len) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
831 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
832 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
833 "(buffer overflow)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
834 arg, msgbuf, bufsize); |
| 12051 | 835 } |
| 836 } | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
837 memcpy(*buffer, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
838 PyString_AS_STRING(s), |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
839 size + 1); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
840 *buffer_len = size; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
841 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
842 /* Using a 0-terminated buffer: |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
843 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
844 - the encoded string has to be 0-terminated |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
845 for this variant to work; if it is not, an |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
846 error raised |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
847 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
848 - a new buffer of the needed size is |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
849 allocated and the data copied into it; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
850 *buffer is updated to point to the new |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
851 buffer; the caller is responsible for |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
852 PyMem_Free()ing it after usage |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
853 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
854 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
855 if ((int)strlen(PyString_AS_STRING(s)) != size) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
856 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
857 "(encoded string without NULL bytes)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
858 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
859 *buffer = PyMem_NEW(char, size + 1); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
860 if (*buffer == NULL) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
861 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
862 return converterr("(memory error)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
863 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
864 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
865 memcpy(*buffer, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
866 PyString_AS_STRING(s), |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
867 size + 1); |
| 12051 | 868 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
869 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
870 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
871 } |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
872 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
873 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
874 case 'u': {/* raw unicode buffer (Py_UNICODE *) */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
875 if (*format == '#') { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
876 void **p = (void **)va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
877 int *q = va_arg(*p_va, int *); |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
878 if (PyUnicode_Check(arg)) { |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
879 *p = PyUnicode_AS_UNICODE(arg); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
880 *q = PyUnicode_GET_SIZE(arg); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
881 } |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
882 else { |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
883 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
884 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
885 if (count < 0) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
886 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
887 *q = count/(sizeof(Py_UNICODE)); |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
888 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
889 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
890 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
891 Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
892 if (PyUnicode_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
893 *p = PyUnicode_AS_UNICODE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
894 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
895 return converterr("unicode", arg, msgbuf, bufsize); |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
896 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
897 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
898 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
899 #endif |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
900 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
901 case 'S': { /* string object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
902 PyObject **p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
903 if (PyString_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
904 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
905 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
906 return converterr("string", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
907 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
908 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
910 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
911 case 'U': { /* Unicode object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
912 PyObject **p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
913 if (PyUnicode_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
914 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
915 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
916 return converterr("unicode", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
917 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
918 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
919 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
920 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
921 case 'O': { /* object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
922 PyTypeObject *type; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
923 PyObject **p; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
924 if (*format == '!') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
925 type = va_arg(*p_va, PyTypeObject*); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
926 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
927 format++; |
|
19533
3e7897822459
The "O!" format code should implement an isinstance() test
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
928 if (PyType_IsSubtype(arg->ob_type, type)) |
|
11975
876f35828e87
Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode
Guido van Rossum <guido@python.org>
parents:
10220
diff
changeset
|
929 *p = arg; |
|
876f35828e87
Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode
Guido van Rossum <guido@python.org>
parents:
10220
diff
changeset
|
930 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
931 return converterr(type->tp_name, arg, msgbuf, bufsize); |
|
8358
da4bdceeaad7
Another veeeeeery old patch...
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
932 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
933 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
934 else if (*format == '?') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
935 inquiry pred = va_arg(*p_va, inquiry); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
936 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
937 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
938 if ((*pred)(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
939 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
940 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
941 return converterr("(unspecified)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
942 arg, msgbuf, bufsize); |
|
8358
da4bdceeaad7
Another veeeeeery old patch...
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
943 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
944 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
945 else if (*format == '&') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
946 typedef int (*converter)(PyObject *, void *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
947 converter convert = va_arg(*p_va, converter); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
948 void *addr = va_arg(*p_va, void *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
949 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
950 if (! (*convert)(arg, addr)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
951 return converterr("(unspecified)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
952 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
953 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
954 else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
955 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
956 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
957 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
958 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
959 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
960 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
961 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
962 case 'w': { /* memory buffer, read-write access */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
963 void **p = va_arg(*p_va, void **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
964 PyBufferProcs *pb = arg->ob_type->tp_as_buffer; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
965 int count; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
966 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
967 if (pb == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
968 pb->bf_getwritebuffer == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
969 pb->bf_getsegcount == NULL) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
970 return converterr("read-write buffer", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
971 if ((*pb->bf_getsegcount)(arg, NULL) != 1) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
972 return converterr("single-segment read-write buffer", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
973 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
974 if ((count = pb->bf_getwritebuffer(arg, 0, p)) < 0) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
975 return converterr("(unspecified)", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
976 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
977 int *q = va_arg(*p_va, int *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
978 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
979 *q = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
980 format++; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
981 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
982 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
983 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
984 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
985 case 't': { /* 8-bit character buffer, read-only access */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
986 const char **p = va_arg(*p_va, const char **); |
|
20371
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
987 PyBufferProcs *pb = arg->ob_type->tp_as_buffer; |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
988 int count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
989 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
990 if (*format++ != '#') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
991 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
992 "invalid use of 't' format character", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
993 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
994 if (!PyType_HasFeature(arg->ob_type, |
|
20371
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
995 Py_TPFLAGS_HAVE_GETCHARBUFFER) || |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
996 pb == NULL || pb->bf_getcharbuffer == NULL || |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
997 pb->bf_getsegcount == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
998 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
999 "string or read-only character buffer", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1000 arg, msgbuf, bufsize); |
|
9306
79439e4e9976
Implement new format character 't#'. This is like s#, accepting an
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
1001 |
|
20371
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
1002 if (pb->bf_getsegcount(arg, NULL) != 1) |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
1003 return converterr( |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
1004 "string or single-segment read-only buffer", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1005 arg, msgbuf, bufsize); |
|
20371
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
1006 |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
1007 count = pb->bf_getcharbuffer(arg, 0, p); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1008 if (count < 0) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1009 return converterr("(unspecified)", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1010 *va_arg(*p_va, int *) = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1011 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1012 } |
|
9306
79439e4e9976
Implement new format character 't#'. This is like s#, accepting an
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
1013 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1014 default: |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1015 return converterr("impossible<bad format char>", arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1016 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1017 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1018 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1019 *p_format = format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1020 return NULL; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1021 } |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1022 |
|
20629
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1023 static int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1024 convertbuffer(PyObject *arg, void **p, char **errmsg) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1025 { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1026 PyBufferProcs *pb = arg->ob_type->tp_as_buffer; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1027 int count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1028 if (pb == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1029 pb->bf_getreadbuffer == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1030 pb->bf_getsegcount == NULL) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1031 *errmsg = "string or read-only buffer"; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1032 return -1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1033 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1034 if ((*pb->bf_getsegcount)(arg, NULL) != 1) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1035 *errmsg = "string or single-segment read-only buffer"; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1036 return -1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1037 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1038 if ((count = (*pb->bf_getreadbuffer)(arg, 0, p)) < 0) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1039 *errmsg = "(unspecified)"; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1040 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1041 return count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1042 } |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1043 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1044 /* Support for keyword arguments donated by |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1045 Geoff Philbrick <philbric@delphi.hks.com> */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1046 |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1047 /* Return false (0) for error, else true. */ |
|
20629
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1048 int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1049 PyArg_ParseTupleAndKeywords(PyObject *args, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1050 PyObject *keywords, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1051 char *format, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1052 char **kwlist, ...) |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1053 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1054 int retval; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1055 va_list va; |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1056 |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1057 if ((args == NULL || !PyTuple_Check(args)) || |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1058 (keywords != NULL && !PyDict_Check(keywords)) || |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1059 format == NULL || |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1060 kwlist == NULL) |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1061 { |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1062 PyErr_BadInternalCall(); |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1063 return 0; |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1064 } |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1065 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1066 va_start(va, kwlist); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1067 retval = vgetargskeywords(args, keywords, format, kwlist, &va); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1068 va_end(va); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1069 return retval; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1070 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1071 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1072 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1073 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1074 vgetargskeywords(PyObject *args, PyObject *keywords, char *format, |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1075 char **kwlist, va_list *p_va) |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1076 { |
|
20721
acb854b897bb
vgetargskeywords: Prevent another potential sprintf buffer overrun.
Tim Peters <tim.peters@gmail.com>
parents:
20720
diff
changeset
|
1077 char msgbuf[512]; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1078 int levels[32]; |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1079 char *fname, *message; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1080 int min, max; |
| 20713 | 1081 char *formatsave; |
|
20722
676f106a5002
vgetargskeywords: Now that it's clear that nkwlist must equal max, and
Tim Peters <tim.peters@gmail.com>
parents:
20721
diff
changeset
|
1082 int i, len, nargs, nkeywords; |
| 20723 | 1083 char *msg, **p; |
|
20708
e912b683ed3e
vgetargskeywords(): remove test that can't succeed. Not a bugfix, just
Tim Peters <tim.peters@gmail.com>
parents:
20632
diff
changeset
|
1084 |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1085 assert(args != NULL && PyTuple_Check(args)); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1086 assert(keywords == NULL || PyDict_Check(keywords)); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1087 assert(format != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1088 assert(kwlist != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1089 assert(p_va != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1090 |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1091 /* Search the format: |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1092 message <- error msg, if any (else NULL). |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1093 fname <- routine name, if any (else NULL). |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1094 min <- # of required arguments, or -1 if all are required. |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1095 max <- most arguments (required + optional). |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1096 Check that kwlist has a non-NULL entry for each arg. |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1097 Raise error if a tuple arg spec is found. |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1098 */ |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1099 fname = message = NULL; |
| 20713 | 1100 formatsave = format; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1101 p = kwlist; |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1102 min = -1; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1103 max = 0; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1104 while ((i = *format++) != '\0') { |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1105 if (isalpha(i) && i != 'e') { |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1106 max++; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1107 if (*p == NULL) { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1108 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1109 "more argument specifiers than " |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1110 "keyword list entries"); |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1111 return 0; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1112 } |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1113 p++; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1114 } |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1115 else if (i == '|') |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1116 min = max; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1117 else if (i == ':') { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1118 fname = format; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1119 break; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1120 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1121 else if (i == ';') { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1122 message = format; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1123 break; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1124 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1125 else if (i == '(') { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1126 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1127 "tuple found in format when using keyword " |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1128 "arguments"); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1129 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1130 } |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1131 } |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1132 format = formatsave; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1133 if (*p != NULL) { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1134 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1135 "more keyword list entries than " |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1136 "argument specifiers"); |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1137 return 0; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1138 } |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1139 if (min < 0) { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1140 /* All arguments are required. */ |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1141 min = max; |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1142 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1143 |
| 20713 | 1144 nargs = PyTuple_GET_SIZE(args); |
| 20714 | 1145 nkeywords = keywords == NULL ? 0 : PyDict_Size(keywords); |
|
20708
e912b683ed3e
vgetargskeywords(): remove test that can't succeed. Not a bugfix, just
Tim Peters <tim.peters@gmail.com>
parents:
20632
diff
changeset
|
1146 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1147 /* make sure there are no duplicate values for an argument; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1148 its not clear when to use the term "keyword argument vs. |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1149 keyword parameter in messages */ |
| 20715 | 1150 if (nkeywords > 0) { |
| 20713 | 1151 for (i = 0; i < nargs; i++) { |
|
20709
310450e74f2f
tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
Tim Peters <tim.peters@gmail.com>
parents:
20708
diff
changeset
|
1152 char *thiskw = kwlist[i]; |
|
310450e74f2f
tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
Tim Peters <tim.peters@gmail.com>
parents:
20708
diff
changeset
|
1153 if (thiskw == NULL) |
|
310450e74f2f
tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
Tim Peters <tim.peters@gmail.com>
parents:
20708
diff
changeset
|
1154 break; |
|
20717
84715d52d954
vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
Tim Peters <tim.peters@gmail.com>
parents:
20716
diff
changeset
|
1155 if (PyDict_GetItemString(keywords, thiskw)) { |
| 20715 | 1156 PyErr_Format(PyExc_TypeError, |
| 1157 "keyword parameter '%s' was given " | |
| 1158 "by position and by name", | |
|
20709
310450e74f2f
tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
Tim Peters <tim.peters@gmail.com>
parents:
20708
diff
changeset
|
1159 thiskw); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1160 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1161 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1162 else if (PyErr_Occurred()) |
|
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1163 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1164 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1165 } |
|
20716
dcf769c12d8b
vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.
Tim Peters <tim.peters@gmail.com>
parents:
20715
diff
changeset
|
1166 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1167 /* required arguments missing from args can be supplied by keyword |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1168 arguments; set len to the number of posiitional arguments, and, |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1169 if that's less than the minimum required, add in the number of |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1170 required arguments that are supplied by keywords */ |
| 20713 | 1171 len = nargs; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1172 if (nkeywords > 0 && nargs < min) { |
| 20713 | 1173 for (i = nargs; i < min; i++) { |
|
20717
84715d52d954
vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
Tim Peters <tim.peters@gmail.com>
parents:
20716
diff
changeset
|
1174 if (PyDict_GetItemString(keywords, kwlist[i])) |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1175 len++; |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1176 else if (PyErr_Occurred()) |
|
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1177 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1178 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1179 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1180 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1181 /* make sure we got an acceptable number of arguments; the message |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1182 is a little confusing with keywords since keyword arguments |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1183 which are supplied, but don't match the required arguments |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1184 are not included in the "%d given" part of the message */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1185 if (len < min || max < len) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1186 if (message == NULL) { |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1187 PyOS_snprintf(msgbuf, sizeof(msgbuf), |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1188 "%.200s%s takes %s %d argument%s " |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1189 "(%d given)", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1190 fname==NULL ? "function" : fname, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1191 fname==NULL ? "" : "()", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1192 min==max ? "exactly" |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1193 : len < min ? "at least" : "at most", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1194 len < min ? min : max, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1195 (len < min ? min : max) == 1 ? "" : "s", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1196 len); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1197 message = msgbuf; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1198 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1199 PyErr_SetString(PyExc_TypeError, message); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1200 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1201 } |
| 20723 | 1202 |
| 1203 /* convert the positional arguments */ | |
| 20713 | 1204 for (i = 0; i < nargs; i++) { |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1205 if (*format == '|') |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1206 format++; |
|
17856
2807949e0ba5
vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17817
diff
changeset
|
1207 msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1208 levels, msgbuf, sizeof(msgbuf)); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1209 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1210 seterror(i+1, msg, levels, fname, message); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1211 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1212 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1213 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1214 |
| 20723 | 1215 /* handle no keyword parameters in call */ |
| 20715 | 1216 if (nkeywords == 0) |
| 20712 | 1217 return 1; |
| 20715 | 1218 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1219 /* convert the keyword arguments; this uses the format |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1220 string where it was left after processing args */ |
|
20722
676f106a5002
vgetargskeywords: Now that it's clear that nkwlist must equal max, and
Tim Peters <tim.peters@gmail.com>
parents:
20721
diff
changeset
|
1221 for (i = nargs; i < max; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1222 PyObject *item; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1223 if (*format == '|') |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1224 format++; |
|
20717
84715d52d954
vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
Tim Peters <tim.peters@gmail.com>
parents:
20716
diff
changeset
|
1225 item = PyDict_GetItemString(keywords, kwlist[i]); |
| 4596 | 1226 if (item != NULL) { |
|
20717
84715d52d954
vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
Tim Peters <tim.peters@gmail.com>
parents:
20716
diff
changeset
|
1227 Py_INCREF(item); |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1228 msg = convertitem(item, &format, p_va, levels, msgbuf, |
|
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
1229 sizeof(msgbuf)); |
|
20717
84715d52d954
vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
Tim Peters <tim.peters@gmail.com>
parents:
20716
diff
changeset
|
1230 Py_DECREF(item); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1231 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1232 seterror(i+1, msg, levels, fname, message); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1233 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1234 } |
| 20723 | 1235 --nkeywords; |
| 1236 if (nkeywords == 0) | |
| 1237 break; | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1238 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1239 else if (PyErr_Occurred()) |
|
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1240 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1241 else { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1242 msg = skipitem(&format, p_va); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1243 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1244 seterror(i+1, msg, levels, fname, message); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1245 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1246 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1247 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1248 } |
| 20715 | 1249 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1250 /* make sure there are no extraneous keyword arguments */ |
| 20723 | 1251 if (nkeywords > 0) { |
| 1252 PyObject *key, *value; | |
| 1253 int pos = 0; | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1254 while (PyDict_Next(keywords, &pos, &key, &value)) { |
| 20723 | 1255 int match = 0; |
|
22801
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1256 char *ks; |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1257 if (!PyString_Check(key)) { |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1258 PyErr_SetString(PyExc_TypeError, |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1259 "keywords must be strings"); |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1260 return 0; |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1261 } |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1262 ks = PyString_AsString(key); |
|
20722
676f106a5002
vgetargskeywords: Now that it's clear that nkwlist must equal max, and
Tim Peters <tim.peters@gmail.com>
parents:
20721
diff
changeset
|
1263 for (i = 0; i < max; i++) { |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1264 if (!strcmp(ks, kwlist[i])) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1265 match = 1; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1266 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1267 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1268 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1269 if (!match) { |
| 20723 | 1270 PyErr_Format(PyExc_TypeError, |
| 1271 "'%s' is an invalid keyword " | |
| 1272 "argument for this function", | |
| 1273 ks); | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1274 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1275 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1276 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1277 } |
| 20723 | 1278 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1279 return 1; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1280 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1281 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1282 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1283 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1284 skipitem(char **p_format, va_list *p_va) |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1285 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1286 char *format = *p_format; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1287 char c = *format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1288 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1289 switch (c) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1290 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1291 case 'b': /* byte -- very short int */ |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
1292 case 'B': /* byte as bitfield */ |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1293 { |
| 4596 | 1294 (void) va_arg(*p_va, char *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1295 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1296 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1297 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1298 case 'h': /* short int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1299 { |
| 4596 | 1300 (void) va_arg(*p_va, short *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1301 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1302 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1303 |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
1304 case 'H': /* short int as bitfield */ |
|
13378
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1305 { |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1306 (void) va_arg(*p_va, unsigned short *); |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1307 break; |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1308 } |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1309 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1310 case 'i': /* int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1311 { |
| 4596 | 1312 (void) va_arg(*p_va, int *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1313 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1314 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1315 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1316 case 'l': /* long int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1317 { |
| 4596 | 1318 (void) va_arg(*p_va, long *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1319 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1320 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1321 |
|
9949
98e37347378b
Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents:
9306
diff
changeset
|
1322 #ifdef HAVE_LONG_LONG |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
1323 case 'L': /* PY_LONG_LONG int */ |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1324 { |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27685
diff
changeset
|
1325 (void) va_arg(*p_va, PY_LONG_LONG *); |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1326 break; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1327 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1328 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1329 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1330 case 'f': /* float */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1331 { |
| 4596 | 1332 (void) va_arg(*p_va, float *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1333 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1334 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1335 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1336 case 'd': /* double */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1337 { |
| 4596 | 1338 (void) va_arg(*p_va, double *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1339 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1340 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1341 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1342 #ifndef WITHOUT_COMPLEX |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1343 case 'D': /* complex double */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1344 { |
| 4596 | 1345 (void) va_arg(*p_va, Py_complex *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1346 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1347 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1348 #endif /* WITHOUT_COMPLEX */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1349 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1350 case 'c': /* char */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1351 { |
| 4596 | 1352 (void) va_arg(*p_va, char *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1353 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1354 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1355 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1356 case 's': /* string */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1357 { |
| 4596 | 1358 (void) va_arg(*p_va, char **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1359 if (*format == '#') { |
| 4596 | 1360 (void) va_arg(*p_va, int *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1361 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1362 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1363 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1364 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1365 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1366 case 'z': /* string */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1367 { |
| 4596 | 1368 (void) va_arg(*p_va, char **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1369 if (*format == '#') { |
| 4596 | 1370 (void) va_arg(*p_va, int *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1371 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1372 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1373 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1374 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1375 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1376 case 'S': /* string object */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1377 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1378 (void) va_arg(*p_va, PyObject **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1379 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1380 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1381 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1382 case 'O': /* object */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1383 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1384 if (*format == '!') { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1385 format++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1386 (void) va_arg(*p_va, PyTypeObject*); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1387 (void) va_arg(*p_va, PyObject **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1388 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1389 #if 0 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1390 /* I don't know what this is for */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1391 else if (*format == '?') { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1392 inquiry pred = va_arg(*p_va, inquiry); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1393 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1394 if ((*pred)(arg)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1395 (void) va_arg(*p_va, PyObject **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1396 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1397 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1398 #endif |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1399 else if (*format == '&') { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13378
diff
changeset
|
1400 typedef int (*converter)(PyObject *, void *); |
| 4596 | 1401 (void) va_arg(*p_va, converter); |
| 1402 (void) va_arg(*p_va, void *); | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1403 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1404 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1405 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1406 (void) va_arg(*p_va, PyObject **); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1407 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1408 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1409 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1410 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1411 default: |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1412 return "impossible<bad format char>"; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1413 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1414 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1415 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1416 *p_format = format; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1417 return NULL; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1418 } |
|
20632
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1419 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1420 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1421 int |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1422 PyArg_UnpackTuple(PyObject *args, char *name, int min, int max, ...) |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1423 { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1424 int i, l; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1425 PyObject **o; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1426 va_list vargs; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1427 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1428 #ifdef HAVE_STDARG_PROTOTYPES |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1429 va_start(vargs, max); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1430 #else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1431 va_start(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1432 #endif |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1433 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1434 assert(min >= 0); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1435 assert(min <= max); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1436 if (!PyTuple_Check(args)) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1437 PyErr_SetString(PyExc_SystemError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1438 "PyArg_UnpackTuple() argument list is not a tuple"); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1439 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1440 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1441 l = PyTuple_GET_SIZE(args); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1442 if (l < min) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1443 if (name != NULL) |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1444 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1445 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1446 "%s expected %s%d arguments, got %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1447 name, (min == max ? "" : "at least "), min, l); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1448 else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1449 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1450 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1451 "unpacked tuple should have %s%d elements," |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1452 " but has %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1453 (min == max ? "" : "at least "), min, l); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1454 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1455 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1456 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1457 if (l > max) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1458 if (name != NULL) |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1459 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1460 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1461 "%s expected %s%d arguments, got %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1462 name, (min == max ? "" : "at most "), max, l); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1463 else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1464 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1465 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1466 "unpacked tuple should have %s%d elements," |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1467 " but has %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1468 (min == max ? "" : "at most "), max, l); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1469 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1470 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1471 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1472 for (i = 0; i < l; i++) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1473 o = va_arg(vargs, PyObject **); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1474 *o = PyTuple_GET_ITEM(args, i); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1475 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1476 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1477 return 1; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1478 } |
