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
7c1d21f2
Commit
7c1d21f2
authored
Aug 18, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow rewriting getattr() with unicode arguments
parent
87fe352e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+19
-14
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
7c1d21f2
...
...
@@ -472,6 +472,8 @@ Box* delattrFunc(Box* obj, Box* _str) {
}
static
Box
*
getattrFuncHelper
(
Box
*
return_val
,
Box
*
obj
,
BoxedString
*
str
,
Box
*
default_val
)
noexcept
{
assert
(
PyString_Check
(
str
));
if
(
return_val
)
return
return_val
;
...
...
@@ -492,21 +494,24 @@ static Box* getattrFuncHelper(Box* return_val, Box* obj, BoxedString* str, Box*
template
<
ExceptionStyle
S
>
Box
*
getattrFuncInternal
(
BoxedFunctionBase
*
func
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
if
(
argspec
!=
ArgPassSpec
(
2
,
0
,
false
,
false
)
||
argspec
!=
ArgPassSpec
(
3
,
0
,
false
,
false
))
{
static
Box
*
defaults
[]
=
{
NULL
};
bool
rewrite_success
=
false
;
rearrangeArguments
(
ParamReceiveSpec
(
3
,
1
,
false
,
false
),
NULL
,
"getattr"
,
defaults
,
rewrite_arg
s
,
rewrite_success
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
NULL
,
keyword_names
);
rearrangeArguments
(
ParamReceiveSpec
(
3
,
1
,
false
,
false
),
NULL
,
"getattr"
,
defaults
,
rewrite_args
,
rewrite_succes
s
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
NULL
,
keyword_names
);
if
(
!
rewrite_success
)
rewrite_args
=
NULL
;
}
Box
*
obj
=
arg1
;
Box
*
_str
=
arg2
;
Box
*
default_value
=
arg3
;
if
(
rewrite_args
)
{
if
(
!
PyString_Check
(
_str
))
// We need to make sure that the attribute string will be the same.
// Even though the passed string might not be the exact attribute name
// that we end up looking up (because we need to encode it or intern it),
// guarding on that object means (for strings and unicode) that the string
// value is fixed.
if
(
!
PyString_CheckExact
(
_str
)
&&
!
PyUnicode_CheckExact
(
_str
))
rewrite_args
=
NULL
;
else
rewrite_args
->
arg2
->
addGuard
((
intptr_t
)
arg2
);
...
...
@@ -531,10 +536,8 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
}
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
_str
);
if
(
!
PyString_CHECK_INTERNED
(
str
))
{
if
(
!
PyString_CHECK_INTERNED
(
str
))
internStringMortalInplace
(
str
);
rewrite_args
=
NULL
;
}
Box
*
rtn
;
RewriterVar
*
r_rtn
;
...
...
@@ -554,8 +557,10 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
}
if
(
rewrite_args
)
{
RewriterVar
*
final_rtn
=
rewrite_args
->
rewriter
->
call
(
false
,
(
void
*
)
getattrFuncHelper
,
r_rtn
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
,
rewrite_args
->
arg3
);
assert
(
PyString_CHECK_INTERNED
(
str
)
==
SSTATE_INTERNED_IMMORTAL
);
RewriterVar
*
r_str
=
rewrite_args
->
rewriter
->
loadConst
((
intptr_t
)
str
,
Location
::
forArg
(
2
));
RewriterVar
*
final_rtn
=
rewrite_args
->
rewriter
->
call
(
false
,
(
void
*
)
getattrFuncHelper
,
r_rtn
,
rewrite_args
->
arg1
,
r_str
,
rewrite_args
->
arg3
);
if
(
S
==
CXX
)
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
final_rtn
);
...
...
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