annotate Python/modsupport.c @ 1848:b724599401ff legacy-trunk

Merge back to main trunk
author Guido van Rossum <guido@python.org>
date Tue, 30 Aug 1994 08:27:36 +0000
parents cd397266dc1c
children 8623aa3915db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1 /***********************************************************
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
3 Amsterdam, The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
6
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
8 documentation for any purpose and without fee is hereby granted,
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
9 provided that the above copyright notice appear in all copies and that
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
10 both that copyright notice and this permission notice appear in
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
13 distribution of the software without specific, written prior permission.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
22
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
23 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
24
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Module support implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
27 #include "allobjects.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "modsupport.h"
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "import.h"
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
31 #ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
32 typedef extended va_double;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
33 #else
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
34 typedef double va_double;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
35 #endif
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
36
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
37
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
38 /* initmodule2() has an additional parameter, 'passthrough', which is
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
39 passed as 'self' to functions defined in the module. This is used
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
40 e.g. by dynamically loaded modules on the Mac. */
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
41
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 object *
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
43 initmodule2(name, methods, passthrough)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 char *name;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 struct methodlist *methods;
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
46 object *passthrough;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 object *m, *d, *v;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 struct methodlist *ml;
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
50 char *namebuf;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
51 if ((m = add_module(name)) == NULL) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 fprintf(stderr, "initializing module: %s\n", name);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 fatal("can't create a module");
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 d = getmoduledict(m);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 for (ml = methods; ml->ml_name != NULL; ml++) {
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
57 namebuf = NEW(char, strlen(name) + strlen(ml->ml_name) + 2);
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
58 if (namebuf == NULL)
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
59 fatal("out of mem for method name");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
60 sprintf(namebuf, "%s.%s", name, ml->ml_name);
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
61 v = newmethodobject(namebuf, ml->ml_meth,
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
62 (object *)passthrough, ml->ml_varargs);
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
63 /* XXX The malloc'ed memory in namebuf is never freed */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 fprintf(stderr, "initializing module: %s\n", name);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 fatal("can't initialize module");
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 DECREF(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
70 return m;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
73 /* The standard initmodule() passes NULL for 'self' */
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
74
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
75 object *
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
76 initmodule(name, methods)
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
77 char *name;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
78 struct methodlist *methods;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
79 {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
80 return initmodule2(name, methods, (object *)NULL);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
81 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
82
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
84 /* Helper for mkvalue() to scan the length of a format */
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
85
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
86 static int countformat PROTO((char *format, int endchar));
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
87 static int countformat(format, endchar)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
88 char *format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
89 int endchar;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
90 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
91 int count = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
92 int level = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
93 while (level > 0 || *format != endchar) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
94 if (*format == '\0') {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
95 /* Premature end */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
96 err_setstr(SystemError, "unmatched paren in format");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
97 return -1;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
98 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
99 else if (*format == '(') {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
100 if (level == 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
101 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
102 level++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
103 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
104 else if (*format == ')')
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
105 level--;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
106 else if (level == 0 && *format != '#')
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
107 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
108 format++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
109 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
110 return count;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
111 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
112
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
113
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
114 /* Generic argument list parser */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
116 static int do_arg PROTO((object *arg, char** p_format, va_list *p_va));
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
117 static int
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
118 do_arg(arg, p_format, p_va)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
119 object *arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
120 char** p_format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
121 va_list *p_va;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
123 char *format = *p_format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
124
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
125 if (arg == NULL)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
126 return 0; /* Incomplete tuple or list */
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
127
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
128 switch (*format++) {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
129
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
130 case '(': /* tuple, distributed over C parameters */ {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
131 int i, n;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
132 if (!is_tupleobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
133 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
134 n = gettuplesize(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
135 for (i = 0; i < n; i++) {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
136 if (!do_arg(gettupleitem(arg, i), &format, p_va))
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
137 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
138 }
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
139 if (*format++ != ')')
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
140 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
141 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
142 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
143
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
144 case ')': /* End of format -- too many arguments */
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
145 return 0;
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
146
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
147 case 'b': /* byte -- very short int */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
148 char *p = va_arg(*p_va, char *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
149 long ival = getintvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
150 if (ival == -1 && err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
151 return 0;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
152 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
153 *p = ival;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
154 break;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
155 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
156
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
157 case 'h': /* short int */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
158 short *p = va_arg(*p_va, short *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
159 long ival = getintvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
160 if (ival == -1 && err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
161 return 0;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
162 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
163 *p = ival;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
164 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
165 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
166
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
167 case 'i': /* int */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
168 int *p = va_arg(*p_va, int *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
169 long ival = getintvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
170 if (ival == -1 && err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
171 return 0;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
172 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
173 *p = ival;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
174 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
175 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
176
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
177 case 'l': /* long int */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
178 long *p = va_arg(*p_va, long *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
179 long ival = getintvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
180 if (ival == -1 && err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
181 return 0;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
182 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
183 *p = ival;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
184 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
185 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
186
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
187 case 'f': /* float */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
188 float *p = va_arg(*p_va, float *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
189 double dval = getfloatvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
190 if (err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
191 return 0;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
192 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
193 *p = dval;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
194 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
195 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
196
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
197 case 'd': /* double */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
198 double *p = va_arg(*p_va, double *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
199 double dval = getfloatvalue(arg);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
200 if (err_occurred())
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
201 return 0;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
202 else
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
203 *p = dval;
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
204 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
205 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
206
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
207 case 'c': /* char */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
208 char *p = va_arg(*p_va, char *);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
209 if (is_stringobject(arg) && getstringsize(arg) == 1)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
210 *p = getstringvalue(arg)[0];
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
211 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
212 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
213 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
214 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
215
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
216 case 's': /* string */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
217 char **p = va_arg(*p_va, char **);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
218 if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
219 *p = getstringvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
220 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
221 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
222 if (*format == '#') {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
223 int *q = va_arg(*p_va, int *);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
224 *q = getstringsize(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
225 format++;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
226 }
957
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
227 else if (strlen(*p) != getstringsize(arg)) {
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
228 err_setstr(ValueError, "embedded '\\0' in string arg");
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
229 return 0;
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
230 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
231 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
232 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
233
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
234 case 'z': /* string, may be NULL (None) */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
235 char **p = va_arg(*p_va, char **);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
236 if (arg == None)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
237 *p = 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
238 else if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
239 *p = getstringvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
240 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
241 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
242 if (*format == '#') {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
243 int *q = va_arg(*p_va, int *);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
244 if (arg == None)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
245 *q = 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
246 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
247 *q = getstringsize(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
248 format++;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
249 }
957
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
250 else if (*p != NULL && strlen(*p) != getstringsize(arg)) {
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
251 err_setstr(ValueError, "embedded '\\0' in string arg");
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
252 return 0;
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
253 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
254 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
255 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
256
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
257 case 'S': /* string object */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
258 object **p = va_arg(*p_va, object **);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
259 if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
260 *p = arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
261 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
262 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
263 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
264 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
265
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
266 case 'O': /* object */ {
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
267 typeobject *type;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
268 object **p;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
269 if (*format == '!') {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
270 format++;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
271 type = va_arg(*p_va, typeobject*);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
272 if (arg->ob_type != type)
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
273 return 0;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
274 else {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
275 p = va_arg(*p_va, object **);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
276 *p = arg;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
277 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
278 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
279 else if (*format == '?') {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
280 inquiry pred = va_arg(*p_va, inquiry);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
281 format++;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
282 if ((*pred)(arg)) {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
283 p = va_arg(*p_va, object **);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
284 *p = arg;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
285 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
286 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
287 else if (*format == '&') {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
288 binaryfunc convert = va_arg(*p_va, binaryfunc);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
289 void *addr = va_arg(*p_va, void *);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
290 format++;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
291 if (! (*convert)(arg, addr))
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
292 return 0;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
293 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
294 else {
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
295 p = va_arg(*p_va, object **);
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
296 *p = arg;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
297 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
298 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
299 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
301 default:
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
302 fprintf(stderr, "bad do_arg format: x%x '%c'\n",
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
303 format[-1], format[-1]);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
304 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
305
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
307
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
308 *p_format = format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
309
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
312
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
313 #ifdef HAVE_STDARG_PROTOTYPES
733
f179d8d5ee8c Shut up lint
Guido van Rossum <guido@python.org>
parents: 637
diff changeset
314 /* VARARGS2 */
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
315 int getargs(object *arg, char *format, ...)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
316 #else
733
f179d8d5ee8c Shut up lint
Guido van Rossum <guido@python.org>
parents: 637
diff changeset
317 /* VARARGS */
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
318 int getargs(va_alist) va_dcl
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
319 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
321 char *f;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
322 int ok;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
323 va_list va;
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
324 #ifdef HAVE_STDARG_PROTOTYPES
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
325
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
326 va_start(va, format);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
327 #else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
328 object *arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
329 char *format;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
331 va_start(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
332 arg = va_arg(va, object *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
333 format = va_arg(va, char *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
334 #endif
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
335 if (*format == '\0' || *format == ';') {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
336 va_end(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
337 if (arg != NULL) {
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
338 char *str = "no arguments needed";
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
339 if (*format == ';')
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
340 str = format+1;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
341 err_setstr(TypeError, str);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
342 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
343 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
344 return 1;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
346
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
347 f = format;
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
348 ok = do_arg(arg, &f, &va) && (*f == '\0' || *f == ';');
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
349 va_end(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
350 if (!ok) {
957
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
351 if (!err_occurred()) {
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
352 char buf[256];
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
353 char *str;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
354 f = strchr(format, ';');
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
355 if (f != NULL)
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
356 str = f+1;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
357 else {
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
358 sprintf(buf, "bad argument list (format '%s')",
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
359 format);
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
360 str = buf;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
361 }
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
362 err_setstr(TypeError, str);
957
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
363 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
365 return ok;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
1319
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
368 #ifdef UNUSED
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
369
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 getlongtuplearg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 long *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 if (!is_tupleobject(args) || gettuplesize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 object *v = gettupleitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 getshorttuplearg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 short *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 if (!is_tupleobject(args) || gettuplesize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 object *v = gettupleitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
409
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 getlonglistarg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 long *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 if (!is_listobject(args) || getlistsize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 object *v = getlistitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 getshortlistarg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 short *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 if (!is_listobject(args) || getlistsize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 object *v = getlistitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
449
1319
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
450 #endif /* UNUSED */
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
451
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
452
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
453 /* Generic function to create a value -- the inverse of getargs() */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
454 /* After an original idea and first implementation by Steven Miale */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
455
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
456 static object *do_mktuple PROTO((char**, va_list *, int, int));
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
457 static object *do_mkvalue PROTO((char**, va_list *));
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
458
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
459 static object *
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
460 do_mktuple(p_format, p_va, endchar, n)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
461 char **p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
462 va_list *p_va;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
463 int endchar;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
464 int n;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
465 {
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
466 object *v;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
467 int i;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
468 if (n < 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
469 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
470 if ((v = newtupleobject(n)) == NULL)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
471 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
472 for (i = 0; i < n; i++) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
473 object *w = do_mkvalue(p_format, p_va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
474 if (w == NULL) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
475 DECREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
476 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
477 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
478 settupleitem(v, i, w);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
479 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
480 if (v != NULL && **p_format != endchar) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
481 DECREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
482 v = NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
483 err_setstr(SystemError, "Unmatched paren in format");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
484 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
485 else if (endchar)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
486 ++*p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
487 return v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
488 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
489
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
490 static object *
860
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
491 do_mkvalue(p_format, p_va)
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
492 char **p_format;
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
493 va_list *p_va;
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
494 {
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
495
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
496 switch (*(*p_format)++) {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
497
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
498 case '(':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
499 return do_mktuple(p_format, p_va, ')',
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
500 countformat(*p_format, ')'));
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
501
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
502 case 'b':
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
503 case 'h':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
504 case 'i':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
505 return newintobject((long)va_arg(*p_va, int));
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
506
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
507 case 'l':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
508 return newintobject((long)va_arg(*p_va, long));
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
509
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
510 case 'f':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
511 case 'd':
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
512 return newfloatobject((double)va_arg(*p_va, va_double));
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
513
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
514 case 'c':
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
515 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
516 char p[1];
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
517 p[0] = va_arg(*p_va, int);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
518 return newsizedstringobject(p, 1);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
519 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
520
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
521 case 's':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
522 case 'z':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
523 {
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
524 object *v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
525 char *str = va_arg(*p_va, char *);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
526 int n;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
527 if (**p_format == '#') {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
528 ++*p_format;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
529 n = va_arg(*p_va, int);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
530 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
531 else
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
532 n = -1;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
533 if (str == NULL) {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
534 v = None;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
535 INCREF(v);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
536 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
537 else {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
538 if (n < 0)
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
539 n = strlen(str);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
540 v = newsizedstringobject(str, n);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
541 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
542 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
543 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
544
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
545 case 'S':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
546 case 'O':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
547 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
548 object *v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
549 v = va_arg(*p_va, object *);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
550 if (v != NULL)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
551 INCREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
552 else if (!err_occurred())
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
553 /* If a NULL was passed because a call
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
554 that should have constructed a value
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
555 failed, that's OK, and we pass the error
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
556 on; but if no error occurred it's not
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
557 clear that the caller knew what she
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
558 was doing. */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
559 err_setstr(SystemError,
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
560 "NULL object passed to mkvalue");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
561 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
562 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
563
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
564 default:
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
565 err_setstr(SystemError, "bad format char passed to mkvalue");
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
566 return NULL;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
567
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
568 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
569 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
570
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
571 #ifdef HAVE_STDARG_PROTOTYPES
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
572 /* VARARGS 2 */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
573 object *mkvalue(char *format, ...)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
574 #else
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
575 /* VARARGS */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
576 object *mkvalue(va_alist) va_dcl
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
577 #endif
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
578 {
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
579 va_list va;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
580 object* retval;
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1319
diff changeset
581 #ifdef HAVE_STDARG_PROTOTYPES
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
582 va_start(va, format);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
583 #else
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
584 char *format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
585 va_start(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
586 format = va_arg(va, char *);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
587 #endif
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
588 retval = vmkvalue(format, va);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
589 va_end(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
590 return retval;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
591 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
592
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
593 object *
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
594 vmkvalue(format, va)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
595 char *format;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
596 va_list va;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
597 {
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
598 char *f = format;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
599 int n = countformat(f, '\0');
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
600 if (n < 0)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
601 return NULL;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
602 if (n == 0) {
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
603 INCREF(None);
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
604 return None;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
605 }
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
606 if (n == 1)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
607 return do_mkvalue(&f, &va);
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
608 return do_mktuple(&f, &va, '\0', n);
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
609 }