Mercurial > cpython-lru_cache-weakref
annotate Modules/operator.c @ 6719:faebc1940432 legacy-trunk
Understand -Xlinker option.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 02 Dec 1997 20:38:11 +0000 |
| parents | 613f976a57b4 |
| children | 1f38a2b548bf |
| rev | line source |
|---|---|
| 3844 | 1 static char operator_doc[] = "\ |
| 2 Operator interface.\n\ | |
| 3 \n\ | |
| 4 This module exports a set of functions implemented in C corresponding\n\ | |
| 5 to the intrinsic operators of Python. For example, operator.add(x, y)\n\ | |
| 6 is equivalent to the expression x+y. The function names are those\n\ | |
| 7 used for special class methods; variants without leading and trailing\n\ | |
| 8 '__' are also provided for convenience.\n\ | |
| 9 "; | |
| 10 | |
| 11 /* | |
| 12 | |
| 13 Copyright | |
| 14 | |
| 15 Copyright 1996 Digital Creations, L.C., 910 Princess Anne | |
| 16 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All | |
| 17 rights reserved. Copyright in this software is owned by DCLC, | |
| 18 unless otherwise indicated. Permission to use, copy and | |
| 19 distribute this software is hereby granted, provided that the | |
| 20 above copyright notice appear in all copies and that both that | |
| 21 copyright notice and this permission notice appear. Note that | |
| 22 any product, process or technology described in this software | |
| 23 may be the subject of other Intellectual Property rights | |
| 24 reserved by Digital Creations, L.C. and are not licensed | |
| 25 hereunder. | |
| 26 | |
| 27 Trademarks | |
| 28 | |
| 29 Digital Creations & DCLC, are trademarks of Digital Creations, L.C.. | |
| 30 All other trademarks are owned by their respective companies. | |
| 31 | |
| 32 No Warranty | |
| 33 | |
| 34 The software is provided "as is" without warranty of any kind, | |
| 35 either express or implied, including, but not limited to, the | |
| 36 implied warranties of merchantability, fitness for a particular | |
| 37 purpose, or non-infringement. This software could include | |
| 38 technical inaccuracies or typographical errors. Changes are | |
| 39 periodically made to the software; these changes will be | |
| 40 incorporated in new editions of the software. DCLC may make | |
| 41 improvements and/or changes in this software at any time | |
| 42 without notice. | |
| 43 | |
| 44 Limitation Of Liability | |
| 45 | |
| 46 In no event will DCLC be liable for direct, indirect, special, | |
| 47 incidental, economic, cover, or consequential damages arising | |
| 48 out of the use of or inability to use this software even if | |
| 49 advised of the possibility of such damages. Some states do not | |
| 50 allow the exclusion or limitation of implied warranties or | |
| 51 limitation of liability for incidental or consequential | |
| 52 damages, so the above limitation or exclusion may not apply to | |
| 53 you. | |
| 54 | |
| 55 | |
| 56 If you have questions regarding this software, | |
| 57 contact: | |
| 58 | |
| 59 Jim Fulton, jim@digicool.com | |
| 60 Digital Creations L.C. | |
| 61 | |
| 62 (540) 371-6909 | |
| 63 | |
| 64 Modifications | |
| 65 | |
| 66 Renamed and slightly rearranged by Guido van Rossum | |
| 67 | |
| 68 */ | |
| 69 | |
| 70 #include "Python.h" | |
| 71 | |
| 72 #define spam1(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 73 PyObject *a1; \ | |
| 74 if(! PyArg_ParseTuple(a,"O",&a1)) return NULL; \ | |
| 75 return AOP(a1); } | |
| 76 | |
| 77 #define spam2(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 78 PyObject *a1, *a2; \ | |
| 79 if(! PyArg_ParseTuple(a,"OO",&a1,&a2)) return NULL; \ | |
| 80 return AOP(a1,a2); } | |
| 81 | |
| 82 #define spamoi(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 83 PyObject *a1; int a2; \ | |
| 84 if(! PyArg_ParseTuple(a,"Oi",&a1,&a2)) return NULL; \ | |
| 85 return AOP(a1,a2); } | |
| 86 | |
| 87 #define spam2n(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 88 PyObject *a1, *a2; \ | |
| 89 if(! PyArg_ParseTuple(a,"OO",&a1,&a2)) return NULL; \ | |
| 90 if(-1 == AOP(a1,a2)) return NULL; \ | |
| 91 Py_INCREF(Py_None); \ | |
| 92 return Py_None; } | |
| 93 | |
| 94 #define spam3n(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 95 PyObject *a1, *a2, *a3; \ | |
| 96 if(! PyArg_ParseTuple(a,"OOO",&a1,&a2,&a3)) return NULL; \ | |
| 97 if(-1 == AOP(a1,a2,a3)) return NULL; \ | |
| 98 Py_INCREF(Py_None); \ | |
| 99 return Py_None; } | |
| 100 | |
| 101 #define spami(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 102 PyObject *a1; long r; \ | |
| 103 if(! PyArg_ParseTuple(a,"O",&a1)) return NULL; \ | |
| 104 if(-1 == (r=AOP(a1))) return NULL; \ | |
| 105 return PyInt_FromLong(r); } | |
| 106 | |
| 107 #define spami2(OP,AOP) static PyObject *OP(s,a) PyObject *s, *a; { \ | |
| 108 PyObject *a1, *a2; long r; \ | |
| 109 if(! PyArg_ParseTuple(a,"OO",&a1,&a2)) return NULL; \ | |
| 110 if(-1 == (r=AOP(a1,a2))) return NULL; \ | |
| 111 return PyInt_FromLong(r); } | |
| 112 | |
| 113 spami(isCallable , PyCallable_Check) | |
| 114 spami(isNumberType , PyNumber_Check) | |
| 115 spami(truth , PyObject_IsTrue) | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
116 spam2(op_add , PyNumber_Add) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
117 spam2(op_sub , PyNumber_Subtract) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
118 spam2(op_mul , PyNumber_Multiply) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
119 spam2(op_div , PyNumber_Divide) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
120 spam2(op_mod , PyNumber_Remainder) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
121 spam1(op_neg , PyNumber_Negative) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
122 spam1(op_pos , PyNumber_Positive) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
123 spam1(op_abs , PyNumber_Absolute) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
124 spam1(op_inv , PyNumber_Invert) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
125 spam2(op_lshift , PyNumber_Lshift) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
126 spam2(op_rshift , PyNumber_Rshift) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
127 spam2(op_and_ , PyNumber_And) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
128 spam2(op_xor , PyNumber_Xor) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
129 spam2(op_or_ , PyNumber_Or) |
| 3844 | 130 spami(isSequenceType , PySequence_Check) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
131 spam2(op_concat , PySequence_Concat) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
132 spamoi(op_repeat , PySequence_Repeat) |
| 3844 | 133 spami2(sequenceIncludes, PySequence_In) |
| 134 spami2(indexOf , PySequence_Index) | |
| 135 spami2(countOf , PySequence_Count) | |
| 136 spami(isMappingType , PyMapping_Check) | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
137 spam2(op_getitem , PyObject_GetItem) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
138 spam2n(op_delitem , PyObject_DelItem) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
139 spam3n(op_setitem , PyObject_SetItem) |
| 3844 | 140 |
| 141 static PyObject* | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
142 op_getslice(s,a) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
143 PyObject *s, *a; |
| 3844 | 144 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
145 PyObject *a1; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
146 int a2,a3; |
| 3844 | 147 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
148 if (!PyArg_ParseTuple(a,"Oii",&a1,&a2,&a3)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
149 return NULL; |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
150 return PySequence_GetSlice(a1,a2,a3); |
| 3844 | 151 } |
| 152 | |
| 153 static PyObject* | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
154 op_setslice(s,a) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
155 PyObject *s, *a; |
| 3844 | 156 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
157 PyObject *a1, *a4; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
158 int a2,a3; |
| 3844 | 159 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
160 if (!PyArg_ParseTuple(a,"OiiO",&a1,&a2,&a3,&a4)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
161 return NULL; |
| 3844 | 162 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
163 if (-1 == PySequence_SetSlice(a1,a2,a3,a4)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
164 return NULL; |
| 3844 | 165 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
166 Py_INCREF(Py_None); |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
167 return Py_None; |
| 3844 | 168 } |
| 169 | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
170 static PyObject* |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
171 op_delslice(s,a) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
172 PyObject *s, *a; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
173 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
174 PyObject *a1; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
175 int a2,a3; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
176 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
177 if(! PyArg_ParseTuple(a,"Oii",&a1,&a2,&a3)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
178 return NULL; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
179 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
180 if (-1 == PySequence_DelSlice(a1,a2,a3)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
181 return NULL; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
182 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
183 Py_INCREF(Py_None); |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
184 return Py_None; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
185 } |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
186 |
| 3844 | 187 #undef spam1 |
| 188 #undef spam2 | |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
189 #ifdef HAVE_OLD_CPP |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
190 #define spam1(OP,DOC) {"OP", OP, 1, DOC}, |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
191 #define spam2(OP,ALTOP,DOC) {"OP", op_/**/OP, 1, DOC}, \ |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
192 {"ALTOP", op_/**/OP, 1, DOC}, |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
193 #else |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
194 #define spam1(OP,DOC) {#OP, OP, 1, DOC}, |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
195 #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, 1, DOC}, \ |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
196 {#ALTOP, op_##OP, 1, DOC}, |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
197 #endif |
| 3844 | 198 |
| 199 static struct PyMethodDef operator_methods[] = { | |
| 200 | |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
201 spam1(isCallable, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
202 "isCallable(o) -- Return 1 if o is callable, and zero otherwise.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
203 spam1(isNumberType, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
204 "isNumberType(o) -- Return 1 if o has a numeric type, and zero otherwise.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
205 spam1(isSequenceType, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
206 "isSequenceType(o) -- Return 1 if o has a sequence type, and zero otherwise.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
207 spam1(truth, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
208 "truth(o) -- Return 1 if o is true, and 0 otherwise.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
209 spam1(sequenceIncludes, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
210 "sequenceIncludes(a, b) -- Return 1 is a includes b, and 0 otherwise.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
211 spam1(indexOf, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
212 "indexOf(a, b) -- Return the index of b in a.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
213 spam1(countOf, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
214 "countOf(a, b) -- Return the number of times b occurs in a.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
215 spam1(isMappingType, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
216 "isMappingType(o) -- Return 1 if o has a mapping type, and zero otherwise.") |
| 3844 | 217 |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
218 spam2(add,__add__, "add(a, b) -- Return a + b, for a and b numbers.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
219 spam2(sub,__sub__, "sub(a, b) -- Return a - b.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
220 spam2(mul,__mul__, "mul(a, b) -- Return a * b, for a and b numbers.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
221 spam2(div,__div__, "div(a, b) -- Return a / b.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
222 spam2(mod,__mod__, "mod(a, b) -- Return a % b.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
223 spam2(neg,__neg__, "neg(o) -- Return o negated.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
224 spam2(pos,__pos__, "pos(o) -- Return o positive.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
225 spam2(abs,__abs__, "abs(o) -- Return the absolute value of o.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
226 spam2(inv,__inv__, "inv(o) -- Return the inverse of o.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
227 spam2(lshift,__lshift__, "lshift(a, b) -- Return a shifted left by b.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
228 spam2(rshift,__rshift__, "rshift(a, b) -- Return a shifted right by b.") |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
229 spam2(and_,__and__, "and_(a, b) -- Return the bitwise and of a and b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
230 spam2(xor,__xor__, "xor(a, b) -- Return the bitwise exclusive-or of a and b.") |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
231 spam2(or_,__or__, "or_(a, b) -- Return the bitwise or of a and b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
232 spam2(concat,__concat__, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
233 "concat(a, b) -- Return a + b, for a and b sequences.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
234 spam2(repeat,__repeat__, |
|
4580
11bd4f497742
Correct typo -- repeat implements *, not +.
Guido van Rossum <guido@python.org>
parents:
4104
diff
changeset
|
235 "repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
236 spam2(getitem,__getitem__, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
237 "getitem(a, b) -- Return the value of a at index b.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
238 spam2(setitem,__setitem__, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
239 "setitem(a, b, c) -- Set the value of a at b to c.") |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
240 spam2(delitem,__delitem__, |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
241 "delitem(a, b) -- Delete the value of a at b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
242 spam2(getslice,__getslice__, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
243 "getslice(a, b, c) -- Return the slice of a from b to c-1.") |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
244 spam2(setslice,__setslice__, |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
245 "setslice(a, b, c, v) -- Set the slice of a from b to c-1 to the sequence v.") |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
246 spam2(delslice,__delslice__, |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
247 "delslice(a, b, c) -- Delete the slice of a from b to c-1.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
248 |
| 3844 | 249 {NULL, NULL} /* sentinel */ |
| 250 | |
| 251 }; | |
| 252 | |
| 253 | |
| 254 /* Initialization function for the module (*must* be called initoperator) */ | |
| 255 | |
| 256 void | |
| 257 initoperator() | |
| 258 { | |
|
6227
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6183
diff
changeset
|
259 PyObject *m, *d, *v; |
| 3844 | 260 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
261 /* Create the module and add the functions */ |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
262 m = Py_InitModule4("operator", operator_methods, |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
263 operator_doc, |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
264 (PyObject*)NULL,PYTHON_API_VERSION); |
| 3844 | 265 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
266 /* Add some symbolic constants to the module */ |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
267 d = PyModule_GetDict(m); |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
268 PyDict_SetItemString(d, "__version__", |
|
6227
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6183
diff
changeset
|
269 v = PyString_FromString("$Rev$")); |
|
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6183
diff
changeset
|
270 Py_XDECREF(v); |
| 3844 | 271 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
272 /* Check for errors */ |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
273 if (PyErr_Occurred()) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
274 Py_FatalError("can't initialize module operator"); |
| 3844 | 275 } |
