Mercurial > cpython-lru_cache-weakref
annotate Objects/abstract.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 5ffab65f8d05 |
| children | 1f1f949505af |
| rev | line source |
|---|---|
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 The Netherlands. |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
15 permission. |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4344
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 ******************************************************************/ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 /* Abstract Object Interface (many thanks to Jim Fulton) */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 #include "Python.h" |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #define Py_TRY(E) if(!(E)) return NULL |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 #define Py_ASSERT(EXP,E,V) if(!(EXP)) return PyErr_SetString(E,V), (void*)NULL |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 #define SPAM printf("line %d\n",__LINE__) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 static PyObject * |
| 3097 | 41 Py_ReturnMethodError(name) |
| 42 char *name; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 if(! name) name = "Unknown Error"; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 PyErr_SetString(PyExc_AttributeError,name); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
4529
337562330fd0
Make Py_ReturnNullError() statis as it should be.
Guido van Rossum <guido@python.org>
parents:
4528
diff
changeset
|
49 static PyObject * |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 Py_ReturnNullError() |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 if(! PyErr_Occurred()) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 PyErr_SetString(PyExc_SystemError, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 "null argument to internal routine"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 int |
| 3097 | 59 PyObject_Cmp(o1, o2, result) |
| 60 PyObject *o1; | |
| 61 PyObject *o2; | |
| 62 int *result; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 int r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 if(! o1 || ! o2) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 r=PyObject_Compare(o1,o2); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 if(PyErr_Occurred()) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 *result=r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 #if 0 /* Already in object.c */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 int |
| 3097 | 75 PyCallable_Check(x) |
| 76 PyObject *x; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 if (x == NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 if (x->ob_type->tp_call != NULL || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 PyFunction_Check(x) || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 PyMethod_Check(x) || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 PyCFunction_Check(x) || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 PyClass_Check(x)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 return 1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 if (PyInstance_Check(x)) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 PyObject *call = PyObject_GetAttrString(x, "__call__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 if (call == NULL) { |
| 3097 | 89 PyErr_Clear(); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 /* Could test recursively but don't, for fear of endless |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 recursion if some joker sets self.__call__ = self */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 Py_DECREF(call); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return 1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 #endif |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 PyObject * |
| 3097 | 102 PyObject_Type(o) |
| 103 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 v = (PyObject *)o->ob_type; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 Py_INCREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 return v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 int |
| 3097 | 114 PyObject_Length(o) |
| 115 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 if(! o) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 if((m=o->ob_type->tp_as_sequence) && m->sq_length) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 return m->sq_length(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 return PyMapping_Length(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 PyObject * |
| 3097 | 128 PyObject_GetItem(o, key) |
| 129 PyObject *o; | |
| 130 PyObject *key; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 PyMappingMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 if(! o || ! key) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 if((m=o->ob_type->tp_as_mapping) && m->mp_subscript) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 return m->mp_subscript(o,key); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 if(PyInt_Check(key)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 return PySequence_GetItem(o,PyInt_AsLong(key)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 PyErr_SetString(PyExc_TypeError,"expected integer index"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 int |
| 3097 | 147 PyObject_SetItem(o, key, value) |
| 148 PyObject *o; | |
| 149 PyObject *key; | |
| 150 PyObject *value; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 PyMappingMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 if(! o || ! key || ! value) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 if((m=o->ob_type->tp_as_mapping) && m->mp_ass_subscript) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 return m->mp_ass_subscript(o,key,value); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 if(PyInt_Check(key)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 return PySequence_SetItem(o,PyInt_AsLong(key),value); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
161 PyErr_SetString(PyExc_TypeError,"expected integer index"); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
4090
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
165 int |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
166 PyObject_DelItem(o, key) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
167 PyObject *o; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
168 PyObject *key; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
169 { |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
170 PyMappingMethods *m; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
171 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
172 if(! o || ! key) return Py_ReturnNullError(),-1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
173 if((m=o->ob_type->tp_as_mapping) && m->mp_ass_subscript) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
174 return m->mp_ass_subscript(o,key,(PyObject*)NULL); |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
175 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
176 if(PyInt_Check(key)) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
177 return PySequence_SetItem(o,PyInt_AsLong(key),(PyObject*)NULL); |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
178 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
179 PyErr_SetString(PyExc_TypeError,"expected integer index"); |
|
4090
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
180 return -1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
181 } |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
182 |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 int |
| 3097 | 184 PyNumber_Check(o) |
| 185 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 return o && o->ob_type->tp_as_number; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 #define BINOP(opname, ropname, thisfunc) \ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 if (!PyInstance_Check(v) && !PyInstance_Check(w)) \ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 ; \ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 else \ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 return PyInstance_DoBinOp(v, w, opname, ropname, thisfunc) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 PyNumber_Or(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 extern int PyNumber_Coerce(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 BINOP("__or__", "__ror__", PyNumber_Or); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 if (v->ob_type->tp_as_number != NULL) { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
205 PyObject *x = NULL; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 PyObject * (*f) Py_FPROTO((PyObject *, PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 if ((f = v->ob_type->tp_as_number->nb_or) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 x = (*f)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 if (f != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for |"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 PyNumber_Xor(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 extern int PyNumber_Coerce(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 BINOP("__xor__", "__rxor__", PyNumber_Xor); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 if (v->ob_type->tp_as_number != NULL) { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
228 PyObject *x = NULL; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 PyObject * (*f) Py_FPROTO((PyObject *, PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 if ((f = v->ob_type->tp_as_number->nb_xor) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 x = (*f)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 if (f != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for ^"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 PyNumber_And(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 BINOP("__and__", "__rand__", PyNumber_And); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 if (v->ob_type->tp_as_number != NULL) { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
249 PyObject *x = NULL; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 PyObject * (*f) Py_FPROTO((PyObject *, PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 if ((f = v->ob_type->tp_as_number->nb_and) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 x = (*f)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 if (f != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for &"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 PyNumber_Lshift(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 BINOP("__lshift__", "__rlshift__", PyNumber_Lshift); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 if (v->ob_type->tp_as_number != NULL) { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
270 PyObject *x = NULL; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 PyObject * (*f) Py_FPROTO((PyObject *, PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 if ((f = v->ob_type->tp_as_number->nb_lshift) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 x = (*f)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 if (f != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for <<"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 PyNumber_Rshift(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 BINOP("__rshift__", "__rrshift__", PyNumber_Rshift); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 if (v->ob_type->tp_as_number != NULL) { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
291 PyObject *x = NULL; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 PyObject * (*f) Py_FPROTO((PyObject *, PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 if ((f = v->ob_type->tp_as_number->nb_rshift) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 x = (*f)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 if (f != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for >>"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 PyNumber_Add(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 BINOP("__add__", "__radd__", PyNumber_Add); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 if (v->ob_type->tp_as_sequence != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 return (*v->ob_type->tp_as_sequence->sq_concat)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 else if (v->ob_type->tp_as_number != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 PyObject *x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 x = (*v->ob_type->tp_as_number->nb_add)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for +"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 PyNumber_Subtract(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 BINOP("__sub__", "__rsub__", PyNumber_Subtract); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 if (v->ob_type->tp_as_number != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 PyObject *x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 x = (*v->ob_type->tp_as_number->nb_subtract)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for -"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 PyNumber_Multiply(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 PyTypeObject *tp; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 tp = v->ob_type; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 BINOP("__mul__", "__rmul__", PyNumber_Multiply); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 if (tp->tp_as_number != NULL && |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 w->ob_type->tp_as_sequence != NULL && |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 !PyInstance_Check(v)) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 /* number*sequence -- swap v and w */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 PyObject *tmp = v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 v = w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 w = tmp; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 tp = v->ob_type; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 if (tp->tp_as_number != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 PyObject *x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 if (PyInstance_Check(v)) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 /* Instances of user-defined classes get their |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 other argument uncoerced, so they may |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 implement sequence*number as well as |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 number*number. */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 Py_INCREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 Py_INCREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 else if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 x = (*v->ob_type->tp_as_number->nb_multiply)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 if (tp->tp_as_sequence != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 if (!PyInt_Check(w)) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 PyErr_SetString(PyExc_TypeError, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 "can't multiply sequence with non-int"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 return (*tp->tp_as_sequence->sq_repeat) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 (v, (int)PyInt_AsLong(w)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for *"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 PyNumber_Divide(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 BINOP("__div__", "__rdiv__", PyNumber_Divide); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 if (v->ob_type->tp_as_number != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 PyObject *x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 x = (*v->ob_type->tp_as_number->nb_divide)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for /"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 PyNumber_Remainder(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 if (PyString_Check(v)) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 return PyString_Format(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 BINOP("__mod__", "__rmod__", PyNumber_Remainder); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 if (v->ob_type->tp_as_number != NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 PyObject *x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 x = (*v->ob_type->tp_as_number->nb_remainder)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 return x; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for %"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 PyNumber_Divmod(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 PyObject *res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 if (PyInstance_Check(v) || PyInstance_Check(w)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 return PyInstance_DoBinOp(v, w, "__divmod__", "__rdivmod__", |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 PyNumber_Divmod); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 if (v->ob_type->tp_as_number == NULL || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 w->ob_type->tp_as_number == NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 PyErr_SetString(PyExc_TypeError, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 "divmod() requires numeric or class instance arguments"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 res = (*v->ob_type->tp_as_number->nb_divmod)(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
447 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 return res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 static PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 do_pow(v, w) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 PyObject *v, *w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 PyObject *res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 if (PyInstance_Check(v) || PyInstance_Check(w)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 return PyInstance_DoBinOp(v, w, "__pow__", "__rpow__", do_pow); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 if (v->ob_type->tp_as_number == NULL || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 w->ob_type->tp_as_number == NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 PyErr_SetString(PyExc_TypeError, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 "pow() requires numeric arguments"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 if (PyFloat_Check(w) && PyFloat_AsDouble(v) < 0.0) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 if (!PyErr_Occurred()) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 PyErr_SetString(PyExc_ValueError, |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 "negative number to float power"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 res = (*v->ob_type->tp_as_number->nb_power)(v, w, Py_None); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 return res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 PyNumber_Power(v,w,z) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 PyObject *v, *w, *z; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 PyObject *res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
485 PyObject *v1, *z1, *w2, *z2; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 if (z == Py_None) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 return do_pow(v, w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
489 /* XXX The ternary version doesn't do class instance coercions */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 if (PyInstance_Check(v)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 return v->ob_type->tp_as_number->nb_power(v, w, z); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 if (v->ob_type->tp_as_number == NULL || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 z->ob_type->tp_as_number == NULL || |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
494 w->ob_type->tp_as_number == NULL) { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
495 PyErr_SetString(PyExc_TypeError, "pow() requires numeric arguments"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
497 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 if (PyNumber_Coerce(&v, &w) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 res = NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 v1 = v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 z1 = z; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 if (PyNumber_Coerce(&v1, &z1) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 goto error2; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 w2 = w; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 z2 = z1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 if (PyNumber_Coerce(&w2, &z2) != 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
508 goto error1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 res = (*v1->ob_type->tp_as_number->nb_power)(v1, w2, z2); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 Py_DECREF(w2); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 Py_DECREF(z2); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 error1: |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 Py_DECREF(v1); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 Py_DECREF(z1); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 error2: |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 Py_DECREF(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 Py_DECREF(w); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 return res; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 PyNumber_Negative(v) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 if (v->ob_type->tp_as_number != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 return (*v->ob_type->tp_as_number->nb_negative)(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary -"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
532 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 PyNumber_Positive(v) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 if (v->ob_type->tp_as_number != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 return (*v->ob_type->tp_as_number->nb_positive)(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
538 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary +"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
542 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
543 PyNumber_Invert(v) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
546 PyObject * (*f) Py_FPROTO((PyObject *)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 if (v->ob_type->tp_as_number != NULL && |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 (f = v->ob_type->tp_as_number->nb_invert) != NULL) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 return (*f)(v); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary ~"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
551 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
552 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
553 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 PyObject * |
| 3097 | 555 PyNumber_Absolute(o) |
| 556 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
558 PyNumberMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
559 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
560 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
561 if((m=o->ob_type->tp_as_number) && m->nb_absolute) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
562 return m->nb_absolute(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
563 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 return Py_ReturnMethodError("__abs__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
565 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 PyObject * |
| 3097 | 568 PyNumber_Int(o) |
| 569 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
570 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 PyNumberMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
574 if((m=o->ob_type->tp_as_number) && m->nb_int) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
575 return m->nb_int(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
576 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
577 return Py_ReturnMethodError("__int__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
579 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 PyObject * |
| 3097 | 581 PyNumber_Long(o) |
| 582 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 PyNumberMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 if((m=o->ob_type->tp_as_number) && m->nb_long) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 return m->nb_long(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 return Py_ReturnMethodError("__long__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 PyObject * |
| 3097 | 594 PyNumber_Float(o) |
| 595 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
597 PyNumberMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
598 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
600 if((m=o->ob_type->tp_as_number) && m->nb_float) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 return m->nb_float(o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
603 return Py_ReturnMethodError("__float__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
604 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
605 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 int |
| 3097 | 608 PySequence_Check(o) |
| 609 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 return o && o->ob_type->tp_as_sequence; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 int |
| 3097 | 615 PySequence_Length(s) |
| 616 PyObject *s; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 if(! s) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 if((m=s->ob_type->tp_as_sequence) && m->sq_length) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 return m->sq_length(s); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 Py_ReturnMethodError("__len__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 PyObject * |
| 3097 | 630 PySequence_Concat(s, o) |
| 631 PyObject *s; | |
| 632 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 if(! s || ! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 if((m=s->ob_type->tp_as_sequence) && m->sq_concat) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 return m->sq_concat(s,o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 return Py_ReturnMethodError("__concat__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 PyObject * |
| 3097 | 645 PySequence_Repeat(o, count) |
| 646 PyObject *o; | |
| 647 int count; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
650 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 if(! o) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
652 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
653 if((m=o->ob_type->tp_as_sequence) && m->sq_repeat) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 return m->sq_repeat(o,count); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 return Py_ReturnMethodError("__repeat__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
658 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 PyObject * |
| 3097 | 660 PySequence_GetItem(s, i) |
| 661 PyObject *s; | |
| 662 int i; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 int l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
667 if(! s) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
668 |
|
4528
2824cbdbe12c
Only call sq_length in Sequence_GetItem for negative index.
Guido van Rossum <guido@python.org>
parents:
4515
diff
changeset
|
669 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_item)) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
670 return Py_ReturnMethodError("__getitem__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 |
|
4528
2824cbdbe12c
Only call sq_length in Sequence_GetItem for negative index.
Guido van Rossum <guido@python.org>
parents:
4515
diff
changeset
|
672 if(i < 0) |
|
2824cbdbe12c
Only call sq_length in Sequence_GetItem for negative index.
Guido van Rossum <guido@python.org>
parents:
4515
diff
changeset
|
673 { |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
674 if(! m->sq_length || 0 > (l=m->sq_length(s))) return NULL; |
|
4528
2824cbdbe12c
Only call sq_length in Sequence_GetItem for negative index.
Guido van Rossum <guido@python.org>
parents:
4515
diff
changeset
|
675 i += l; |
|
2824cbdbe12c
Only call sq_length in Sequence_GetItem for negative index.
Guido van Rossum <guido@python.org>
parents:
4515
diff
changeset
|
676 } |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
677 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
678 return m->sq_item(s,i); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
679 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
680 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
681 PyObject * |
| 3097 | 682 PySequence_GetSlice(s, i1, i2) |
| 683 PyObject *s; | |
| 684 int i1; | |
| 685 int i2; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 int l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 if(! s) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
692 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_slice)) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 return Py_ReturnMethodError("__getslice__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
695 if(i1 < 0 || i2 < 0) |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
696 { |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
698 if(! m->sq_length || 0 > (l=m->sq_length(s))) return NULL; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
699 |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
700 if(i1 < 0) i1 += l; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
701 if(i2 < 0) i2 += l; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
702 } |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 return m->sq_slice(s,i1,i2); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 int |
| 3097 | 708 PySequence_SetItem(s, i, o) |
| 709 PyObject *s; | |
| 710 int i; | |
| 711 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 int l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 if(! s) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_item)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 return Py_ReturnMethodError("__setitem__"),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 if(i < 0) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 if(0 > (l=m->sq_length(s))) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 i += l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 return m->sq_ass_item(s,i,o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 |
|
4090
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
729 int |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
730 PySequence_DelItem(s, i) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
731 PyObject *s; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
732 int i; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
733 { |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
734 PySequenceMethods *m; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
735 int l; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
736 if(! s) return Py_ReturnNullError(),-1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
737 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
738 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_item)) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
739 return Py_ReturnMethodError("__delitem__"),-1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
740 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
741 if(i < 0) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
742 { |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
743 if(0 > (l=m->sq_length(s))) return -1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
744 i += l; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
745 } |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
746 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
747 return m->sq_ass_item(s,i,(PyObject*)NULL); |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
748 } |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
749 |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 int |
| 3097 | 751 PySequence_SetSlice(s, i1, i2, o) |
| 752 PyObject *s; | |
| 753 int i1; | |
| 754 int i2; | |
| 755 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
756 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 PySequenceMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
758 int l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
760 if(! s) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
762 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_slice)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
763 return Py_ReturnMethodError("__setslice__"),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
764 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
765 if(0 > (l=m->sq_length(s))) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
766 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 if(i1 < 0) i1 += l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 if(i2 < 0) i2 += l; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
769 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
770 return m->sq_ass_slice(s,i1,i2,o); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 |
|
4090
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
773 int |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
774 PySequence_DelSlice(s, i1, i2) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
775 PyObject *s; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
776 int i1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
777 int i2; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
778 { |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
779 PySequenceMethods *m; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
780 int l; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
781 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
782 if(! s) return Py_ReturnNullError(),-1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
783 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
784 if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_slice)) |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
785 return Py_ReturnMethodError("__delslice__"),-1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
786 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
787 if(0 > (l=m->sq_length(s))) return -1; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
788 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
789 if(i1 < 0) i1 += l; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
790 if(i2 < 0) i2 += l; |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
791 |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
792 return m->sq_ass_slice(s,i1,i2,(PyObject*)NULL); |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
793 } |
|
0b40c8d5b21d
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
Guido van Rossum <guido@python.org>
parents:
3097
diff
changeset
|
794 |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
795 PyObject * |
| 3097 | 796 PySequence_Tuple(s) |
| 797 PyObject *s; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 int l, i; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
800 PyObject *t, *item; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
801 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
802 if(! s) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
803 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
804 Py_TRY((l=PySequence_Length(s)) != -1); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
805 Py_TRY(t=PyTuple_New(l)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
806 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
807 for(i=0; i < l; i++) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
808 { |
|
5515
064c86719ca7
Fix reversed test for failure in PySequence_List() and PySequence_Tuple().
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
809 if(!(item=PySequence_GetItem(s,i)) || |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
810 PyTuple_SetItem(t,i,item) == -1) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
811 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
812 Py_DECREF(t); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
813 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
814 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
815 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
816 return t; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
817 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
818 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
819 PyObject * |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
820 PySequence_List(s) |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
821 PyObject *s; |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
822 { |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
823 int l, i; |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
824 PyObject *t, *item; |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
825 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
826 if(! s) return Py_ReturnNullError(); |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
827 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
828 Py_TRY((l=PySequence_Length(s)) != -1); |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
829 Py_TRY(t=PyList_New(l)); |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
830 |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
831 for(i=0; i < l; i++) |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
832 { |
|
5515
064c86719ca7
Fix reversed test for failure in PySequence_List() and PySequence_Tuple().
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
833 if(!(item=PySequence_GetItem(s,i)) || |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
834 PyList_SetItem(t,i,item) == -1) |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
835 { |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
836 Py_DECREF(t); |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
837 return NULL; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
838 } |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
839 } |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
840 return t; |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
841 } |
|
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
842 |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
843 int |
| 3097 | 844 PySequence_Count(s, o) |
| 845 PyObject *s; | |
| 846 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
847 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
848 int l, i, n=0, not_equal, err; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
849 PyObject *item; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
850 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
851 if(! s || ! o) return Py_ReturnNullError(), -1; |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
852 if((l=PySequence_Length(s)) == -1) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
853 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
854 for(i=0; i < l; i++) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
855 { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
856 if((item=PySequence_GetItem(s,i)) == NULL) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
857 err=PyObject_Cmp(item,o,¬_equal) == -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
858 Py_DECREF(item); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
859 if(err) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
860 n += ! not_equal; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
861 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
862 return n; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
863 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
864 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
865 int |
| 3097 | 866 PySequence_In(s, o) |
| 867 PyObject *s; | |
| 868 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
869 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
870 int l, i, not_equal, err; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
871 PyObject *item; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
872 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
873 if(! o || ! s) return Py_ReturnNullError(), -1; |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
874 if((l=PySequence_Length(s)) == -1) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
875 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
876 for(i=0; i < l; i++) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
877 { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
878 if((item=PySequence_GetItem(s,i)) == NULL) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
879 err=PyObject_Cmp(item,o,¬_equal) == -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
880 Py_DECREF(item); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
881 if(err) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
882 if(! not_equal) return 1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
883 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
884 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
885 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
886 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
887 int |
| 3097 | 888 PySequence_Index(s, o) |
| 889 PyObject *s; | |
| 890 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
891 { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
892 int l, i, not_equal, err; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
893 PyObject *item; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
894 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
895 if(! s || ! o) return Py_ReturnNullError(), -1; |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
896 if((l=PySequence_Length(s)) == -1) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
897 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
898 for(i=0; i < l; i++) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
899 { |
|
4582
2f8d9c22de62
Added missing PySequence_List.
Guido van Rossum <guido@python.org>
parents:
4529
diff
changeset
|
900 if((item=PySequence_GetItem(s,i)) == NULL) return -1; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
901 err=PyObject_Cmp(item,o,¬_equal) == -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
902 Py_DECREF(item); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
903 if(err) return -1; |
|
4515
a75858fef550
correct typo in return variable for PySequence_Index()
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
904 if(! not_equal) return i; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
905 } |
|
4771
4710701690c1
PySequence_Index(): set exception when object is not found in
Barry Warsaw <barry@python.org>
parents:
4582
diff
changeset
|
906 PyErr_SetString(PyExc_ValueError, "list.index(x): x not in list"); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
907 return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
908 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
910 int |
| 3097 | 911 PyMapping_Check(o) |
| 912 PyObject *o; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
913 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
914 return o && o->ob_type->tp_as_mapping; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
915 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
916 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
917 int |
| 3097 | 918 PyMapping_Length(s) |
| 919 PyObject *s; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
920 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
921 PyMappingMethods *m; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
922 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
923 if(! s) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
924 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
925 if((m=s->ob_type->tp_as_mapping) && m->mp_length) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
926 return m->mp_length(s); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
928 Py_ReturnMethodError("__len__"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
929 return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
930 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
931 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
932 int |
| 3097 | 933 PyMapping_HasKeyString(o, key) |
| 934 PyObject *o; | |
| 935 char *key; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
936 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
937 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
938 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
939 v=PyMapping_GetItemString(o,key); |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
940 if(v) { |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
941 Py_DECREF(v); |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
942 return 1; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
943 } |
| 3097 | 944 PyErr_Clear(); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
945 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
946 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
947 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
948 int |
| 3097 | 949 PyMapping_HasKey(o, key) |
| 950 PyObject *o; | |
| 951 PyObject *key; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
952 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
953 PyObject *v; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
955 v=PyObject_GetItem(o,key); |
|
5235
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
956 if(v) { |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
957 Py_DECREF(v); |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
958 return 1; |
|
4f1fa7b69ba7
Several fixes reported by jim F.
Guido van Rossum <guido@python.org>
parents:
4771
diff
changeset
|
959 } |
| 3097 | 960 PyErr_Clear(); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
961 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
962 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
963 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 PyObject * |
| 3097 | 965 PyObject_CallObject(o, a) |
| 966 PyObject *o, *a; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
967 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
968 PyObject *r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
970 if(a) return PyEval_CallObject(o,a); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
971 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 if(! (a=PyTuple_New(0))) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
974 r=PyEval_CallObject(o,a); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
975 Py_DECREF(a); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
976 return r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
978 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 #ifdef HAVE_STDARG_PROTOTYPES |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
981 /* VARARGS 2 */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5235
diff
changeset
|
982 PyObject_CallFunction(PyObject *PyCallable_Check, char *format, ...) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
983 #else |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
984 /* VARARGS */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
985 PyObject_CallFunction(va_alist) va_dcl |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
986 #endif |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
987 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 va_list va; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
989 PyObject *args, *retval; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
990 #ifdef HAVE_STDARG_PROTOTYPES |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
991 va_start(va, format); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
992 #else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5235
diff
changeset
|
993 PyObject *PyCallable_Check; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
994 char *format; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
995 va_start(va); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5235
diff
changeset
|
996 PyCallable_Check = va_arg(va, PyObject *); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
997 format = va_arg(va, char *); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
998 #endif |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
999 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5235
diff
changeset
|
1000 if( ! PyCallable_Check) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1001 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1002 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1003 return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1004 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1005 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1006 if(format) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1007 args = Py_VaBuildValue(format, va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1008 else |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1009 args = PyTuple_New(0); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1010 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1011 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1012 if(! args) return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1013 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1014 if(! PyTuple_Check(args)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1015 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1016 PyObject *a; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1017 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1018 Py_TRY(a=PyTuple_New(1)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1019 Py_TRY(PyTuple_SetItem(a,0,args) != -1); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1020 args=a; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1021 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5235
diff
changeset
|
1022 retval = PyObject_CallObject(PyCallable_Check,args); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1023 Py_DECREF(args); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1024 return retval; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1025 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1026 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1027 PyObject * |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1028 #ifdef HAVE_STDARG_PROTOTYPES |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1029 /* VARARGS 2 */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1030 PyObject_CallMethod(PyObject *o, char *name, char *format, ...) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1031 #else |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1032 /* VARARGS */ |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1033 PyObject_CallMethod(va_alist) va_dcl |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1034 #endif |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1035 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1036 va_list va; |
|
5565
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1037 PyObject *args, *func=0, *retval; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1038 #ifdef HAVE_STDARG_PROTOTYPES |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1039 va_start(va, format); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1040 #else |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1041 PyObject *o; |
| 3097 | 1042 char *name; |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1043 char *format; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1044 va_start(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1045 o = va_arg(va, PyObject *); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1046 name = va_arg(va, char *); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1047 format = va_arg(va, char *); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1048 #endif |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1049 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1050 if( ! o || ! name) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1051 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1052 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1053 return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1054 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1055 |
|
5565
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1056 func=PyObject_GetAttrString(o,name); |
|
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1057 if(! func) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1058 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1059 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1060 PyErr_SetString(PyExc_AttributeError,name); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1061 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1062 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1063 |
|
5565
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1064 if(! (PyCallable_Check(func))) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1065 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1066 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1067 PyErr_SetString(PyExc_TypeError,"call of non-callable attribute"); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1068 return 0; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1069 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1070 |
|
4344
5cbdba4d2e15
Fix subtle bug detected by Jim F.
Guido van Rossum <guido@python.org>
parents:
4090
diff
changeset
|
1071 if(format && *format) |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1072 args = Py_VaBuildValue(format, va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1073 else |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1074 args = PyTuple_New(0); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1075 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1076 va_end(va); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1077 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1078 if(! args) return NULL; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1079 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1080 if(! PyTuple_Check(args)) |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1081 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1082 PyObject *a; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1083 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1084 Py_TRY(a=PyTuple_New(1)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1085 Py_TRY(PyTuple_SetItem(a,0,args) != -1); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1086 args=a; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1087 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1088 |
|
5565
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1089 retval = PyObject_CallObject(func,args); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1090 Py_DECREF(args); |
|
5565
5ffab65f8d05
Renamed a local variable from 'PyCFunction' (which is also a typedef
Guido van Rossum <guido@python.org>
parents:
5515
diff
changeset
|
1091 Py_DECREF(func); |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1092 return retval; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1094 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1095 PyObject * |
| 3097 | 1096 PyMapping_GetItemString(o, key) |
| 1097 PyObject *o; | |
| 1098 char *key; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1099 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1100 PyObject *okey, *r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1102 if( ! key) return Py_ReturnNullError(); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1103 Py_TRY(okey=PyString_FromString(key)); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1104 r = PyObject_GetItem(o,okey); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1105 Py_DECREF(okey); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1106 return r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1107 } |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1108 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1109 int |
| 3097 | 1110 PyMapping_SetItemString(o, key, value) |
| 1111 PyObject *o; | |
| 1112 char *key; | |
| 1113 PyObject *value; | |
|
2840
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1114 { |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1115 PyObject *okey; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1116 int r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1117 |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1118 if( ! key) return Py_ReturnNullError(),-1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1119 if (!(okey=PyString_FromString(key))) return -1; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1120 r = PyObject_SetItem(o,okey,value); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1121 Py_DECREF(okey); |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1122 return r; |
|
d5398acafa2c
Generic Abstract Object Interface
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1123 } |
