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
a4b0a153
Commit
a4b0a153
authored
Oct 21, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #976 from undingen/instance_setattr
rewrite instance_setattro
parents
5472b5e0
26cbd0d2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
10 deletions
+91
-10
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+46
-8
src/runtime/classobj.h
src/runtime/classobj.h
+2
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+12
-2
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+2
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+19
-0
test/tests/setattr_ics.py
test/tests/setattr_ics.py
+8
-0
test/tests/tuples.py
test/tests/tuples.py
+2
-0
No files found.
src/runtime/classobj.cpp
View file @
a4b0a153
...
...
@@ -46,6 +46,14 @@ static Box* classLookup(BoxedClassobj* cls, BoxedString* attr, GetattrRewriteArg
return
r
;
}
if
(
cls
->
bases
==
EmptyTuple
)
{
if
(
rewrite_args
&&
rewrite_args
->
isSuccessful
())
{
rewrite_args
->
obj
->
addAttrGuard
(
offsetof
(
BoxedClassobj
,
bases
),
(
uint64_t
)
EmptyTuple
);
rewrite_args
->
assertReturnConvention
(
ReturnConvention
::
NO_RETURN
);
}
return
NULL
;
}
if
(
rewrite_args
)
{
if
(
rewrite_args
->
isSuccessful
())
{
rewrite_args
->
getReturn
();
// just to make the asserts happy
...
...
@@ -489,7 +497,9 @@ Box* instanceGetattroInternal(Box* cls, Box* _attr, GetattrRewriteArgs* rewrite_
template
Box
*
instanceGetattroInternal
<
CAPI
>(
Box
*
,
Box
*
,
GetattrRewriteArgs
*
)
noexcept
;
template
Box
*
instanceGetattroInternal
<
CXX
>(
Box
*
,
Box
*
,
GetattrRewriteArgs
*
);
Box
*
instanceSetattr
(
Box
*
_inst
,
Box
*
_attr
,
Box
*
value
)
{
Box
*
instanceSetattroInternal
(
Box
*
_inst
,
Box
*
_attr
,
Box
*
value
,
SetattrRewriteArgs
*
rewrite_args
)
{
STAT_TIMER
(
t0
,
"us_timer_instance_setattro"
,
0
);
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
...
...
@@ -513,15 +523,43 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
}
static
BoxedString
*
setattr_str
=
internStringImmortal
(
"__setattr__"
);
Box
*
setattr
=
classLookup
(
inst
->
inst_cls
,
setattr_str
);
if
(
setattr
)
{
setattr
=
processDescriptor
(
setattr
,
inst
,
inst
->
inst_cls
);
return
runtimeCall
(
setattr
,
ArgPassSpec
(
2
),
_attr
,
value
,
NULL
,
NULL
,
NULL
);
if
(
rewrite_args
)
{
RewriterVar
*
inst_r
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
BoxedInstance
,
inst_cls
));
inst_r
->
addGuard
((
uint64_t
)
inst
->
inst_cls
);
GetattrRewriteArgs
grewrite_args
(
rewrite_args
->
rewriter
,
inst_r
,
rewrite_args
->
rewriter
->
getReturnDestination
());
Box
*
setattr
=
classLookup
<
REWRITABLE
>
(
inst
->
inst_cls
,
setattr_str
,
&
grewrite_args
);
if
(
!
grewrite_args
.
isSuccessful
())
{
assert
(
!
rewrite_args
->
out_success
);
rewrite_args
=
NULL
;
}
if
(
setattr
)
{
setattr
=
processDescriptor
(
setattr
,
inst
,
inst
->
inst_cls
);
return
runtimeCall
(
setattr
,
ArgPassSpec
(
2
),
_attr
,
value
,
NULL
,
NULL
,
NULL
);
}
if
(
rewrite_args
)
grewrite_args
.
assertReturnConvention
(
ReturnConvention
::
NO_RETURN
);
_inst
->
setattr
(
attr
,
value
,
rewrite_args
);
return
None
;
}
else
{
Box
*
setattr
=
classLookup
(
inst
->
inst_cls
,
setattr_str
);
if
(
setattr
)
{
setattr
=
processDescriptor
(
setattr
,
inst
,
inst
->
inst_cls
);
return
runtimeCall
(
setattr
,
ArgPassSpec
(
2
),
_attr
,
value
,
NULL
,
NULL
,
NULL
);
}
_inst
->
setattr
(
attr
,
value
,
NULL
);
return
None
;
}
}
_inst
->
setattr
(
attr
,
value
,
NULL
);
return
None
;
Box
*
instanceSetattr
(
Box
*
_inst
,
Box
*
_attr
,
Box
*
value
)
{
return
instanceSetattroInternal
(
_inst
,
_attr
,
value
,
NULL
)
;
}
Box
*
instanceDelattr
(
Box
*
_inst
,
Box
*
_attr
)
{
...
...
@@ -552,7 +590,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
return
None
;
}
static
int
instance_setattro
(
Box
*
cls
,
Box
*
attr
,
Box
*
value
)
noexcept
{
int
instance_setattro
(
Box
*
cls
,
Box
*
attr
,
Box
*
value
)
noexcept
{
try
{
if
(
value
)
{
instanceSetattr
(
cls
,
attr
,
value
);
...
...
src/runtime/classobj.h
View file @
a4b0a153
...
...
@@ -85,9 +85,11 @@ public:
};
Box
*
instance_getattro
(
Box
*
cls
,
Box
*
attr
)
noexcept
;
int
instance_setattro
(
Box
*
cls
,
Box
*
attr
,
Box
*
value
)
noexcept
;
class
GetattrRewriteArgs
;
template
<
ExceptionStyle
S
>
Box
*
instanceGetattroInternal
(
Box
*
self
,
Box
*
attr
,
GetattrRewriteArgs
*
rewrite_args
)
noexcept
(
S
==
CAPI
);
Box
*
instanceSetattroInternal
(
Box
*
self
,
Box
*
attr
,
Box
*
val
,
SetattrRewriteArgs
*
rewrite_args
);
}
#endif
src/runtime/objmodel.cpp
View file @
a4b0a153
...
...
@@ -2429,12 +2429,22 @@ extern "C" void setattr(Box* obj, BoxedString* attr, Box* attr_val) {
r_cls
->
addAttrGuard
(
offsetof
(
BoxedClass
,
tp_setattro
),
(
intptr_t
)
tp_setattro
);
}
// Note: setattr will only be retrieved if we think it will be profitable to try calling that as opposed to
// the tp_setattr function pointer.
Box
*
setattr
=
NULL
;
RewriterVar
*
r_setattr
;
if
(
tp_setattro
!=
PyObject_GenericSetAttr
)
{
if
(
tp_setattro
==
instance_setattro
)
{
if
(
rewriter
.
get
())
{
SetattrRewriteArgs
rewrite_args
(
rewriter
.
get
(),
rewriter
->
getArg
(
0
),
rewriter
->
getArg
(
2
));
instanceSetattroInternal
(
obj
,
attr
,
attr_val
,
&
rewrite_args
);
if
(
rewrite_args
.
out_success
)
rewriter
->
commit
();
}
else
instanceSetattroInternal
(
obj
,
attr
,
attr_val
,
NULL
);
return
;
}
else
if
(
tp_setattro
!=
PyObject_GenericSetAttr
)
{
static
BoxedString
*
setattr_str
=
internStringImmortal
(
"__setattr__"
);
if
(
rewriter
.
get
())
{
GetattrRewriteArgs
rewrite_args
(
rewriter
.
get
(),
rewriter
->
getArg
(
0
)
->
getAttr
(
offsetof
(
Box
,
cls
)),
...
...
src/runtime/tuple.cpp
View file @
a4b0a153
...
...
@@ -372,6 +372,8 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
return
BoxedTuple
::
create
(
elts
.
size
(),
&
elts
[
0
],
cls
);
}
else
{
if
(
cls
==
tuple_cls
)
return
EmptyTuple
;
return
BoxedTuple
::
create
(
0
,
cls
);
}
}
...
...
test/tests/oldstyle_classes.py
View file @
a4b0a153
...
...
@@ -492,3 +492,22 @@ try:
except
:
print
sys
.
exc_info
()[
0
].
__name__
,
sys
.
exc_info
()[
1
]
s1
=
0
class
C
():
pass
class
D
():
def
__setattr__
(
self
,
a
,
v
):
global
s1
s1
+=
v
o
=
C
()
s2
=
0
for
i
in
range
(
500
):
o
.
a
=
1
s2
+=
o
.
a
if
i
==
100
:
C
.
__bases__
=
(
D
,)
if
i
==
150
:
C
.
__bases__
=
tuple
()
print
s1
,
s2
test/tests/setattr_ics.py
View file @
a4b0a153
...
...
@@ -30,3 +30,11 @@ test(Test())
del
Test
.
__setattr__
for
i
in
xrange
(
100
):
test
(
Test
())
class
Old
():
pass
old
=
Old
()
for
i
in
xrange
(
1000
):
old
.
a
=
i
assert
old
.
a
==
i
test/tests/tuples.py
View file @
a4b0a153
...
...
@@ -27,6 +27,8 @@ print (2,) < (2,)
print
(
2
,)
<
(
2
,
3
)
print
(
3
,)
<
(
2
,
3
)
print
()
is
(),
()
is
tuple
(),
tuple
()
is
tuple
()
print
class
T
(
object
):
...
...
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