Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
d660c034
Commit
d660c034
authored
Apr 29, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add __eq__ and __ne__ support for old style classes
parent
49fcc87c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+22
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+12
-0
No files found.
src/runtime/classobj.cpp
View file @
d660c034
...
...
@@ -511,6 +511,26 @@ static PyObject* instance_index(PyObject* self) noexcept {
return
res
;
}
Box
*
instanceEq
(
Box
*
_inst
,
Box
*
other
)
{
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
Box
*
func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__eq__"
),
false
);
if
(
!
func
)
return
NotImplemented
;
return
runtimeCall
(
func
,
ArgPassSpec
(
1
),
other
,
NULL
,
NULL
,
NULL
,
NULL
);
}
Box
*
instanceNe
(
Box
*
_inst
,
Box
*
other
)
{
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
Box
*
func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__ne__"
),
false
);
if
(
!
func
)
return
NotImplemented
;
return
runtimeCall
(
func
,
ArgPassSpec
(
1
),
other
,
NULL
,
NULL
,
NULL
,
NULL
);
}
Box
*
instanceCall
(
Box
*
_inst
,
Box
*
_args
,
Box
*
_kwargs
)
{
assert
(
_inst
->
cls
==
instance_cls
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
...
...
@@ -560,6 +580,8 @@ void setupClassobj() {
instance_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceHash
,
UNKNOWN
,
1
)));
instance_cls
->
giveAttr
(
"__call__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceCall
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
instance_cls
->
giveAttr
(
"__eq__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceEq
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__ne__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceNe
,
UNKNOWN
,
2
)));
instance_cls
->
freeze
();
instance_cls
->
tp_getattro
=
instance_getattro
;
...
...
test/tests/oldstyle_classes.py
View file @
d660c034
...
...
@@ -55,6 +55,14 @@ class E():
print
"f"
,
a
return
f
def
__eq__
(
self
,
other
):
print
"eq"
return
self
.
n
==
other
.
n
def
__ne__
(
self
,
other
):
print
"ne"
return
self
.
n
!=
other
.
n
e
=
E
(
1
)
print
e
print
e
.
n
...
...
@@ -63,6 +71,8 @@ print e[1]
print
e
[
1
:
2
]
print
len
(
e
)
print
e
()(
"test"
)
print
e
==
E
(
1
)
print
e
!=
E
(
1
)
def
str2
():
return
"str2"
...
...
@@ -82,6 +92,8 @@ class F:
print
bool
(
F
(
0
))
print
bool
(
F
(
1
))
print
F
(
0
)
==
F
(
0
)
print
F
(
0
)
!=
F
(
0
)
f
=
F
(
0
)
try
:
...
...
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