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