annotate Modules/operator.c @ 16798:258dcafe2d0b legacy-trunk

Gustavo Niemeyer <niemeyer@conectiva.com>: Fixed recno support (keys are integers rather than strings). Work around DB bug that cause stdin to be closed by rnopen() when the DB file needed to exist but did not (no longer segfaults). This closes SF tracker patch #403445. Also wrapped some long lines and added whitespace around operators -- FLD.
author Fred Drake <fdrake@acm.org>
date Tue, 27 Feb 2001 18:56:46 +0000
parents 0bd746bc7627
children 6ba441507220
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 static char operator_doc[] = "\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 Operator interface.\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 This module exports a set of functions implemented in C corresponding\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 to the intrinsic operators of Python. For example, operator.add(x, y)\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 is equivalent to the expression x+y. The function names are those\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 used for special class methods; variants without leading and trailing\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 '__' are also provided for convenience.\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 ";
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /*
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 Copyright
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 Copyright 1996 Digital Creations, L.C., 910 Princess Anne
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 rights reserved. Copyright in this software is owned by DCLC,
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 unless otherwise indicated. Permission to use, copy and
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 distribute this software is hereby granted, provided that the
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 above copyright notice appear in all copies and that both that
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 copyright notice and this permission notice appear. Note that
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 any product, process or technology described in this software
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 may be the subject of other Intellectual Property rights
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 reserved by Digital Creations, L.C. and are not licensed
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 hereunder.
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 Trademarks
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 All other trademarks are owned by their respective companies.
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 No Warranty
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 The software is provided "as is" without warranty of any kind,
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 either express or implied, including, but not limited to, the
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 implied warranties of merchantability, fitness for a particular
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 purpose, or non-infringement. This software could include
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 technical inaccuracies or typographical errors. Changes are
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 periodically made to the software; these changes will be
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 incorporated in new editions of the software. DCLC may make
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 improvements and/or changes in this software at any time
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 without notice.
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 Limitation Of Liability
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 In no event will DCLC be liable for direct, indirect, special,
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 incidental, economic, cover, or consequential damages arising
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 out of the use of or inability to use this software even if
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 advised of the possibility of such damages. Some states do not
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 allow the exclusion or limitation of implied warranties or
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 limitation of liability for incidental or consequential
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 damages, so the above limitation or exclusion may not apply to
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 you.
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 If you have questions regarding this software,
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 contact:
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 Jim Fulton, jim@digicool.com
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 Digital Creations L.C.
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 (540) 371-6909
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 Modifications
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 Renamed and slightly rearranged by Guido van Rossum
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 */
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 #include "Python.h"
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
72 #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 PyObject *a1; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
74 if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 return AOP(a1); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
77 #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 PyObject *a1, *a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
79 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 return AOP(a1,a2); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
82 #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 PyObject *a1; int a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
84 if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 return AOP(a1,a2); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
87 #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 PyObject *a1, *a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
89 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 if(-1 == AOP(a1,a2)) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 Py_INCREF(Py_None); \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 return Py_None; }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
94 #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 PyObject *a1, *a2, *a3; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
96 if(! PyArg_ParseTuple(a,"OOO:" #OP,&a1,&a2,&a3)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 if(-1 == AOP(a1,a2,a3)) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 Py_INCREF(Py_None); \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 return Py_None; }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
101 #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 PyObject *a1; long r; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
103 if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 if(-1 == (r=AOP(a1))) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 return PyInt_FromLong(r); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
107 #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 PyObject *a1, *a2; long r; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
109 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 if(-1 == (r=AOP(a1,a2))) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 return PyInt_FromLong(r); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 spami(isCallable , PyCallable_Check)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 spami(isNumberType , PyNumber_Check)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
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)
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
125 spam1(op_invert , PyNumber_Invert)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
126 spam2(op_lshift , PyNumber_Lshift)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
127 spam2(op_rshift , PyNumber_Rshift)
7936
1f38a2b548bf Add not_ and __not__.
Guido van Rossum <guido@python.org>
parents: 6227
diff changeset
128 spami(op_not_ , PyObject_Not)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
129 spam2(op_and_ , PyNumber_And)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
130 spam2(op_xor , PyNumber_Xor)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
131 spam2(op_or_ , PyNumber_Or)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 spami(isSequenceType , PySequence_Check)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
133 spam2(op_concat , PySequence_Concat)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
134 spamoi(op_repeat , PySequence_Repeat)
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
135 spami2(op_contains , PySequence_Contains)
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
136 spami2(sequenceIncludes, PySequence_Contains)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 spami2(indexOf , PySequence_Index)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 spami2(countOf , PySequence_Count)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 spami(isMappingType , PyMapping_Check)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
140 spam2(op_getitem , PyObject_GetItem)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
141 spam2n(op_delitem , PyObject_DelItem)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
142 spam3n(op_setitem , PyObject_SetItem)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
143
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
145 op_getslice(PyObject *s, PyObject *a)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
147 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
148 int a2,a3;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
149
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
150 if (!PyArg_ParseTuple(a,"Oii:getslice",&a1,&a2,&a3))
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
151 return NULL;
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
152 return PySequence_GetSlice(a1,a2,a3);
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
156 op_setslice(PyObject *s, PyObject *a)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
158 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
159 int a2,a3;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
161 if (!PyArg_ParseTuple(a,"OiiO:setslice",&a1,&a2,&a3,&a4))
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
162 return NULL;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
164 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
165 return NULL;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
167 Py_INCREF(Py_None);
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
168 return Py_None;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
171 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
172 op_delslice(PyObject *s, PyObject *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
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
177 if(! PyArg_ParseTuple(a,"Oii:delslice",&a1,&a2,&a3))
4775
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
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 #undef spam1
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 #undef spam2
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
189 #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, DOC},
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
190 #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, DOC}, \
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
191 {#ALTOP, op_##OP, METH_VARARGS, DOC},
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 static struct PyMethodDef operator_methods[] = {
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
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
195 spam1(isCallable,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
196 "isCallable(a) -- Same as callable(a).")
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 spam1(isNumberType,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
198 "isNumberType(a) -- Return 1 if a has a numeric type, and zero otherwise.")
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
199 spam1(isSequenceType,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
200 "isSequenceType(a) -- Return 1 if a has a sequence type, and zero otherwise.")
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(truth,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
202 "truth(a) -- Return 1 if a is true, and 0 otherwise.")
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
203 spam2(contains,__contains__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
204 "contains(a, b) -- Same as b in a (note reversed operands).")
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
205 spam1(sequenceIncludes,
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
206 "sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).")
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
207 spam1(indexOf,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
208 "indexOf(a, b) -- Return the first index of b in a.")
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
209 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
210 "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
211 spam1(isMappingType,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
212 "isMappingType(a) -- Return 1 if a has a mapping type, and zero otherwise.")
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
214 spam2(add,__add__, "add(a, b) -- Same as a + b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
215 spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
216 spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
217 spam2(div,__div__, "div(a, b) -- Same as a / b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
218 spam2(mod,__mod__, "mod(a, b) -- Same as a % b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
219 spam2(neg,__neg__, "neg(a) -- Same as -a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
220 spam2(pos,__pos__, "pos(a) -- Same as +a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
221 spam2(abs,__abs__, "abs(a) -- Same as abs(a).")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
222 spam2(inv,__inv__, "inv(a) -- Same as ~a.")
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
223 spam2(invert,__invert__, "invert(a) -- Same as ~a.")
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
224 spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
225 spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
226 spam2(not_,__not__, "not_(a) -- Same as not a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
227 spam2(and_,__and__, "and_(a, b) -- Same as a & b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
228 spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
229 spam2(or_,__or__, "or_(a, b) -- Same as a | 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(concat,__concat__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
231 "concat(a, b) -- Same as a + b, for a and b sequences.")
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(repeat,__repeat__,
4580
11bd4f497742 Correct typo -- repeat implements *, not +.
Guido van Rossum <guido@python.org>
parents: 4104
diff changeset
233 "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
234 spam2(getitem,__getitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
235 "getitem(a, b) -- Same as a[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
236 spam2(setitem,__setitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
237 "setitem(a, b, c) -- Same as a[b] = c.")
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
238 spam2(delitem,__delitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
239 "delitem(a, b) -- Same as del a[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
240 spam2(getslice,__getslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
241 "getslice(a, b, c) -- Same as a[b:c].")
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(setslice,__setslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
243 "setslice(a, b, c, d) -- Same as a[b:c] = d.")
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
244 spam2(delslice,__delslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
245 "delslice(a, b, c) -- Same as del a[b:c].")
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
246
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 {NULL, NULL} /* sentinel */
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 };
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
250
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
251
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 /* Initialization function for the module (*must* be called initoperator) */
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 8414
diff changeset
254 DL_EXPORT(void)
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13424
diff changeset
255 initoperator(void)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
257 /* Create the module and add the functions */
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
258 Py_InitModule4("operator", operator_methods, operator_doc,
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
259 (PyObject*)NULL, PYTHON_API_VERSION);
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 }