Mercurial > cpython-lru_cache-weakref
annotate Python/getargs.c @ 26923:dbfc3ef7d003 legacy-trunk
Since the *_Init() are private, prefix with _, suggested by Skip
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Tue, 31 Dec 2002 03:42:13 +0000 |
| parents | 680360e68a06 |
| children | eb1e529fdfdf |
| 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++; |
|
26321
680360e68a06
Wrap uargs declaration in a #ifdef Py_USING_UNICODE, so that
Walter Dörwald <walter@livinglogic.de>
parents:
24400
diff
changeset
|
403 #ifdef Py_USING_UNICODE |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
404 PyObject *uarg; |
|
26321
680360e68a06
Wrap uargs declaration in a #ifdef Py_USING_UNICODE, so that
Walter Dörwald <walter@livinglogic.de>
parents:
24400
diff
changeset
|
405 #endif |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 switch (c) { |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
409 case 'b': { /* unsigned byte -- very short int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
410 char *p = va_arg(*p_va, char *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
411 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
412 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
|
413 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
|
414 else if (ival < 0) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
415 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
416 "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
|
417 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
|
418 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
419 else if (ival > UCHAR_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
420 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
421 "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
|
422 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
|
423 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
424 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
425 *p = (unsigned char) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
426 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
427 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
429 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
|
430 values allowed */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
431 char *p = va_arg(*p_va, char *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
432 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
433 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
|
434 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
|
435 else if (ival < SCHAR_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
436 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
437 "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
|
438 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
|
439 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
440 else if (ival > (int)UCHAR_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
441 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
442 "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
|
443 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
|
444 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
445 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
446 *p = (unsigned char) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
447 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
448 } |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
449 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
450 case 'h': {/* signed short int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
451 short *p = va_arg(*p_va, short *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
452 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
453 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
|
454 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
|
455 else if (ival < SHRT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
456 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
457 "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
|
458 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
|
459 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
460 else if (ival > SHRT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
461 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
462 "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
|
463 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
|
464 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
465 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
466 *p = (short) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
467 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
468 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
470 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
|
471 unsigned allowed */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
472 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
|
473 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
474 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
|
475 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
|
476 else if (ival < SHRT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
477 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
478 "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
|
479 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
|
480 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
481 else if (ival > USHRT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
482 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
483 "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
|
484 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
|
485 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
486 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
487 *p = (unsigned short) ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
488 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
489 } |
|
13378
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
490 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
491 case 'i': {/* signed int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
492 int *p = va_arg(*p_va, int *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
493 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
494 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
|
495 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
|
496 else if (ival > INT_MAX) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
497 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
498 "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
|
499 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
|
500 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
501 else if (ival < INT_MIN) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
502 PyErr_SetString(PyExc_OverflowError, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
503 "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
|
504 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
|
505 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
506 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
507 *p = ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
508 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
509 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
510 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
511 case 'l': {/* long int */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
512 long *p = va_arg(*p_va, long *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
513 long ival = PyInt_AsLong(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
514 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
|
515 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
|
516 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
517 *p = ival; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
518 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
519 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 |
|
9949
98e37347378b
Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents:
9306
diff
changeset
|
521 #ifdef HAVE_LONG_LONG |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
522 case 'L': {/* LONG_LONG */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
523 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
|
524 LONG_LONG ival = PyLong_AsLongLong( arg ); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
525 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
|
526 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
|
527 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
528 *p = ival; |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
529 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
530 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
531 } |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
532 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
533 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
534 case 'f': {/* float */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
535 float *p = va_arg(*p_va, float *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
536 double dval = PyFloat_AsDouble(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
537 if (PyErr_Occurred()) |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
538 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
|
539 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
540 *p = (float) dval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
541 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
542 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
543 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
544 case 'd': {/* double */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
545 double *p = va_arg(*p_va, double *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
546 double dval = PyFloat_AsDouble(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
547 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
|
548 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
|
549 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
550 *p = dval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
551 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
552 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
553 |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3323
diff
changeset
|
554 #ifndef WITHOUT_COMPLEX |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
555 case 'D': {/* complex double */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
556 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
|
557 Py_complex cval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
558 cval = PyComplex_AsCComplex(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
559 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
|
560 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
|
561 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
562 *p = cval; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
563 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
564 } |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3323
diff
changeset
|
565 #endif /* WITHOUT_COMPLEX */ |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2210
diff
changeset
|
566 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
567 case 'c': {/* char */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
568 char *p = va_arg(*p_va, char *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
569 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
|
570 *p = PyString_AS_STRING(arg)[0]; |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
571 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
572 return converterr("char", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
573 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
574 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
575 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
576 case 's': {/* string */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
577 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
578 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
|
579 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
|
580 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
581 if (PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
582 *p = PyString_AS_STRING(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
583 *q = PyString_GET_SIZE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
584 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
585 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
586 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
|
587 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
|
588 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
589 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
|
590 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
591 *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
|
592 *q = PyString_GET_SIZE(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
593 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
594 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
595 else { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
596 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
597 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
598 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
|
599 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
600 *q = count; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
602 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
603 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
604 char **p = va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
605 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
606 if (PyString_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
607 *p = PyString_AS_STRING(arg); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
608 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
609 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
|
610 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
|
611 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
612 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
|
613 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
614 *p = PyString_AS_STRING(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
615 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
616 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
617 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
618 return converterr("string", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
619 if ((int)strlen(*p) != PyString_Size(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
620 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
|
621 arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
623 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
624 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
625 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
626 case 'z': {/* string, may be NULL (None) */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
627 if (*format == '#') { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
628 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
|
629 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
|
630 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
631 if (arg == Py_None) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
632 *p = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
633 *q = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
634 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
635 else if (PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
636 *p = PyString_AS_STRING(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
637 *q = PyString_GET_SIZE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
638 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
639 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
640 else if (PyUnicode_Check(arg)) { |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
641 uarg = UNICODE_DEFAULT_ENCODING(arg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
642 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
643 return converterr(CONV_UNICODE, |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
644 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
645 *p = PyString_AS_STRING(uarg); |
|
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
646 *q = PyString_GET_SIZE(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
647 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
648 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
649 else { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
650 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
651 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
652 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
|
653 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
654 *q = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
655 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
656 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
657 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
658 char **p = va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
659 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
660 if (arg == Py_None) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
661 *p = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
662 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
|
663 *p = PyString_AS_STRING(arg); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
664 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
665 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
|
666 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
|
667 if (uarg == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
668 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
|
669 arg, msgbuf, bufsize); |
|
19820
fe5ec1a3a7e0
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19533
diff
changeset
|
670 *p = PyString_AS_STRING(uarg); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
671 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
672 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
673 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
674 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
|
675 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
676 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
677 int *q = va_arg(*p_va, int *); |
| 12612 | 678 if (arg == Py_None) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
679 *q = 0; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
680 else |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
681 *q = PyString_Size(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
682 format++; |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
684 else if (*p != NULL && |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
685 (int)strlen(*p) != PyString_Size(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
686 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
687 "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
|
688 arg, msgbuf, bufsize); |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
690 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
691 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
693 case 'e': {/* encoded string */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
694 char **buffer; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
695 const char *encoding; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
696 PyObject *s; |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
697 int size, recode_strings; |
| 12051 | 698 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
699 /* Get 'e' parameter: the encoding name */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
700 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
|
701 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
702 if (encoding == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
703 encoding = PyUnicode_GetDefaultEncoding(); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
704 #endif |
| 12051 | 705 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
706 /* Get output buffer parameter: |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
707 's' (recode all objects via Unicode) or |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
708 't' (only recode non-string objects) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
709 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
710 if (*format == 's') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
711 recode_strings = 1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
712 else if (*format == 't') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
713 recode_strings = 0; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
714 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
715 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
716 "(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
|
717 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
718 buffer = (char **)va_arg(*p_va, char **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
719 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
720 if (buffer == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
721 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
|
722 arg, msgbuf, bufsize); |
| 12051 | 723 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
724 /* Encode object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
725 if (!recode_strings && PyString_Check(arg)) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
726 s = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
727 Py_INCREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
728 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
729 else { |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
730 #ifdef Py_USING_UNICODE |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
731 PyObject *u; |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
732 |
| 12051 | 733 /* Convert object to Unicode */ |
| 734 u = PyUnicode_FromObject(arg); | |
| 735 if (u == NULL) | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
736 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
737 "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
|
738 arg, msgbuf, bufsize); |
| 12051 | 739 |
| 740 /* Encode object; use default error handling */ | |
| 741 s = PyUnicode_AsEncodedString(u, | |
| 742 encoding, | |
| 743 NULL); | |
| 744 Py_DECREF(u); | |
| 745 if (s == NULL) | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
746 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
|
747 arg, msgbuf, bufsize); |
| 12051 | 748 if (!PyString_Check(s)) { |
| 749 Py_DECREF(s); | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
750 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
751 "(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
|
752 arg, msgbuf, bufsize); |
| 12051 | 753 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
754 #else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
755 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
|
756 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
757 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
758 size = PyString_GET_SIZE(s); |
| 12051 | 759 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
760 /* 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
|
761 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
762 /* Using buffer length parameter '#': |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
763 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
764 - 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
|
765 needed size is allocated and the data |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
766 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
|
767 to the new buffer; the caller is |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
768 responsible for PyMem_Free()ing it after |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
769 usage |
| 12051 | 770 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
771 - 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
|
772 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
|
773 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
|
774 buffer overflow is signalled with an error; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
775 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
|
776 encoded string plus the trailing 0-byte |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
777 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
778 - 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
|
779 the size of the buffer /excluding/ the |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
780 trailing 0-byte |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
781 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
782 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
783 int *buffer_len = va_arg(*p_va, int *); |
| 12051 | 784 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
785 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
786 if (buffer_len == NULL) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
787 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
788 "(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
|
789 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
790 if (*buffer == NULL) { |
| 12051 | 791 *buffer = PyMem_NEW(char, size + 1); |
| 792 if (*buffer == NULL) { | |
| 793 Py_DECREF(s); | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
794 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
795 "(memory error)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
796 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
797 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
798 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
799 if (size + 1 > *buffer_len) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
800 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
801 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
802 "(buffer overflow)", |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
803 arg, msgbuf, bufsize); |
| 12051 | 804 } |
| 805 } | |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
806 memcpy(*buffer, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
807 PyString_AS_STRING(s), |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
808 size + 1); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
809 *buffer_len = size; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
810 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
811 /* Using a 0-terminated buffer: |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
812 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
813 - 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
|
814 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
|
815 error raised |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
816 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
817 - 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
|
818 allocated and the data copied into it; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
819 *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
|
820 buffer; the caller is responsible for |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
821 PyMem_Free()ing it after usage |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
822 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
823 */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
824 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
|
825 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
826 "(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
|
827 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
828 *buffer = PyMem_NEW(char, size + 1); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
829 if (*buffer == NULL) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
830 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
831 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
|
832 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
833 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
834 memcpy(*buffer, |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
835 PyString_AS_STRING(s), |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
836 size + 1); |
| 12051 | 837 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
838 Py_DECREF(s); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
839 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
840 } |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
841 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
842 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
843 case 'u': {/* raw unicode buffer (Py_UNICODE *) */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
844 if (*format == '#') { /* any buffer-like object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
845 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
|
846 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
|
847 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
|
848 *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
|
849 *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
|
850 } |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21145
diff
changeset
|
851 else { |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
852 char *buf; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
853 int count = convertbuffer(arg, p, &buf); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
854 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
|
855 return converterr(buf, arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
856 *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
|
857 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
858 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
859 } else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
860 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
|
861 if (PyUnicode_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
862 *p = PyUnicode_AS_UNICODE(arg); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
863 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
864 return converterr("unicode", arg, msgbuf, bufsize); |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
865 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
866 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
867 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
868 #endif |
|
12570
3dbe41380266
Brian Hooper <brian_takashi@hotmail.com>:
Fred Drake <fdrake@acm.org>
parents:
12510
diff
changeset
|
869 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
870 case 'S': { /* string object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
871 PyObject **p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
872 if (PyString_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
873 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
874 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
875 return converterr("string", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
876 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
877 } |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
878 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
879 #ifdef Py_USING_UNICODE |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
880 case 'U': { /* Unicode object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
881 PyObject **p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
882 if (PyUnicode_Check(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
883 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
884 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
885 return converterr("unicode", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
886 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
887 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18887
diff
changeset
|
888 #endif |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
889 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
890 case 'O': { /* object */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
891 PyTypeObject *type; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
892 PyObject **p; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
893 if (*format == '!') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
894 type = va_arg(*p_va, PyTypeObject*); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
895 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
896 format++; |
|
19533
3e7897822459
The "O!" format code should implement an isinstance() test
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
897 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
|
898 *p = arg; |
|
876f35828e87
Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode
Guido van Rossum <guido@python.org>
parents:
10220
diff
changeset
|
899 else |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
900 return converterr(type->tp_name, arg, msgbuf, bufsize); |
|
8358
da4bdceeaad7
Another veeeeeery old patch...
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
901 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
902 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
903 else if (*format == '?') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
904 inquiry pred = va_arg(*p_va, inquiry); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
905 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
906 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
907 if ((*pred)(arg)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
908 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
909 else |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
910 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
|
911 arg, msgbuf, bufsize); |
|
8358
da4bdceeaad7
Another veeeeeery old patch...
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
912 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
913 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
914 else if (*format == '&') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
915 typedef int (*converter)(PyObject *, void *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
916 converter convert = va_arg(*p_va, converter); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
917 void *addr = va_arg(*p_va, void *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
918 format++; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
919 if (! (*convert)(arg, addr)) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
920 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
|
921 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
922 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
923 else { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
924 p = va_arg(*p_va, PyObject **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
925 *p = arg; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
926 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
927 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
928 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
929 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
930 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
931 case 'w': { /* memory buffer, read-write access */ |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
932 void **p = va_arg(*p_va, void **); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
933 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
|
934 int count; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
935 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
936 if (pb == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
937 pb->bf_getwritebuffer == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
938 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
|
939 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
|
940 if ((*pb->bf_getsegcount)(arg, NULL) != 1) |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
941 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
|
942 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
943 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
|
944 return converterr("(unspecified)", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
945 if (*format == '#') { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
946 int *q = va_arg(*p_va, int *); |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
947 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
948 *q = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
949 format++; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
950 } |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
951 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
952 } |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5408
diff
changeset
|
953 |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 int count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
958 |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
959 if (*format++ != '#') |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
960 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
961 "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
|
962 arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
963 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
|
964 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
|
965 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
|
966 pb->bf_getsegcount == NULL) |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
967 return converterr( |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
968 "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
|
969 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
|
970 |
|
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
|
971 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
|
972 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
|
973 "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
|
974 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
|
975 |
|
8ef3e95182c3
Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20357
diff
changeset
|
976 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
|
977 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
|
978 return converterr("(unspecified)", arg, msgbuf, bufsize); |
|
17996
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
979 *va_arg(*p_va, int *) = count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
980 break; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
981 } |
|
9306
79439e4e9976
Implement new format character 't#'. This is like s#, accepting an
Guido van Rossum <guido@python.org>
parents:
9044
diff
changeset
|
982 |
|
1913
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
983 default: |
|
21096
cdb70bf88db1
Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21092
diff
changeset
|
984 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
|
985 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
986 } |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
987 |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 *p_format = format; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
989 return NULL; |
|
8623aa3915db
* Python/{modsupport.c,getargs.c,Makefile.in},
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
990 } |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
991 |
|
20629
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
992 static int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
993 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
|
994 { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
995 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
|
996 int count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
997 if (pb == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
998 pb->bf_getreadbuffer == NULL || |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
999 pb->bf_getsegcount == NULL) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1000 *errmsg = "string or read-only buffer"; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1001 return -1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1002 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1003 if ((*pb->bf_getsegcount)(arg, NULL) != 1) { |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1004 *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
|
1005 return -1; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1006 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1007 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
|
1008 *errmsg = "(unspecified)"; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1009 } |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1010 return count; |
|
5a9debb14440
Internal refactoring of convertsimple() and friends.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17857
diff
changeset
|
1011 } |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1012 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1013 /* 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
|
1014 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
|
1015 |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1016 /* 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
|
1017 int |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1018 PyArg_ParseTupleAndKeywords(PyObject *args, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1019 PyObject *keywords, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1020 char *format, |
|
acc7e3b4d042
Style conformance: function name begins a new line *consistently*.
Fred Drake <fdrake@acm.org>
parents:
20371
diff
changeset
|
1021 char **kwlist, ...) |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1022 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1023 int retval; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1024 va_list va; |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1025 |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1026 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
|
1027 (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
|
1028 format == NULL || |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1029 kwlist == NULL) |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1030 { |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1031 PyErr_BadInternalCall(); |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1032 return 0; |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1033 } |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1034 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1035 va_start(va, kwlist); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1036 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
|
1037 va_end(va); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1038 return retval; |
|
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 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1041 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1042 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1043 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
|
1044 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
|
1045 { |
|
20721
acb854b897bb
vgetargskeywords: Prevent another potential sprintf buffer overrun.
Tim Peters <tim.peters@gmail.com>
parents:
20720
diff
changeset
|
1046 char msgbuf[512]; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1047 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
|
1048 char *fname, *message; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1049 int min, max; |
| 20713 | 1050 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
|
1051 int i, len, nargs, nkeywords; |
| 20723 | 1052 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
|
1053 |
|
20710
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1054 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
|
1055 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
|
1056 assert(format != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1057 assert(kwlist != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1058 assert(p_va != NULL); |
|
a44cc0c21cfe
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
Tim Peters <tim.peters@gmail.com>
parents:
20709
diff
changeset
|
1059 |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1060 /* Search the format: |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 */ |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1068 fname = message = NULL; |
| 20713 | 1069 formatsave = format; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1070 p = kwlist; |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1071 min = -1; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1072 max = 0; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1073 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
|
1074 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
|
1075 max++; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1076 if (*p == NULL) { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1077 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1078 "more argument specifiers than " |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1079 "keyword list entries"); |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1080 return 0; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1081 } |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1082 p++; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1083 } |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1084 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 min = max; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1086 else if (i == ':') { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1087 fname = format; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1088 break; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1089 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1090 else if (i == ';') { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1091 message = format; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1092 break; |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1093 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1094 else if (i == '(') { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1095 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1096 "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
|
1097 "arguments"); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1098 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1099 } |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1100 } |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1101 format = formatsave; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1102 if (*p != NULL) { |
|
21100
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1103 PyErr_SetString(PyExc_RuntimeError, |
|
0feac45ee662
SF bug 486278 SystemError: Python/getargs.c:1086: bad.
Tim Peters <tim.peters@gmail.com>
parents:
21096
diff
changeset
|
1104 "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
|
1105 "argument specifiers"); |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1106 return 0; |
|
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1107 } |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1108 if (min < 0) { |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1109 /* All arguments are required. */ |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1110 min = max; |
|
20711
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1111 } |
|
2890769b1e69
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
Tim Peters <tim.peters@gmail.com>
parents:
20710
diff
changeset
|
1112 |
| 20713 | 1113 nargs = PyTuple_GET_SIZE(args); |
| 20714 | 1114 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
|
1115 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1116 /* 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
|
1117 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
|
1118 keyword parameter in messages */ |
| 20715 | 1119 if (nkeywords > 0) { |
| 20713 | 1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 if (PyDict_GetItemString(keywords, thiskw)) { |
| 20715 | 1125 PyErr_Format(PyExc_TypeError, |
| 1126 "keyword parameter '%s' was given " | |
| 1127 "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
|
1128 thiskw); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1129 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1130 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1131 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
|
1132 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1133 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1134 } |
|
20716
dcf769c12d8b
vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.
Tim Peters <tim.peters@gmail.com>
parents:
20715
diff
changeset
|
1135 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1136 /* 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
|
1137 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
|
1138 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
|
1139 required arguments that are supplied by keywords */ |
| 20713 | 1140 len = nargs; |
|
20720
aaefc2f21bae
vgetargskeywords: Verify kwlist has the required length while parsing
Tim Peters <tim.peters@gmail.com>
parents:
20718
diff
changeset
|
1141 if (nkeywords > 0 && nargs < min) { |
| 20713 | 1142 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
|
1143 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
|
1144 len++; |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1145 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
|
1146 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1147 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1148 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1149 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1150 /* 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
|
1151 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
|
1152 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
|
1153 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
|
1154 if (len < min || max < len) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1155 if (message == NULL) { |
|
21074
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1156 PyOS_snprintf(msgbuf, sizeof(msgbuf), |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1157 "%.200s%s takes %s %d argument%s " |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1158 "(%d given)", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1159 fname==NULL ? "function" : fname, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1160 fname==NULL ? "" : "()", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1161 min==max ? "exactly" |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1162 : len < min ? "at least" : "at most", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1163 len < min ? min : max, |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1164 (len < min ? min : max) == 1 ? "" : "s", |
|
47ea73fd7e6b
Use PyOS_snprintf when possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21066
diff
changeset
|
1165 len); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1166 message = msgbuf; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1167 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1168 PyErr_SetString(PyExc_TypeError, message); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1169 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1170 } |
| 20723 | 1171 |
| 1172 /* convert the positional arguments */ | |
| 20713 | 1173 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
|
1174 if (*format == '|') |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1175 format++; |
|
17856
2807949e0ba5
vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17817
diff
changeset
|
1176 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
|
1177 levels, msgbuf, sizeof(msgbuf)); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1178 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1179 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
|
1180 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1181 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1182 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1183 |
| 20723 | 1184 /* handle no keyword parameters in call */ |
| 20715 | 1185 if (nkeywords == 0) |
| 20712 | 1186 return 1; |
| 20715 | 1187 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1188 /* 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
|
1189 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
|
1190 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
|
1191 PyObject *item; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1192 if (*format == '|') |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1193 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
|
1194 item = PyDict_GetItemString(keywords, kwlist[i]); |
| 4596 | 1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 Py_DECREF(item); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1200 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1201 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
|
1202 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1203 } |
| 20723 | 1204 --nkeywords; |
| 1205 if (nkeywords == 0) | |
| 1206 break; | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1207 } |
|
20718
c6384591d846
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
Tim Peters <tim.peters@gmail.com>
parents:
20717
diff
changeset
|
1208 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
|
1209 return 0; |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1210 else { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1211 msg = skipitem(&format, p_va); |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1212 if (msg) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1213 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
|
1214 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1215 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1216 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1217 } |
| 20715 | 1218 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1219 /* make sure there are no extraneous keyword arguments */ |
| 20723 | 1220 if (nkeywords > 0) { |
| 1221 PyObject *key, *value; | |
| 1222 int pos = 0; | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1223 while (PyDict_Next(keywords, &pos, &key, &value)) { |
| 20723 | 1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 "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
|
1229 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
|
1230 } |
|
f0277146aa16
Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Guido van Rossum <guido@python.org>
parents:
21667
diff
changeset
|
1231 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
|
1232 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
|
1233 if (!strcmp(ks, kwlist[i])) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1234 match = 1; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1235 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1236 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1237 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1238 if (!match) { |
| 20723 | 1239 PyErr_Format(PyExc_TypeError, |
| 1240 "'%s' is an invalid keyword " | |
| 1241 "argument for this function", | |
| 1242 ks); | |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1243 return 0; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1244 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1245 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1246 } |
| 20723 | 1247 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1248 return 1; |
|
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 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1251 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1252 static char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1253 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
|
1254 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1255 char *format = *p_format; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1256 char c = *format++; |
|
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 switch (c) { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1259 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1260 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
|
1261 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
|
1262 { |
| 4596 | 1263 (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
|
1264 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1265 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1266 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1267 case 'h': /* short int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1268 { |
| 4596 | 1269 (void) va_arg(*p_va, short *); |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1270 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1271 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1272 |
|
13872
35fc9511a36f
Changed H specifier to mean "bitfield", i.e. any value from
Jack Jansen <jack.jansen@cwi.nl>
parents:
13837
diff
changeset
|
1273 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
|
1274 { |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1275 (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
|
1276 break; |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1277 } |
|
113d833eea7e
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Jack Jansen <jack.jansen@cwi.nl>
parents:
13268
diff
changeset
|
1278 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1279 case 'i': /* int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1280 { |
| 4596 | 1281 (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
|
1282 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1283 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1284 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1285 case 'l': /* long int */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1286 { |
| 4596 | 1287 (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
|
1288 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1289 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1290 |
|
9949
98e37347378b
Change rare occurrences of #if HAVE_LONG_LONG to #ifdef.
Guido van Rossum <guido@python.org>
parents:
9306
diff
changeset
|
1291 #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
|
1292 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
|
1293 { |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
1294 (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
|
1295 break; |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1296 } |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1297 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8358
diff
changeset
|
1298 |
|
4026
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1299 case 'f': /* float */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1300 { |
| 4596 | 1301 (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
|
1302 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1303 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1304 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1305 case 'd': /* double */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1306 { |
| 4596 | 1307 (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
|
1308 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1309 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1310 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1311 #ifndef WITHOUT_COMPLEX |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1312 case 'D': /* complex double */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1313 { |
| 4596 | 1314 (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
|
1315 break; |
|
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 #endif /* WITHOUT_COMPLEX */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1318 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1319 case 'c': /* char */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1320 { |
| 4596 | 1321 (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
|
1322 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1323 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1324 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1325 case 's': /* string */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1326 { |
| 4596 | 1327 (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
|
1328 if (*format == '#') { |
| 4596 | 1329 (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
|
1330 format++; |
|
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 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1333 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1334 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1335 case 'z': /* string */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1336 { |
| 4596 | 1337 (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
|
1338 if (*format == '#') { |
| 4596 | 1339 (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
|
1340 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1341 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1342 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1343 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1344 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1345 case 'S': /* string object */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1346 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1347 (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
|
1348 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1349 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1350 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1351 case 'O': /* object */ |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1352 { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1353 if (*format == '!') { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1354 format++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1355 (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
|
1356 (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
|
1357 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1358 #if 0 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1359 /* 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
|
1360 else if (*format == '?') { |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1361 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
|
1362 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1363 if ((*pred)(arg)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1364 (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
|
1365 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1366 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1367 #endif |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1368 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
|
1369 typedef int (*converter)(PyObject *, void *); |
| 4596 | 1370 (void) va_arg(*p_va, converter); |
| 1371 (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
|
1372 format++; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1373 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1374 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1375 (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
|
1376 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1377 break; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1378 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1379 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1380 default: |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1381 return "impossible<bad format char>"; |
|
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 } |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1384 |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1385 *p_format = format; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1386 return NULL; |
|
6bbc13b7dca8
Support for keyword arguments (PyArg_ParseTupleAndKeywords) donated by
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1387 } |
|
20632
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1388 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1389 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1390 int |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1391 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
|
1392 { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1393 int i, l; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1394 PyObject **o; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1395 va_list vargs; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1396 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1397 #ifdef HAVE_STDARG_PROTOTYPES |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1398 va_start(vargs, max); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1399 #else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1400 va_start(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1401 #endif |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1402 |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1403 assert(min >= 0); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1404 assert(min <= max); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1405 if (!PyTuple_Check(args)) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1406 PyErr_SetString(PyExc_SystemError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1407 "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
|
1408 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1409 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1410 l = PyTuple_GET_SIZE(args); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1411 if (l < min) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1412 if (name != NULL) |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1413 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1414 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1415 "%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
|
1416 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
|
1417 else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1418 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1419 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1420 "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
|
1421 " but has %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1422 (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
|
1423 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1424 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1425 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1426 if (l > max) { |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1427 if (name != NULL) |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1428 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1429 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1430 "%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
|
1431 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
|
1432 else |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1433 PyErr_Format( |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1434 PyExc_TypeError, |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1435 "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
|
1436 " but has %d", |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1437 (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
|
1438 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1439 return 0; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1440 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1441 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
|
1442 o = va_arg(vargs, PyObject **); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1443 *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
|
1444 } |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1445 va_end(vargs); |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1446 return 1; |
|
6c84d55abb58
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fred Drake <fdrake@acm.org>
parents:
20629
diff
changeset
|
1447 } |
