comparison Python/getargs.c @ 13658:f79434ee41fa legacy-trunk

Mass ANSIfication of function definitions. Doesn't cover all 'extern' declarations yet, those come later.
author Thomas Wouters <thomas@python.org>
date Sat, 22 Jul 2000 18:47:25 +0000
parents 5b727ab37092
children 2badb322355f
comparison
equal deleted inserted replaced
13657:6a5314a6c2c2 13658:f79434ee41fa
41 41
42 static int vgetargskeywords(PyObject *, PyObject *, 42 static int vgetargskeywords(PyObject *, PyObject *,
43 char *, char **, va_list *); 43 char *, char **, va_list *);
44 static char *skipitem(char **, va_list *); 44 static char *skipitem(char **, va_list *);
45 45
46 #ifdef HAVE_STDARG_PROTOTYPES
47 /* VARARGS2 */
48 int PyArg_Parse(PyObject *args, char *format, ...) 46 int PyArg_Parse(PyObject *args, char *format, ...)
49 #else
50 /* VARARGS */
51 int PyArg_Parse(va_alist) va_dcl
52 #endif
53 { 47 {
54 int retval; 48 int retval;
55 va_list va; 49 va_list va;
56 #ifdef HAVE_STDARG_PROTOTYPES
57 50
58 va_start(va, format); 51 va_start(va, format);
59 #else
60 PyObject *args;
61 char *format;
62
63 va_start(va);
64 args = va_arg(va, PyObject *);
65 format = va_arg(va, char *);
66 #endif
67 retval = vgetargs1(args, format, &va, 1); 52 retval = vgetargs1(args, format, &va, 1);
68 va_end(va); 53 va_end(va);
69 return retval; 54 return retval;
70 } 55 }
71 56
72 57
73 #ifdef HAVE_STDARG_PROTOTYPES
74 /* VARARGS2 */
75 int PyArg_ParseTuple(PyObject *args, char *format, ...) 58 int PyArg_ParseTuple(PyObject *args, char *format, ...)
76 #else
77 /* VARARGS */
78 int PyArg_ParseTuple(va_alist) va_dcl
79 #endif
80 { 59 {
81 int retval; 60 int retval;
82 va_list va; 61 va_list va;
83 #ifdef HAVE_STDARG_PROTOTYPES
84 62
85 va_start(va, format); 63 va_start(va, format);
86 #else
87 PyObject *args;
88 char *format;
89
90 va_start(va);
91 args = va_arg(va, PyObject *);
92 format = va_arg(va, char *);
93 #endif
94 retval = vgetargs1(args, format, &va, 0); 64 retval = vgetargs1(args, format, &va, 0);
95 va_end(va); 65 va_end(va);
96 return retval; 66 return retval;
97 } 67 }
98 68
99 69
100 int 70 int
101 PyArg_VaParse(args, format, va) 71 PyArg_VaParse(PyObject *args, char *format, va_list va)
102 PyObject *args;
103 char *format;
104 va_list va;
105 { 72 {
106 va_list lva; 73 va_list lva;
107 74
108 #ifdef VA_LIST_IS_ARRAY 75 #ifdef VA_LIST_IS_ARRAY
109 memcpy(lva, va, sizeof(va_list)); 76 memcpy(lva, va, sizeof(va_list));
114 return vgetargs1(args, format, &lva, 0); 81 return vgetargs1(args, format, &lva, 0);
115 } 82 }
116 83
117 84
118 static int 85 static int
119 vgetargs1(args, format, p_va, compat) 86 vgetargs1(PyObject *args, char *format, va_list *p_va, int compat)
120 PyObject *args;
121 char *format;
122 va_list *p_va;
123 int compat;
124 { 87 {
125 char msgbuf[256]; 88 char msgbuf[256];
126 int levels[32]; 89 int levels[32];
127 char *fname = NULL; 90 char *fname = NULL;
128 char *message = NULL; 91 char *message = NULL;
252 } 215 }
253 216
254 217
255 218
256 static void 219 static void
257 seterror(iarg, msg, levels, fname, message) 220 seterror(int iarg, char *msg, int *levels, char *fname, char *message)
258 int iarg;
259 char *msg;
260 int *levels;
261 char *fname;
262 char *message;
263 { 221 {
264 char buf[256]; 222 char buf[256];
265 int i; 223 int i;
266 char *p = buf; 224 char *p = buf;
267 225
307 (so you can surround it by "expected ... found"), 265 (so you can surround it by "expected ... found"),
308 and msgbuf is returned. 266 and msgbuf is returned.
309 */ 267 */
310 268
311 static char * 269 static char *
312 converttuple(arg, p_format, p_va, levels, msgbuf, toplevel) 270 converttuple(PyObject *arg, char **p_format, va_list *p_va, int *levels,
313 PyObject *arg; 271 char *msgbuf, int toplevel)
314 char **p_format;
315 va_list *p_va;
316 int *levels;
317 char *msgbuf;
318 int toplevel;
319 { 272 {
320 int level = 0; 273 int level = 0;
321 int n = 0; 274 int n = 0;
322 char *format = *p_format; 275 char *format = *p_format;
323 int i; 276 int i;
376 329
377 330
378 /* Convert a single item. */ 331 /* Convert a single item. */
379 332
380 static char * 333 static char *
381 convertitem(arg, p_format, p_va, levels, msgbuf) 334 convertitem(PyObject *arg, char **p_format, va_list *p_va, int *levels,
382 PyObject *arg; 335 char *msgbuf)
383 char **p_format;
384 va_list *p_va;
385 int *levels;
386 char *msgbuf;
387 { 336 {
388 char *msg; 337 char *msg;
389 char *format = *p_format; 338 char *format = *p_format;
390 339
391 if (*format == '(' /* ')' */) { 340 if (*format == '(' /* ')' */) {
407 356
408 /* Convert a non-tuple argument. Adds to convertsimple1 functionality 357 /* Convert a non-tuple argument. Adds to convertsimple1 functionality
409 by appending ", <actual argument type>" to error message. */ 358 by appending ", <actual argument type>" to error message. */
410 359
411 static char * 360 static char *
412 convertsimple(arg, p_format, p_va, msgbuf) 361 convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf)
413 PyObject *arg;
414 char **p_format;
415 va_list *p_va;
416 char *msgbuf;
417 { 362 {
418 char *msg = convertsimple1(arg, p_format, p_va); 363 char *msg = convertsimple1(arg, p_format, p_va);
419 if (msg != NULL) { 364 if (msg != NULL) {
420 sprintf(msgbuf, "%.50s, %.50s", msg, 365 sprintf(msgbuf, "%.50s, %.50s", msg,
421 arg == Py_None ? "None" : arg->ob_type->tp_name); 366 arg == Py_None ? "None" : arg->ob_type->tp_name);
434 or a string representing the expected type if the conversion failed. 379 or a string representing the expected type if the conversion failed.
435 When failing, an exception may or may not have been raised. 380 When failing, an exception may or may not have been raised.
436 Don't call if a tuple is expected. */ 381 Don't call if a tuple is expected. */
437 382
438 static char * 383 static char *
439 convertsimple1(arg, p_format, p_va) 384 convertsimple1(PyObject *arg, char **p_format, va_list *p_va)
440 PyObject *arg;
441 char **p_format;
442 va_list *p_va;
443 { 385 {
444 char *format = *p_format; 386 char *format = *p_format;
445 char c = *format++; 387 char c = *format++;
446 388
447 switch (c) { 389 switch (c) {
959 901
960 902
961 /* Support for keyword arguments donated by 903 /* Support for keyword arguments donated by
962 Geoff Philbrick <philbric@delphi.hks.com> */ 904 Geoff Philbrick <philbric@delphi.hks.com> */
963 905
964 #ifdef HAVE_STDARG_PROTOTYPES
965 /* VARARGS2 */
966 int PyArg_ParseTupleAndKeywords(PyObject *args, 906 int PyArg_ParseTupleAndKeywords(PyObject *args,
967 PyObject *keywords, 907 PyObject *keywords,
968 char *format, 908 char *format,
969 char **kwlist, ...) 909 char **kwlist, ...)
970 #else
971 /* VARARGS */
972 int PyArg_ParseTupleAndKeywords(va_alist) va_dcl
973 #endif
974 { 910 {
975 int retval; 911 int retval;
976 va_list va; 912 va_list va;
977 #ifdef HAVE_STDARG_PROTOTYPES
978 913
979 va_start(va, kwlist); 914 va_start(va, kwlist);
980 #else
981 PyObject *args;
982 PyObject *keywords;
983 char *format;
984 char **kwlist;
985
986 va_start(va);
987 args = va_arg(va, PyObject *);
988 keywords = va_arg(va, PyObject *);
989 format = va_arg(va, char *);
990 kwlist = va_arg(va, char **);
991 #endif
992 retval = vgetargskeywords(args, keywords, format, kwlist, &va); 915 retval = vgetargskeywords(args, keywords, format, kwlist, &va);
993 va_end(va); 916 va_end(va);
994 return retval; 917 return retval;
995 } 918 }
996 919
997 920
998 static int 921 static int
999 vgetargskeywords(args, keywords, format, kwlist, p_va) 922 vgetargskeywords(PyObject *args, PyObject *keywords, char *format,
1000 PyObject *args; 923 char **kwlist, va_list *p_va)
1001 PyObject *keywords;
1002 char *format;
1003 char **kwlist;
1004 va_list *p_va;
1005 { 924 {
1006 char msgbuf[256]; 925 char msgbuf[256];
1007 int levels[32]; 926 int levels[32];
1008 char *fname = NULL; 927 char *fname = NULL;
1009 char *message = NULL; 928 char *message = NULL;
1202 return 1; 1121 return 1;
1203 } 1122 }
1204 1123
1205 1124
1206 static char * 1125 static char *
1207 skipitem(p_format, p_va) 1126 skipitem(char **p_format, va_list *p_va)
1208 char **p_format;
1209 va_list *p_va;
1210 { 1127 {
1211 char *format = *p_format; 1128 char *format = *p_format;
1212 char c = *format++; 1129 char c = *format++;
1213 1130
1214 switch (c) { 1131 switch (c) {