Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2ed6bf87
Commit
2ed6bf87
authored
Sep 27, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch changes (coercion, rich comparisons) into trunk.
parent
33f4d6d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
11 deletions
+106
-11
Objects/complexobject.c
Objects/complexobject.c
+2
-4
Objects/object.c
Objects/object.c
+8
-0
Objects/stringobject.c
Objects/stringobject.c
+2
-4
Objects/typeobject.c
Objects/typeobject.c
+94
-3
No files found.
Objects/complexobject.c
View file @
2ed6bf87
...
@@ -560,10 +560,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
...
@@ -560,10 +560,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
Py_INCREF
(
Py_NotImplemented
);
Py_INCREF
(
Py_NotImplemented
);
return
Py_NotImplemented
;
return
Py_NotImplemented
;
}
}
/* May sure both arguments use complex comparison.
/* Make sure both arguments are complex. */
This implies PyComplex_Check(a) && PyComplex_Check(b). */
if
(
!
(
PyComplex_Check
(
v
)
&&
PyComplex_Check
(
w
)))
{
if
(
v
->
ob_type
->
tp_richcompare
!=
complex_richcompare
||
w
->
ob_type
->
tp_richcompare
!=
complex_richcompare
)
{
Py_DECREF
(
v
);
Py_DECREF
(
v
);
Py_DECREF
(
w
);
Py_DECREF
(
w
);
Py_INCREF
(
Py_NotImplemented
);
Py_INCREF
(
Py_NotImplemented
);
...
...
Objects/object.c
View file @
2ed6bf87
...
@@ -365,6 +365,14 @@ try_rich_compare(PyObject *v, PyObject *w, int op)
...
@@ -365,6 +365,14 @@ try_rich_compare(PyObject *v, PyObject *w, int op)
richcmpfunc
f
;
richcmpfunc
f
;
PyObject
*
res
;
PyObject
*
res
;
if
(
v
->
ob_type
!=
w
->
ob_type
&&
PyType_IsSubtype
(
w
->
ob_type
,
v
->
ob_type
)
&&
(
f
=
RICHCOMPARE
(
w
->
ob_type
))
!=
NULL
)
{
res
=
(
*
f
)(
w
,
v
,
swapped_op
[
op
]);
if
(
res
!=
Py_NotImplemented
)
return
res
;
Py_DECREF
(
res
);
}
if
((
f
=
RICHCOMPARE
(
v
->
ob_type
))
!=
NULL
)
{
if
((
f
=
RICHCOMPARE
(
v
->
ob_type
))
!=
NULL
)
{
res
=
(
*
f
)(
v
,
w
,
op
);
res
=
(
*
f
)(
v
,
w
,
op
);
if
(
res
!=
Py_NotImplemented
)
if
(
res
!=
Py_NotImplemented
)
...
...
Objects/stringobject.c
View file @
2ed6bf87
...
@@ -824,10 +824,8 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
...
@@ -824,10 +824,8 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
int
min_len
;
int
min_len
;
PyObject
*
result
;
PyObject
*
result
;
/* May sure both arguments use string comparison.
/* Make sure both arguments are strings. */
This implies PyString_Check(a) && PyString_Check(b). */
if
(
!
(
PyString_Check
(
a
)
&&
PyString_Check
(
b
)))
{
if
(
a
->
ob_type
->
tp_richcompare
!=
(
richcmpfunc
)
string_richcompare
||
b
->
ob_type
->
tp_richcompare
!=
(
richcmpfunc
)
string_richcompare
)
{
result
=
Py_NotImplemented
;
result
=
Py_NotImplemented
;
goto
out
;
goto
out
;
}
}
...
...
Objects/typeobject.c
View file @
2ed6bf87
...
@@ -1837,6 +1837,40 @@ BINARY(rshift, "x>>y");
...
@@ -1837,6 +1837,40 @@ BINARY(rshift, "x>>y");
BINARY
(
and
,
"x&y"
);
BINARY
(
and
,
"x&y"
);
BINARY
(
xor
,
"x^y"
);
BINARY
(
xor
,
"x^y"
);
BINARY
(
or
,
"x|y"
);
BINARY
(
or
,
"x|y"
);
static
PyObject
*
wrap_coercefunc
(
PyObject
*
self
,
PyObject
*
args
,
void
*
wrapped
)
{
coercion
func
=
(
coercion
)
wrapped
;
PyObject
*
other
,
*
res
;
int
ok
;
if
(
!
PyArg_ParseTuple
(
args
,
"O"
,
&
other
))
return
NULL
;
ok
=
func
(
&
self
,
&
other
);
if
(
ok
<
0
)
return
NULL
;
if
(
ok
>
0
)
{
Py_INCREF
(
Py_NotImplemented
);
return
Py_NotImplemented
;
}
res
=
PyTuple_New
(
2
);
if
(
res
==
NULL
)
{
Py_DECREF
(
self
);
Py_DECREF
(
other
);
return
NULL
;
}
PyTuple_SET_ITEM
(
res
,
0
,
self
);
PyTuple_SET_ITEM
(
res
,
1
,
other
);
return
res
;
}
static
struct
wrapperbase
tab_coerce
[]
=
{
{
"__coerce__"
,
(
wrapperfunc
)
wrap_coercefunc
,
"x.__coerce__(y) <==> coerce(x, y)"
},
{
0
}
};
BINARY
(
floordiv
,
"x//y"
);
BINARY
(
floordiv
,
"x//y"
);
BINARY
(
truediv
,
"x/y # true division"
);
BINARY
(
truediv
,
"x/y # true division"
);
...
@@ -2573,7 +2607,7 @@ add_operators(PyTypeObject *type)
...
@@ -2573,7 +2607,7 @@ add_operators(PyTypeObject *type)
ADD
(
nb
->
nb_and
,
tab_and
);
ADD
(
nb
->
nb_and
,
tab_and
);
ADD
(
nb
->
nb_xor
,
tab_xor
);
ADD
(
nb
->
nb_xor
,
tab_xor
);
ADD
(
nb
->
nb_or
,
tab_or
);
ADD
(
nb
->
nb_or
,
tab_or
);
/* We don't support coerce() -- see above comment */
ADD
(
nb
->
nb_coerce
,
tab_coerce
);
ADD
(
nb
->
nb_int
,
tab_int
);
ADD
(
nb
->
nb_int
,
tab_int
);
ADD
(
nb
->
nb_long
,
tab_long
);
ADD
(
nb
->
nb_long
,
tab_long
);
ADD
(
nb
->
nb_float
,
tab_float
);
ADD
(
nb
->
nb_float
,
tab_float
);
...
@@ -2840,7 +2874,64 @@ SLOT1BIN(slot_nb_rshift, nb_rshift, "__rshift__", "__rrshift__")
...
@@ -2840,7 +2874,64 @@ SLOT1BIN(slot_nb_rshift, nb_rshift, "__rshift__", "__rrshift__")
SLOT1BIN
(
slot_nb_and
,
nb_and
,
"__and__"
,
"__rand__"
)
SLOT1BIN
(
slot_nb_and
,
nb_and
,
"__and__"
,
"__rand__"
)
SLOT1BIN
(
slot_nb_xor
,
nb_xor
,
"__xor__"
,
"__rxor__"
)
SLOT1BIN
(
slot_nb_xor
,
nb_xor
,
"__xor__"
,
"__rxor__"
)
SLOT1BIN
(
slot_nb_or
,
nb_or
,
"__or__"
,
"__ror__"
)
SLOT1BIN
(
slot_nb_or
,
nb_or
,
"__or__"
,
"__ror__"
)
/* Not coerce() */
static
int
slot_nb_coerce
(
PyObject
**
a
,
PyObject
**
b
)
{
static
PyObject
*
coerce_str
;
PyObject
*
self
=
*
a
,
*
other
=
*
b
;
if
(
self
->
ob_type
->
tp_as_number
!=
NULL
&&
self
->
ob_type
->
tp_as_number
->
nb_coerce
==
slot_nb_coerce
)
{
PyObject
*
r
;
r
=
call_maybe
(
self
,
"__coerce__"
,
&
coerce_str
,
"(O)"
,
other
);
if
(
r
==
NULL
)
return
-
1
;
if
(
r
==
Py_NotImplemented
)
{
Py_DECREF
(
r
);
return
1
;
}
if
(
!
PyTuple_Check
(
r
)
||
PyTuple_GET_SIZE
(
r
)
!=
2
)
{
PyErr_SetString
(
PyExc_TypeError
,
"__coerce__ didn't return a 2-tuple"
);
Py_DECREF
(
r
);
return
-
1
;
}
*
a
=
PyTuple_GET_ITEM
(
r
,
0
);
Py_INCREF
(
*
a
);
*
b
=
PyTuple_GET_ITEM
(
r
,
1
);
Py_INCREF
(
*
b
);
Py_DECREF
(
r
);
return
0
;
}
if
(
other
->
ob_type
->
tp_as_number
!=
NULL
&&
other
->
ob_type
->
tp_as_number
->
nb_coerce
==
slot_nb_coerce
)
{
PyObject
*
r
;
r
=
call_maybe
(
other
,
"__coerce__"
,
&
coerce_str
,
"(O)"
,
self
);
if
(
r
==
NULL
)
return
-
1
;
if
(
r
==
Py_NotImplemented
)
{
Py_DECREF
(
r
);
return
1
;
}
if
(
!
PyTuple_Check
(
r
)
||
PyTuple_GET_SIZE
(
r
)
!=
2
)
{
PyErr_SetString
(
PyExc_TypeError
,
"__coerce__ didn't return a 2-tuple"
);
Py_DECREF
(
r
);
return
-
1
;
}
*
a
=
PyTuple_GET_ITEM
(
r
,
1
);
Py_INCREF
(
*
a
);
*
b
=
PyTuple_GET_ITEM
(
r
,
0
);
Py_INCREF
(
*
b
);
Py_DECREF
(
r
);
return
0
;
}
return
1
;
}
SLOT0
(
slot_nb_int
,
"__int__"
)
SLOT0
(
slot_nb_int
,
"__int__"
)
SLOT0
(
slot_nb_long
,
"__long__"
)
SLOT0
(
slot_nb_long
,
"__long__"
)
SLOT0
(
slot_nb_float
,
"__float__"
)
SLOT0
(
slot_nb_float
,
"__float__"
)
...
@@ -3336,7 +3427,7 @@ override_slots(PyTypeObject *type, PyObject *dict)
...
@@ -3336,7 +3427,7 @@ override_slots(PyTypeObject *type, PyObject *dict)
NBSLOT
(
"__and__"
,
nb_and
,
slot_nb_and
);
NBSLOT
(
"__and__"
,
nb_and
,
slot_nb_and
);
NBSLOT
(
"__xor__"
,
nb_xor
,
slot_nb_xor
);
NBSLOT
(
"__xor__"
,
nb_xor
,
slot_nb_xor
);
NBSLOT
(
"__or__"
,
nb_or
,
slot_nb_or
);
NBSLOT
(
"__or__"
,
nb_or
,
slot_nb_or
);
/* Not coerce() */
NBSLOT
(
"__coerce__"
,
nb_coerce
,
slot_nb_coerce
);
NBSLOT
(
"__int__"
,
nb_int
,
slot_nb_int
);
NBSLOT
(
"__int__"
,
nb_int
,
slot_nb_int
);
NBSLOT
(
"__long__"
,
nb_long
,
slot_nb_long
);
NBSLOT
(
"__long__"
,
nb_long
,
slot_nb_long
);
NBSLOT
(
"__float__"
,
nb_float
,
slot_nb_float
);
NBSLOT
(
"__float__"
,
nb_float
,
slot_nb_float
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment