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