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
6f58ccbc
Commit
6f58ccbc
authored
Mar 23, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add '__call__' support to instances of old style classes
parent
5f942f2c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+13
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+6
-0
No files found.
src/runtime/classobj.cpp
View file @
6f58ccbc
...
...
@@ -433,6 +433,17 @@ static Box* instanceHash(BoxedInstance* inst) {
}
}
Box
*
instanceCall
(
Box
*
_inst
,
Box
*
_args
,
Box
*
_kwargs
)
{
assert
(
_inst
->
cls
==
instance_cls
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
Box
*
call_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__call__"
),
false
);
if
(
!
call_func
)
raiseExcHelper
(
AttributeError
,
"%s instance has no __call__ method"
,
inst
->
inst_cls
->
name
->
s
.
c_str
());
return
runtimeCall
(
call_func
,
ArgPassSpec
(
0
,
0
,
true
,
true
),
_args
,
_kwargs
,
NULL
,
NULL
,
NULL
);
}
void
setupClassobj
()
{
classobj_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedClassobj
::
gcHandler
,
offsetof
(
BoxedClassobj
,
attrs
),
0
,
sizeof
(
BoxedClassobj
),
false
,
"classobj"
);
...
...
@@ -467,6 +478,8 @@ void setupClassobj() {
instance_cls
->
giveAttr
(
"__delitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceDelitem
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceContains
,
UNKNOWN
,
2
)));
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
->
freeze
();
instance_cls
->
tp_getattro
=
instance_getattro
;
...
...
test/tests/oldstyle_classes.py
View file @
6f58ccbc
...
...
@@ -50,6 +50,11 @@ class E():
print
"len"
return
self
.
n
def
__call__
(
self
):
def
f
(
a
):
print
"f"
,
a
return
f
e
=
E
(
1
)
print
e
print
e
.
n
...
...
@@ -57,6 +62,7 @@ print e.foo()
print
e
[
1
]
print
e
[
1
:
2
]
print
len
(
e
)
print
e
()(
"test"
)
def
str2
():
return
"str2"
...
...
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