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
abbbbf48
Commit
abbbbf48
authored
Mar 21, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add instance.tp_setattro
parent
5767d26e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+17
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+9
-6
No files found.
src/runtime/classobj.cpp
View file @
abbbbf48
...
@@ -250,6 +250,8 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
...
@@ -250,6 +250,8 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
RELEASE_ASSERT
(
_attr
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
_attr
->
cls
==
str_cls
,
""
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
BoxedString
*
attr
=
static_cast
<
BoxedString
*>
(
_attr
);
assert
(
value
);
// These are special cases in CPython as well:
// These are special cases in CPython as well:
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
[
0
]
==
'_'
&&
attr
->
s
[
1
]
==
'_'
)
{
if
(
attr
->
s
==
"__dict__"
)
if
(
attr
->
s
==
"__dict__"
)
...
@@ -276,6 +278,20 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
...
@@ -276,6 +278,20 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
return
None
;
return
None
;
}
}
static
int
instance_setattro
(
Box
*
cls
,
Box
*
attr
,
Box
*
value
)
noexcept
{
try
{
if
(
value
)
{
instanceSetattr
(
cls
,
attr
,
value
);
return
0
;
}
else
{
RELEASE_ASSERT
(
0
,
""
);
}
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
-
1
;
}
}
Box
*
instanceRepr
(
Box
*
_inst
)
{
Box
*
instanceRepr
(
Box
*
_inst
)
{
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
...
@@ -454,5 +470,6 @@ void setupClassobj() {
...
@@ -454,5 +470,6 @@ void setupClassobj() {
instance_cls
->
freeze
();
instance_cls
->
freeze
();
instance_cls
->
tp_getattro
=
instance_getattro
;
instance_cls
->
tp_getattro
=
instance_getattro
;
instance_cls
->
tp_setattro
=
instance_setattro
;
}
}
}
}
src/runtime/objmodel.cpp
View file @
abbbbf48
...
@@ -549,15 +549,18 @@ Box* Box::getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args) {
...
@@ -549,15 +549,18 @@ Box* Box::getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args) {
if
(
rewrite_args
)
if
(
rewrite_args
)
rewrite_args
->
obj
->
addAttrGuard
(
BOX_CLS_OFFSET
,
(
intptr_t
)
cls
);
rewrite_args
->
obj
->
addAttrGuard
(
BOX_CLS_OFFSET
,
(
intptr_t
)
cls
);
// if (attr == "__setattr__" && !rewrite_args)
// printf("");
#if 0
#if 0
if (attr[0] == '_' && attr[1] == '_') {
if (attr[0] == '_' && attr[1] == '_') {
// Only do this logging for potentially-avoidable cases:
if (!rewrite_args && cls != classobj_cls) {
if (attr == "__setattr__")
printf("");
std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr);
std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr);
int id = Stats::getStatId(per_name_stat_name);
int id = Stats::getStatId(per_name_stat_name);
Stats::log(id);
Stats::log(id);
}
}
}
#endif
#endif
box_getattr_slowpath
.
log
();
box_getattr_slowpath
.
log
();
...
...
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