annotate Python/modsupport.c @ 1263:65a1e4e9cd54 legacy-trunk

* Fixed some subtleties with fastlocals. You can no longer access f_fastlocals in a traceback object (this is a core dump hazard if there are <nil> entries), but instead eval_code() merges the fast locals back into the locals dictionary if it looks like the local variables will be retained. Also, the merge routines save exceptions since this is sometimes needed (alas!). * Added id() to bltinmodule.c, which returns an object's address (identity). Useful to walk arbitrary data structures containing cycles. * Added compile() to bltinmodule.c and compile_string() to pythonrun.[ch]: support to exec/eval arbitrary code objects. The code that defaults globals and locals is moved from run_node in pythonrun.c (which is now identical to eval_node) to eval_code in ceval.c. [XXX For elegance a clean-up session is necessary.]
author Guido van Rossum <guido@python.org>
date Tue, 30 Mar 1993 17:46:03 +0000
parents c4cd0d9d8281
children cd397266dc1c
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 /***********************************************************
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 initmodule(name, methods)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 char *name;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 struct methodlist *methods;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 object *m, *d, *v;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 struct methodlist *ml;
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
38 char *namebuf;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
39 if ((m = add_module(name)) == NULL) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 fprintf(stderr, "initializing module: %s\n", name);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 fatal("can't create a module");
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 d = getmoduledict(m);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 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
45 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
46 if (namebuf == NULL)
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
47 fatal("out of mem for method name");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
48 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
49 v = newmethodobject(namebuf, ml->ml_meth,
488
90f35fcf8ea0 Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents: 372
diff changeset
50 (object *)NULL, ml->ml_varargs);
1177
533e36de1e4d * Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents: 998
diff changeset
51 /* XXX The malloc'ed memory in namebuf is never freed */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 fprintf(stderr, "initializing module: %s\n", name);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 fatal("can't initialize module");
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 DECREF(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 12
diff changeset
58 return m;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
62 /* 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
63
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
64 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
65 static int countformat(format, endchar)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
66 char *format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
67 int endchar;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
68 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
69 int count = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
70 int level = 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
71 while (level > 0 || *format != endchar) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
72 if (*format == '\0') {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
73 /* Premature end */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
74 err_setstr(SystemError, "unmatched paren in format");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
75 return -1;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
76 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
77 else if (*format == '(') {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
78 if (level == 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
79 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
80 level++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
81 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
82 else if (*format == ')')
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
83 level--;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
84 else if (level == 0 && *format != '#')
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
85 count++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
86 format++;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
87 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
88 return count;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
89 }
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
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
92 /* Generic argument list parser */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
94 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
95 static int
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
96 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
97 object *arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
98 char** p_format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
99 va_list *p_va;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
101 char *format = *p_format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
102 va_list va = *p_va;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
103
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
104 if (arg == NULL)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
105 return 0; /* Incomplete tuple or list */
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
106
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
107 switch (*format++) {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
108
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
109 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
110 int i, n;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
111 if (!is_tupleobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
112 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
113 n = gettuplesize(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
114 for (i = 0; i < n; i++) {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
115 if (!do_arg(gettupleitem(arg, i), &format, &va))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
116 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
117 }
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
118 if (*format++ != ')')
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
119 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
120 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
121 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
122
998
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
123 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
124 return 0;
09b48604855f suppress unnecessary error message if too many arguments are passed
Guido van Rossum <guido@python.org>
parents: 957
diff changeset
125
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
126 case 'b': /* byte -- very short int */ {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
127 char *p = va_arg(va, char *);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
128 if (is_intobject(arg))
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
129 *p = getintvalue(arg);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
130 else
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
131 return 0;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
132 break;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
133 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
134
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
135 case 'h': /* short int */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
136 short *p = va_arg(va, short *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
137 if (is_intobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
138 *p = getintvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
139 else
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 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
143
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
144 case 'i': /* int */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
145 int *p = va_arg(va, int *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
146 if (is_intobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
147 *p = getintvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
148 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
149 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
150 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
151 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
152
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
153 case 'l': /* long int */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
154 long *p = va_arg(va, long *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
155 if (is_intobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
156 *p = getintvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
157 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
158 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
159 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
160 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
161
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
162 case 'f': /* float */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
163 float *p = va_arg(va, float *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
164 if (is_floatobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
165 *p = getfloatvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
166 else if (is_intobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
167 *p = (float)getintvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
168 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
169 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
170 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
171 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
172
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
173 case 'd': /* double */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
174 double *p = va_arg(va, double *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
175 if (is_floatobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
176 *p = getfloatvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
177 else if (is_intobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
178 *p = (double)getintvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
179 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
180 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
181 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
182 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
183
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
184 case 'c': /* char */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
185 char *p = va_arg(va, char *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
186 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
187 *p = getstringvalue(arg)[0];
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
188 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
189 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
190 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
191 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
192
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
193 case 's': /* string */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
194 char **p = va_arg(va, char **);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
195 if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
196 *p = getstringvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
197 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
198 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
199 if (*format == '#') {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
200 int *q = va_arg(va, int *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
201 *q = getstringsize(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
202 format++;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
203 }
957
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
204 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
205 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
206 return 0;
5c6cdb58a801 check for embedded \0 in strings for z and s formats
Guido van Rossum <guido@python.org>
parents: 860
diff changeset
207 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
208 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
209 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
210
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
211 case 'z': /* string, may be NULL (None) */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
212 char **p = va_arg(va, char **);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
213 if (arg == None)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
214 *p = 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
215 else if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
216 *p = getstringvalue(arg);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
217 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
218 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
219 if (*format == '#') {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
220 int *q = va_arg(va, int *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
221 if (arg == None)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
222 *q = 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
223 else
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 (*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
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 'S': /* string object */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
235 object **p = va_arg(va, object **);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
236 if (is_stringobject(arg))
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
237 *p = arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
238 else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
239 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
240 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
241 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
242
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
243 case 'O': /* object */ {
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
244 object **p = va_arg(va, object **);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
245 *p = arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
246 break;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
247 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
249 default:
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
250 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
251 format[-1], format[-1]);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
252 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
253
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 }
637
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 *p_va = va;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
257 *p_format = format;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
258
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
262 #ifdef USE_STDARG
733
f179d8d5ee8c Shut up lint
Guido van Rossum <guido@python.org>
parents: 637
diff changeset
263 /* VARARGS2 */
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
264 int getargs(object *arg, char *format, ...)
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
265 #else
733
f179d8d5ee8c Shut up lint
Guido van Rossum <guido@python.org>
parents: 637
diff changeset
266 /* VARARGS */
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
267 int getargs(va_alist) va_dcl
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
268 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
270 char *f;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
271 int ok;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
272 va_list va;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
273 #ifdef USE_STDARG
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
274
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
275 va_start(va, format);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
276 #else
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
277 object *arg;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
278 char *format;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
280 va_start(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
281 arg = va_arg(va, object *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
282 format = va_arg(va, char *);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
283 #endif
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
284 if (*format == '\0' || *format == ';') {
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
285 va_end(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
286 if (arg != NULL) {
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
287 char *str = "no arguments needed";
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
288 if (*format == ';')
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
289 str = format+1;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
290 err_setstr(TypeError, str);
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
291 return 0;
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
292 }
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
293 return 1;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
295
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
296 f = format;
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
297 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
298 va_end(va);
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
299 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
300 if (!err_occurred()) {
1211
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
301 char buf[256];
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
302 char *str;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
303 f = strchr(format, ';');
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
304 if (f != NULL)
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
305 str = f+1;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
306 else {
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
307 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
308 format);
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
309 str = buf;
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
310 }
406860dfaac7 * stdwinmodule.c: various new commands: setwin{pos,size},
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
311 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
312 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 }
637
3cb686c48cdd New getargs() function: a single varargs function,
Guido van Rossum <guido@python.org>
parents: 488
diff changeset
314 return ok;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 getlongtuplearg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 long *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 if (!is_tupleobject(args) || gettuplesize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 object *v = gettupleitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 getshorttuplearg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 short *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 if (!is_tupleobject(args) || gettuplesize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 object *v = gettupleitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 getlonglistarg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 long *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 if (!is_listobject(args) || getlistsize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 return err_badarg();
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 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 object *v = getlistitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 return 1;
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 getshortlistarg(args, a, n)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 short *a; /* [n] */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 int n;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 int i;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 if (!is_listobject(args) || getlistsize(args) != n) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 return err_badarg();
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 for (i = 0; i < n; i++) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 object *v = getlistitem(args, i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 if (!is_intobject(v)) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 return err_badarg();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 a[i] = getintvalue(v);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 return 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
396
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
397
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
398 /* 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
399 /* 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
400
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
401 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
402 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
403
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
404 static object *
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
405 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
406 char **p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
407 va_list *p_va;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
408 int endchar;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
409 int n;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
410 {
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
411 object *v;
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
412 int i;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
413 if (n < 0)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
414 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
415 if ((v = newtupleobject(n)) == NULL)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
416 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
417 for (i = 0; i < n; i++) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
418 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
419 if (w == NULL) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
420 DECREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
421 return NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
422 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
423 settupleitem(v, i, w);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
424 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
425 if (v != NULL && **p_format != endchar) {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
426 DECREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
427 v = NULL;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
428 err_setstr(SystemError, "Unmatched paren in format");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
429 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
430 else if (endchar)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
431 ++*p_format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
432 return v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
433 }
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
434
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
435 static object *
860
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
436 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
437 char **p_format;
39134c99c923 Added parameter decls to do_mkvalue for non-template machines
Guido van Rossum <guido@python.org>
parents: 817
diff changeset
438 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
439 {
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
440
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
441 switch (*(*p_format)++) {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
442
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
443 case '(':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
444 return do_mktuple(p_format, p_va, ')',
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
445 countformat(*p_format, ')'));
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
446
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
447 case 'b':
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
448 case 'h':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
449 case 'i':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
450 return newintobject((long)va_arg(*p_va, int));
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
451
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
452 case 'l':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
453 return newintobject((long)va_arg(*p_va, long));
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
454
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
455 case 'f':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
456 case 'd':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
457 return newfloatobject((double)va_arg(*p_va, double));
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
458
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
459 case 'c':
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
460 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
461 char p[1];
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
462 p[0] = va_arg(*p_va, int);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
463 return newsizedstringobject(p, 1);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
464 }
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
465
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
466 case 's':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
467 case 'z':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
468 {
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
469 object *v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
470 char *str = va_arg(*p_va, char *);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
471 int n;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
472 if (**p_format == '#') {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
473 ++*p_format;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
474 n = va_arg(*p_va, int);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
475 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
476 else
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
477 n = -1;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
478 if (str == NULL) {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
479 v = None;
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
480 INCREF(v);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
481 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
482 else {
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
483 if (n < 0)
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
484 n = strlen(str);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
485 v = newsizedstringobject(str, n);
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
486 }
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
487 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
488 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
489
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
490 case 'S':
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
491 case 'O':
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
492 {
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
493 object *v;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
494 v = va_arg(*p_va, object *);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
495 if (v != NULL)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
496 INCREF(v);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
497 else if (!err_occurred())
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
498 /* 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
499 that should have constructed a value
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
500 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
501 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
502 clear that the caller knew what she
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
503 was doing. */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
504 err_setstr(SystemError,
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
505 "NULL object passed to mkvalue");
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
506 return v;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
507 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
508
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
509 default:
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
510 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
511 return NULL;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
512
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
513 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
514 }
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
515
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
516 #ifdef USE_STDARG
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
517 /* VARARGS 2 */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
518 object *mkvalue(char *format, ...)
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
519 #else
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
520 /* VARARGS */
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
521 object *mkvalue(va_alist) va_dcl
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
522 #endif
816
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 va_list va;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
525 object* retval;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
526 #ifdef USE_STDARG
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
527 va_start(va, format);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
528 #else
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
529 char *format;
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
530 va_start(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
531 format = va_arg(va, char *);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
532 #endif
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
533 retval = vmkvalue(format, va);
817
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
534 va_end(va);
aa633f0defa6 Merged with Steve Miale's version
Guido van Rossum <guido@python.org>
parents: 816
diff changeset
535 return retval;
816
e4a27d84ea36 Added mkvalue() function
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
536 }
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
537
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
538 object *
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
539 vmkvalue(format, va)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
540 char *format;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
541 va_list va;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
542 {
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
543 char *f = format;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
544 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
545 if (n < 0)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
546 return NULL;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
547 if (n == 0) {
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
548 INCREF(None);
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
549 return None;
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
550 }
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
551 if (n == 1)
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1211
diff changeset
552 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
553 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
554 }