1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Abstract Object Interface (many thanks to Jim Fulton) */
37 /* Shorthands to return certain errors */
43 PyErr_SetString(PyExc_TypeError
, msg
);
50 if (!PyErr_Occurred())
51 PyErr_SetString(PyExc_SystemError
,
52 "null argument to internal routine");
56 /* Operations on any object */
59 PyObject_Cmp(o1
, o2
, result
)
66 if (o1
== NULL
|| o2
== NULL
) {
70 r
= PyObject_Compare(o1
, o2
);
85 v
= (PyObject
*)o
->ob_type
;
101 m
= o
->ob_type
->tp_as_sequence
;
102 if (m
&& m
->sq_length
)
103 return m
->sq_length(o
);
105 return PyMapping_Length(o
);
109 PyObject_GetItem(o
, key
)
115 if (o
== NULL
|| key
== NULL
)
118 m
= o
->ob_type
->tp_as_mapping
;
119 if (m
&& m
->mp_subscript
)
120 return m
->mp_subscript(o
, key
);
122 if (o
->ob_type
->tp_as_sequence
) {
123 if (PyInt_Check(key
))
124 return PySequence_GetItem(o
, PyInt_AsLong(key
));
125 return type_error("sequence index must be integer");
128 return type_error("unsubscriptable object");
132 PyObject_SetItem(o
, key
, value
)
139 if (o
== NULL
|| key
== NULL
|| value
== NULL
) {
143 m
= o
->ob_type
->tp_as_mapping
;
144 if (m
&& m
->mp_ass_subscript
)
145 return m
->mp_ass_subscript(o
, key
, value
);
147 if (o
->ob_type
->tp_as_sequence
) {
148 if (PyInt_Check(key
))
149 return PySequence_SetItem(o
, PyInt_AsLong(key
), value
);
150 type_error("sequence index must be integer");
154 type_error("object does not support item assignment");
159 PyObject_DelItem(o
, key
)
165 if (o
== NULL
|| key
== NULL
) {
169 m
= o
->ob_type
->tp_as_mapping
;
170 if (m
&& m
->mp_ass_subscript
)
171 return m
->mp_ass_subscript(o
, key
, (PyObject
*)NULL
);
173 if (o
->ob_type
->tp_as_sequence
) {
174 if (PyInt_Check(key
))
175 return PySequence_DelItem(o
, PyInt_AsLong(key
));
176 type_error("sequence index must be integer");
180 type_error("object does not support item deletion");
184 /* Operations on numbers */
190 return o
&& o
->ob_type
->tp_as_number
;
193 /* Binary operators */
195 #define BINOP(v, w, opname, ropname, thisfunc) \
196 if (PyInstance_Check(v) || PyInstance_Check(w)) \
197 return PyInstance_DoBinOp(v, w, opname, ropname, thisfunc)
203 extern int PyNumber_Coerce();
205 BINOP(v
, w
, "__or__", "__ror__", PyNumber_Or
);
206 if (v
->ob_type
->tp_as_number
!= NULL
) {
208 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
209 if (PyNumber_Coerce(&v
, &w
) != 0)
211 if ((f
= v
->ob_type
->tp_as_number
->nb_or
) != NULL
)
218 return type_error("bad operand type(s) for |");
225 extern int PyNumber_Coerce();
227 BINOP(v
, w
, "__xor__", "__rxor__", PyNumber_Xor
);
228 if (v
->ob_type
->tp_as_number
!= NULL
) {
230 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
231 if (PyNumber_Coerce(&v
, &w
) != 0)
233 if ((f
= v
->ob_type
->tp_as_number
->nb_xor
) != NULL
)
240 return type_error("bad operand type(s) for ^");
247 BINOP(v
, w
, "__and__", "__rand__", PyNumber_And
);
248 if (v
->ob_type
->tp_as_number
!= NULL
) {
250 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
251 if (PyNumber_Coerce(&v
, &w
) != 0)
253 if ((f
= v
->ob_type
->tp_as_number
->nb_and
) != NULL
)
260 return type_error("bad operand type(s) for &");
264 PyNumber_Lshift(v
, w
)
267 BINOP(v
, w
, "__lshift__", "__rlshift__", PyNumber_Lshift
);
268 if (v
->ob_type
->tp_as_number
!= NULL
) {
270 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
271 if (PyNumber_Coerce(&v
, &w
) != 0)
273 if ((f
= v
->ob_type
->tp_as_number
->nb_lshift
) != NULL
)
280 return type_error("bad operand type(s) for <<");
284 PyNumber_Rshift(v
, w
)
287 BINOP(v
, w
, "__rshift__", "__rrshift__", PyNumber_Rshift
);
288 if (v
->ob_type
->tp_as_number
!= NULL
) {
290 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
291 if (PyNumber_Coerce(&v
, &w
) != 0)
293 if ((f
= v
->ob_type
->tp_as_number
->nb_rshift
) != NULL
)
300 return type_error("bad operand type(s) for >>");
307 PySequenceMethods
*m
;
309 BINOP(v
, w
, "__add__", "__radd__", PyNumber_Add
);
310 m
= v
->ob_type
->tp_as_sequence
;
311 if (m
&& m
->sq_concat
)
312 return (*m
->sq_concat
)(v
, w
);
313 else if (v
->ob_type
->tp_as_number
!= NULL
) {
315 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
316 if (PyNumber_Coerce(&v
, &w
) != 0)
318 if ((f
= v
->ob_type
->tp_as_number
->nb_add
) != NULL
)
325 return type_error("bad operand type(s) for +");
329 PyNumber_Subtract(v
, w
)
332 BINOP(v
, w
, "__sub__", "__rsub__", PyNumber_Subtract
);
333 if (v
->ob_type
->tp_as_number
!= NULL
) {
335 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
336 if (PyNumber_Coerce(&v
, &w
) != 0)
338 if ((f
= v
->ob_type
->tp_as_number
->nb_subtract
) != NULL
)
345 return type_error("bad operand type(s) for -");
349 PyNumber_Multiply(v
, w
)
352 PyTypeObject
*tp
= v
->ob_type
;
353 PySequenceMethods
*m
;
355 BINOP(v
, w
, "__mul__", "__rmul__", PyNumber_Multiply
);
356 if (tp
->tp_as_number
!= NULL
&&
357 w
->ob_type
->tp_as_sequence
!= NULL
&&
358 !PyInstance_Check(v
)) {
359 /* number*sequence -- swap v and w */
365 if (tp
->tp_as_number
!= NULL
) {
367 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
368 if (PyInstance_Check(v
)) {
369 /* Instances of user-defined classes get their
370 other argument uncoerced, so they may
371 implement sequence*number as well as
376 else if (PyNumber_Coerce(&v
, &w
) != 0)
378 if ((f
= v
->ob_type
->tp_as_number
->nb_multiply
) != NULL
)
385 m
= tp
->tp_as_sequence
;
386 if (m
&& m
->sq_repeat
) {
389 "can't multiply sequence with non-int");
390 return (*m
->sq_repeat
)(v
, (int)PyInt_AsLong(w
));
392 return type_error("bad operand type(s) for *");
396 PyNumber_Divide(v
, w
)
399 BINOP(v
, w
, "__div__", "__rdiv__", PyNumber_Divide
);
400 if (v
->ob_type
->tp_as_number
!= NULL
) {
402 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
403 if (PyNumber_Coerce(&v
, &w
) != 0)
405 if ((f
= v
->ob_type
->tp_as_number
->nb_divide
) != NULL
)
412 return type_error("bad operand type(s) for /");
416 PyNumber_Remainder(v
, w
)
419 if (PyString_Check(v
))
420 return PyString_Format(v
, w
);
421 BINOP(v
, w
, "__mod__", "__rmod__", PyNumber_Remainder
);
422 if (v
->ob_type
->tp_as_number
!= NULL
) {
424 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
425 if (PyNumber_Coerce(&v
, &w
) != 0)
427 if ((f
= v
->ob_type
->tp_as_number
->nb_remainder
) != NULL
)
434 return type_error("bad operand type(s) for %");
438 PyNumber_Divmod(v
, w
)
441 BINOP(v
, w
, "__divmod__", "__rdivmod__", PyNumber_Divmod
);
442 if (v
->ob_type
->tp_as_number
!= NULL
) {
444 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*));
445 if (PyNumber_Coerce(&v
, &w
) != 0)
447 if ((f
= v
->ob_type
->tp_as_number
->nb_divmod
) != NULL
)
454 return type_error("bad operand type(s) for divmod()");
457 /* Power (binary or ternary) */
464 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*, PyObject
*));
465 BINOP(v
, w
, "__pow__", "__rpow__", do_pow
);
466 if (v
->ob_type
->tp_as_number
== NULL
||
467 w
->ob_type
->tp_as_number
== NULL
) {
468 PyErr_SetString(PyExc_TypeError
,
469 "pow(x, y) requires numeric arguments");
472 if (PyNumber_Coerce(&v
, &w
) != 0)
474 if ((f
= v
->ob_type
->tp_as_number
->nb_power
) != NULL
)
475 res
= (*f
)(v
, w
, Py_None
);
477 res
= type_error("pow(x, y) not defined for these operands");
484 PyNumber_Power(v
, w
, z
)
488 PyObject
*v1
, *z1
, *w2
, *z2
;
489 PyObject
* (*f
) Py_FPROTO((PyObject
*, PyObject
*, PyObject
*));
493 /* XXX The ternary version doesn't do class instance coercions */
494 if (PyInstance_Check(v
))
495 return v
->ob_type
->tp_as_number
->nb_power(v
, w
, z
);
496 if (v
->ob_type
->tp_as_number
== NULL
||
497 z
->ob_type
->tp_as_number
== NULL
||
498 w
->ob_type
->tp_as_number
== NULL
) {
499 return type_error("pow(x, y, z) requires numeric arguments");
501 if (PyNumber_Coerce(&v
, &w
) != 0)
506 if (PyNumber_Coerce(&v1
, &z1
) != 0)
510 if (PyNumber_Coerce(&w2
, &z2
) != 0)
512 if ((f
= v1
->ob_type
->tp_as_number
->nb_power
) != NULL
)
513 res
= (*f
)(v1
, w2
, z2
);
516 "pow(x, y, z) not defined for these operands");
528 /* Unary operators and functions */
538 m
= o
->ob_type
->tp_as_number
;
539 if (m
&& m
->nb_negative
)
540 return (*m
->nb_negative
)(o
);
542 return type_error("bad operand type for unary -");
553 m
= o
->ob_type
->tp_as_number
;
554 if (m
&& m
->nb_positive
)
555 return (*m
->nb_positive
)(o
);
557 return type_error("bad operand type for unary +");
568 m
= o
->ob_type
->tp_as_number
;
569 if (m
&& m
->nb_invert
)
570 return (*m
->nb_invert
)(o
);
572 return type_error("bad operand type for unary ~");
583 m
= o
->ob_type
->tp_as_number
;
584 if (m
&& m
->nb_absolute
)
585 return m
->nb_absolute(o
);
587 return type_error("bad operand type for abs()");
598 if (PyString_Check(o
))
599 return PyInt_FromString(PyString_AS_STRING(o
), NULL
, 10);
600 m
= o
->ob_type
->tp_as_number
;
604 return type_error("object can't be converted to int");
607 /* There are two C API functions for converting a string to a long,
608 * PyNumber_Long() and PyLong_FromString(). Both are used in builtin_long,
609 * reachable from Python with the built-in function long().
611 * The difference is this: PyNumber_Long will raise an exception when the
612 * string cannot be converted to a long. The most common situation is
613 * where a float string is passed in; this raises a ValueError.
614 * PyLong_FromString does not raise an exception; it silently truncates the
615 * float to an integer.
617 * You can see the different behavior from Python with the following:
620 * => ValueError: invalid literal for long(): 9.5
625 * The first example ends up calling PyNumber_Long(), while the second one
626 * calls PyLong_FromString().
634 char buffer
[256]; /* For errors */
636 s
= PyString_AS_STRING(v
);
637 while (*s
&& isspace(Py_CHARMASK(*s
)))
639 x
= PyLong_FromString(s
, &end
, 10);
641 if (PyErr_ExceptionMatches(PyExc_ValueError
))
645 while (*end
&& isspace(Py_CHARMASK(*end
)))
649 sprintf(buffer
, "invalid literal for long(): %.200s", s
);
650 PyErr_SetString(PyExc_ValueError
, buffer
);
654 else if (end
!= PyString_AS_STRING(v
) + PyString_GET_SIZE(v
)) {
655 PyErr_SetString(PyExc_ValueError
,
656 "null byte in argument for long()");
670 if (PyString_Check(o
))
671 /* need to do extra error checking that PyLong_FromString()
672 * doesn't do. In particular long('9.5') must raise an
673 * exception, not truncate the float.
675 return long_from_string(o
);
676 m
= o
->ob_type
->tp_as_number
;
678 return m
->nb_long(o
);
680 return type_error("object can't be converted to long");
691 if (PyString_Check(o
))
692 return PyFloat_FromString(o
, NULL
);
693 m
= o
->ob_type
->tp_as_number
;
694 if (m
&& m
->nb_float
)
695 return m
->nb_float(o
);
697 return type_error("object can't be converted to float");
700 /* Operations on sequences */
706 return s
!= NULL
&& s
->ob_type
->tp_as_sequence
;
713 PySequenceMethods
*m
;
720 m
= s
->ob_type
->tp_as_sequence
;
721 if (m
&& m
->sq_length
)
722 return m
->sq_length(s
);
724 type_error("len() of unsized object");
729 PySequence_Concat(s
, o
)
733 PySequenceMethods
*m
;
735 if (s
== NULL
|| o
== NULL
)
738 m
= s
->ob_type
->tp_as_sequence
;
739 if (m
&& m
->sq_concat
)
740 return m
->sq_concat(s
, o
);
742 return type_error("object can't be concatenated");
746 PySequence_Repeat(o
, count
)
750 PySequenceMethods
*m
;
755 m
= o
->ob_type
->tp_as_sequence
;
756 if (m
&& m
->sq_repeat
)
757 return m
->sq_repeat(o
, count
);
759 return type_error("object can't be repeated");
763 PySequence_GetItem(s
, i
)
767 PySequenceMethods
*m
;
772 m
= s
->ob_type
->tp_as_sequence
;
773 if (m
&& m
->sq_item
) {
776 int l
= (*m
->sq_length
)(s
);
782 return m
->sq_item(s
, i
);
785 return type_error("unindexable object");
789 PySequence_GetSlice(s
, i1
, i2
)
794 PySequenceMethods
*m
;
796 if (!s
) return null_error();
798 m
= s
->ob_type
->tp_as_sequence
;
799 if (m
&& m
->sq_slice
) {
800 if (i1
< 0 || i2
< 0) {
802 int l
= (*m
->sq_length
)(s
);
811 return m
->sq_slice(s
, i1
, i2
);
814 return type_error("unsliceable object");
818 PySequence_SetItem(s
, i
, o
)
823 PySequenceMethods
*m
;
830 m
= s
->ob_type
->tp_as_sequence
;
831 if (m
&& m
->sq_ass_item
) {
834 int l
= (*m
->sq_length
)(s
);
840 return m
->sq_ass_item(s
, i
, o
);
843 type_error("object doesn't support item assignment");
848 PySequence_DelItem(s
, i
)
852 PySequenceMethods
*m
;
859 m
= s
->ob_type
->tp_as_sequence
;
860 if (m
&& m
->sq_ass_item
) {
863 int l
= (*m
->sq_length
)(s
);
869 return m
->sq_ass_item(s
, i
, (PyObject
*)NULL
);
872 type_error("object doesn't support item deletion");
877 PySequence_SetSlice(s
, i1
, i2
, o
)
883 PySequenceMethods
*m
;
890 m
= s
->ob_type
->tp_as_sequence
;
891 if (m
&& m
->sq_ass_slice
) {
892 if (i1
< 0 || i2
< 0) {
894 int l
= (*m
->sq_length
)(s
);
903 return m
->sq_ass_slice(s
, i1
, i2
, o
);
905 type_error("object doesn't support slice assignment");
910 PySequence_DelSlice(s
, i1
, i2
)
915 PySequenceMethods
*m
;
922 m
= s
->ob_type
->tp_as_sequence
;
923 if (m
&& m
->sq_ass_slice
) {
924 if (i1
< 0 || i2
< 0) {
926 int l
= (*m
->sq_length
)(s
);
935 return m
->sq_ass_slice(s
, i1
, i2
, (PyObject
*)NULL
);
937 type_error("object doesn't support slice deletion");
945 PySequenceMethods
*m
;
950 if (PyTuple_Check(v
)) {
956 return PyList_AsTuple(v
);
958 /* There used to be code for strings here, but tuplifying strings is
959 not a common activity, so I nuked it. Down with code bloat! */
961 /* Generic sequence object */
962 m
= v
->ob_type
->tp_as_sequence
;
963 if (m
&& m
->sq_item
) {
966 int n
= PySequence_Length(v
);
973 PyObject
*item
= (*m
->sq_item
)(v
, i
);
975 if (PyErr_ExceptionMatches(PyExc_IndexError
))
988 if (_PyTuple_Resize(&t
, n
, 0) != 0)
991 PyTuple_SET_ITEM(t
, i
, item
);
993 if (i
< n
&& t
!= NULL
)
994 _PyTuple_Resize(&t
, i
, 0);
998 /* None of the above */
999 return type_error("tuple() argument must be a sequence");
1006 PySequenceMethods
*m
;
1009 return null_error();
1011 if (PyList_Check(v
))
1012 return PyList_GetSlice(v
, 0, PyList_GET_SIZE(v
));
1014 m
= v
->ob_type
->tp_as_sequence
;
1015 if (m
&& m
->sq_item
) {
1018 int n
= PySequence_Length(v
);
1024 for (i
= 0; ; i
++) {
1025 PyObject
*item
= (*m
->sq_item
)(v
, i
);
1027 if (PyErr_ExceptionMatches(PyExc_IndexError
))
1036 PyList_SET_ITEM(l
, i
, item
);
1037 else if (PyList_Append(l
, item
) < 0) {
1043 if (i
< n
&& l
!= NULL
) {
1044 if (PyList_SetSlice(l
, i
, n
, (PyObject
*)NULL
) != 0) {
1051 return type_error("list() argument must be a sequence");
1055 PySequence_Count(s
, o
)
1059 int l
, i
, n
, cmp
, err
;
1062 if (s
== NULL
|| o
== NULL
) {
1067 l
= PySequence_Length(s
);
1072 for (i
= 0; i
< l
; i
++) {
1073 item
= PySequence_GetItem(s
, i
);
1076 err
= PyObject_Cmp(item
, o
, &cmp
);
1087 PySequence_Contains(w
, v
) /* v in w */
1093 PySequenceMethods
*sq
;
1095 /* Special case for char in string */
1096 if (PyString_Check(w
)) {
1097 register char *s
, *end
;
1099 if (!PyString_Check(v
) || PyString_Size(v
) != 1) {
1100 PyErr_SetString(PyExc_TypeError
,
1101 "string member test needs char left operand");
1104 c
= PyString_AsString(v
)[0];
1105 s
= PyString_AsString(w
);
1106 end
= s
+ PyString_Size(w
);
1114 sq
= w
->ob_type
->tp_as_sequence
;
1115 if (sq
== NULL
|| sq
->sq_item
== NULL
) {
1116 PyErr_SetString(PyExc_TypeError
,
1117 "'in' or 'not in' needs sequence right argument");
1121 for (i
= 0; ; i
++) {
1122 x
= (*sq
->sq_item
)(w
, i
);
1124 if (PyErr_ExceptionMatches(PyExc_IndexError
)) {
1130 cmp
= PyObject_Compare(v
, x
);
1134 if (PyErr_Occurred())
1141 /* Backwards compatibility */
1142 #undef PySequence_In
1148 return PySequence_Contains(w
, v
);
1152 PySequence_Index(s
, o
)
1159 if (s
== NULL
|| o
== NULL
) {
1164 l
= PySequence_Length(s
);
1168 for (i
= 0; i
< l
; i
++) {
1169 item
= PySequence_GetItem(s
, i
);
1172 err
= PyObject_Cmp(item
, o
, &cmp
);
1180 PyErr_SetString(PyExc_ValueError
, "sequence.index(x): x not in list");
1184 /* Operations on mappings */
1190 return o
&& o
->ob_type
->tp_as_mapping
;
1197 PyMappingMethods
*m
;
1204 m
= o
->ob_type
->tp_as_mapping
;
1205 if (m
&& m
->mp_length
)
1206 return m
->mp_length(o
);
1208 type_error("len() of unsized object");
1213 PyMapping_GetItemString(o
, key
)
1220 return null_error();
1222 okey
= PyString_FromString(key
);
1225 r
= PyObject_GetItem(o
, okey
);
1231 PyMapping_SetItemString(o
, key
, value
)
1244 okey
= PyString_FromString(key
);
1247 r
= PyObject_SetItem(o
, okey
, value
);
1253 PyMapping_HasKeyString(o
, key
)
1259 v
= PyMapping_GetItemString(o
, key
);
1269 PyMapping_HasKey(o
, key
)
1275 v
= PyObject_GetItem(o
, key
);
1284 /* Operations on callable objects */
1286 /* XXX PyCallable_Check() is in object.c */
1289 PyObject_CallObject(o
, a
)
1296 args
= PyTuple_New(0);
1301 r
= PyEval_CallObject(o
, args
);
1311 #ifdef HAVE_STDARG_PROTOTYPES
1313 PyObject_CallFunction(PyObject
*callable
, char *format
, ...)
1316 PyObject_CallFunction(va_alist
) va_dcl
1320 PyObject
*args
, *retval
;
1321 #ifdef HAVE_STDARG_PROTOTYPES
1322 va_start(va
, format
);
1327 callable
= va_arg(va
, PyObject
*);
1328 format
= va_arg(va
, char *);
1331 if (callable
== NULL
) {
1333 return null_error();
1337 args
= Py_VaBuildValue(format
, va
);
1339 args
= PyTuple_New(0);
1346 if (!PyTuple_Check(args
)) {
1352 if (PyTuple_SetItem(a
, 0, args
) < 0)
1356 retval
= PyObject_CallObject(callable
, args
);
1364 #ifdef HAVE_STDARG_PROTOTYPES
1366 PyObject_CallMethod(PyObject
*o
, char *name
, char *format
, ...)
1369 PyObject_CallMethod(va_alist
) va_dcl
1373 PyObject
*args
, *func
= 0, *retval
;
1374 #ifdef HAVE_STDARG_PROTOTYPES
1375 va_start(va
, format
);
1381 o
= va_arg(va
, PyObject
*);
1382 name
= va_arg(va
, char *);
1383 format
= va_arg(va
, char *);
1386 if (o
== NULL
|| name
== NULL
) {
1388 return null_error();
1391 func
= PyObject_GetAttrString(o
, name
);
1394 PyErr_SetString(PyExc_AttributeError
, name
);
1398 if (!PyCallable_Check(func
)) {
1400 return type_error("call of non-callable attribute");
1403 if (format
&& *format
)
1404 args
= Py_VaBuildValue(format
, va
);
1406 args
= PyTuple_New(0);
1413 if (!PyTuple_Check(args
)) {
1419 if (PyTuple_SetItem(a
, 0, args
) < 0)
1424 retval
= PyObject_CallObject(func
, args
);