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