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
f3494350
Commit
f3494350
authored
Sep 24, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check return convention everywhere
This checking should probably be enforced by the API.
parent
01c3fc5c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
9 deletions
+42
-9
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+6
-1
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+2
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+30
-8
src/runtime/types.cpp
src/runtime/types.cpp
+4
-0
No files found.
src/capi/typeobject.cpp
View file @
f3494350
...
@@ -933,11 +933,16 @@ Box* slotTpGetattrHookInternal(Box* self, BoxedString* name, GetattrRewriteArgs*
...
@@ -933,11 +933,16 @@ Box* slotTpGetattrHookInternal(Box* self, BoxedString* name, GetattrRewriteArgs*
getattribute
=
typeLookup
(
self
->
cls
,
_getattribute_str
,
&
grewrite_args
);
getattribute
=
typeLookup
(
self
->
cls
,
_getattribute_str
,
&
grewrite_args
);
if
(
!
grewrite_args
.
out_success
)
if
(
!
grewrite_args
.
out_success
)
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
else
if
(
getattribute
)
else
if
(
getattribute
)
{
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_getattribute
=
grewrite_args
.
out_rtn
;
r_getattribute
=
grewrite_args
.
out_rtn
;
}
else
{
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
NO_RETURN
);
}
}
else
{
}
else
{
getattribute
=
typeLookup
(
self
->
cls
,
_getattribute_str
,
NULL
);
getattribute
=
typeLookup
(
self
->
cls
,
_getattribute_str
,
NULL
);
}
}
// Not sure why CPython checks if getattribute is NULL since I don't think that should happen.
// Not sure why CPython checks if getattribute is NULL since I don't think that should happen.
// Is there some legacy way of creating types that don't inherit from object? Anyway, I think we
// Is there some legacy way of creating types that don't inherit from object? Anyway, I think we
// have the right behavior even if getattribute was somehow NULL, but add an assert because that
// have the right behavior even if getattribute was somehow NULL, but add an assert because that
...
...
src/runtime/classobj.cpp
View file @
f3494350
...
@@ -313,6 +313,8 @@ static Box* instanceGetattributeSimple(BoxedInstance* inst, BoxedString* attr_st
...
@@ -313,6 +313,8 @@ static Box* instanceGetattributeSimple(BoxedInstance* inst, BoxedString* attr_st
r
=
classLookup
(
inst
->
inst_cls
,
attr_str
,
rewriter_args
?
&
grewriter_inst_args
:
NULL
);
r
=
classLookup
(
inst
->
inst_cls
,
attr_str
,
rewriter_args
?
&
grewriter_inst_args
:
NULL
);
if
(
!
grewriter_inst_args
.
out_success
)
if
(
!
grewriter_inst_args
.
out_success
)
rewriter_args
=
NULL
;
rewriter_args
=
NULL
;
else
assert
(
grewriter_inst_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
if
(
r
)
{
if
(
r
)
{
Box
*
rtn
=
processDescriptor
(
r
,
inst
,
inst
->
inst_cls
);
Box
*
rtn
=
processDescriptor
(
r
,
inst
,
inst
->
inst_cls
);
...
...
src/runtime/objmodel.cpp
View file @
f3494350
...
@@ -1592,6 +1592,7 @@ extern "C" Box* getclsattr(Box* obj, BoxedString* attr) {
...
@@ -1592,6 +1592,7 @@ extern "C" Box* getclsattr(Box* obj, BoxedString* attr) {
gotten
=
getclsattrInternal
(
obj
,
attr
,
&
rewrite_args
);
gotten
=
getclsattrInternal
(
obj
,
attr
,
&
rewrite_args
);
if
(
rewrite_args
.
out_success
&&
gotten
)
{
if
(
rewrite_args
.
out_success
&&
gotten
)
{
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
rewriter
->
commitReturning
(
rewrite_args
.
out_rtn
);
rewriter
->
commitReturning
(
rewrite_args
.
out_rtn
);
}
}
#endif
#endif
...
@@ -1715,6 +1716,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
...
@@ -1715,6 +1716,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
if
(
!
grewrite_args
.
out_success
)
{
if
(
!
grewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
if
(
_get_
)
{
}
else
if
(
_get_
)
{
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_get
=
grewrite_args
.
out_rtn
;
r_get
=
grewrite_args
.
out_rtn
;
}
}
}
else
{
}
else
{
...
@@ -1737,6 +1739,9 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
...
@@ -1737,6 +1739,9 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
&
grewrite_args
);
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
&
grewrite_args
);
if
(
!
grewrite_args
.
out_success
)
{
if
(
!
grewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
{
assert
(
grewrite_args
.
out_return_convention
==
(
_set_
?
GetattrRewriteArgs
::
VALID_RETURN
:
GetattrRewriteArgs
::
NO_RETURN
));
}
}
}
else
{
}
else
{
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
NULL
);
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
NULL
);
...
@@ -1847,6 +1852,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
...
@@ -1847,6 +1852,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
if
(
!
grewrite_args
.
out_success
)
{
if
(
!
grewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
if
(
val
)
{
}
else
if
(
val
)
{
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_val
=
grewrite_args
.
out_rtn
;
r_val
=
grewrite_args
.
out_rtn
;
}
}
}
else
{
}
else
{
...
@@ -2190,13 +2196,14 @@ void setattrGeneric(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* r
...
@@ -2190,13 +2196,14 @@ void setattrGeneric(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* r
// (otherwise no need to check descriptor logic)
// (otherwise no need to check descriptor logic)
if
(
rewrite_args
)
{
if
(
rewrite_args
)
{
RewriterVar
*
r_cls
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
Box
,
cls
),
Location
::
any
());
RewriterVar
*
r_cls
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
Box
,
cls
),
Location
::
any
());
GetattrRewriteArgs
c
rewrite_args
(
rewrite_args
->
rewriter
,
r_cls
,
rewrite_args
->
rewriter
->
getReturnDestination
());
GetattrRewriteArgs
g
rewrite_args
(
rewrite_args
->
rewriter
,
r_cls
,
rewrite_args
->
rewriter
->
getReturnDestination
());
descr
=
typeLookup
(
obj
->
cls
,
attr
,
&
c
rewrite_args
);
descr
=
typeLookup
(
obj
->
cls
,
attr
,
&
g
rewrite_args
);
if
(
!
c
rewrite_args
.
out_success
)
{
if
(
!
g
rewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
if
(
descr
)
{
}
else
if
(
descr
)
{
r_descr
=
crewrite_args
.
out_rtn
;
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_descr
=
grewrite_args
.
out_rtn
;
}
}
}
else
{
}
else
{
descr
=
typeLookup
(
obj
->
cls
,
attr
,
NULL
);
descr
=
typeLookup
(
obj
->
cls
,
attr
,
NULL
);
...
@@ -2213,12 +2220,13 @@ void setattrGeneric(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* r
...
@@ -2213,12 +2220,13 @@ void setattrGeneric(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* r
if
(
rewrite_args
)
{
if
(
rewrite_args
)
{
RewriterVar
*
r_cls
=
r_descr
->
getAttr
(
offsetof
(
Box
,
cls
),
Location
::
any
());
RewriterVar
*
r_cls
=
r_descr
->
getAttr
(
offsetof
(
Box
,
cls
),
Location
::
any
());
GetattrRewriteArgs
t
rewrite_args
(
rewrite_args
->
rewriter
,
r_cls
,
Location
::
any
());
GetattrRewriteArgs
g
rewrite_args
(
rewrite_args
->
rewriter
,
r_cls
,
Location
::
any
());
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
&
t
rewrite_args
);
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
&
g
rewrite_args
);
if
(
!
t
rewrite_args
.
out_success
)
{
if
(
!
g
rewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
if
(
_set_
)
{
}
else
if
(
_set_
)
{
r_set
=
trewrite_args
.
out_rtn
;
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_set
=
grewrite_args
.
out_rtn
;
}
}
}
else
{
}
else
{
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
NULL
);
_set_
=
typeLookup
(
descr
->
cls
,
set_str
,
NULL
);
...
@@ -2313,6 +2321,7 @@ extern "C" void setattr(Box* obj, BoxedString* attr, Box* attr_val) {
...
@@ -2313,6 +2321,7 @@ extern "C" void setattr(Box* obj, BoxedString* attr, Box* attr_val) {
if
(
rewrite_args
.
out_success
)
{
if
(
rewrite_args
.
out_success
)
{
r_setattr
=
rewrite_args
.
out_rtn
;
r_setattr
=
rewrite_args
.
out_rtn
;
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
// TODO this is not good enough, since the object could get collected:
// TODO this is not good enough, since the object could get collected:
r_setattr
->
addGuard
((
intptr_t
)
setattr
);
r_setattr
->
addGuard
((
intptr_t
)
setattr
);
}
else
{
}
else
{
...
@@ -2841,6 +2850,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallRewrit
...
@@ -2841,6 +2850,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallRewrit
if
(
!
grewrite_args
.
out_success
||
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
NOEXC_POSSIBLE
)
{
if
(
!
grewrite_args
.
out_success
||
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
NOEXC_POSSIBLE
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
if
(
val
)
{
}
else
if
(
val
)
{
assert
(
grewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
r_val
=
grewrite_args
.
out_rtn
;
r_val
=
grewrite_args
.
out_rtn
;
}
}
}
else
{
}
else
{
...
@@ -4752,6 +4762,9 @@ static Box* callItemOrSliceAttr(Box* target, BoxedString* item_str, BoxedString*
...
@@ -4752,6 +4762,9 @@ static Box* callItemOrSliceAttr(Box* target, BoxedString* item_str, BoxedString*
slice_attr
=
typeLookup
(
target
->
cls
,
slice_str
,
&
grewrite_args
);
slice_attr
=
typeLookup
(
target
->
cls
,
slice_str
,
&
grewrite_args
);
if
(
!
grewrite_args
.
out_success
)
{
if
(
!
grewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
}
else
{
assert
(
grewrite_args
.
out_return_convention
==
(
slice_attr
?
GetattrRewriteArgs
::
VALID_RETURN
:
GetattrRewriteArgs
::
NO_RETURN
));
}
}
}
else
{
}
else
{
slice_attr
=
typeLookup
(
target
->
cls
,
slice_str
,
NULL
);
slice_attr
=
typeLookup
(
target
->
cls
,
slice_str
,
NULL
);
...
@@ -5228,12 +5241,14 @@ extern "C" Box* createBoxedIterWrapperIfNeeded(Box* o) {
...
@@ -5228,12 +5241,14 @@ extern "C" Box* createBoxedIterWrapperIfNeeded(Box* o) {
if
(
!
rewrite_args
.
out_success
)
{
if
(
!
rewrite_args
.
out_success
)
{
rewriter
.
reset
(
NULL
);
rewriter
.
reset
(
NULL
);
}
else
if
(
r
)
{
}
else
if
(
r
)
{
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
rewrite_args
.
out_rtn
->
addGuard
((
uint64_t
)
r
);
rewrite_args
.
out_rtn
->
addGuard
((
uint64_t
)
r
);
if
(
rewrite_args
.
out_success
)
{
if
(
rewrite_args
.
out_success
)
{
rewriter
->
commitReturning
(
r_o
);
rewriter
->
commitReturning
(
r_o
);
return
o
;
return
o
;
}
}
}
else
if
(
!
r
)
{
}
else
if
(
!
r
)
{
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
NO_RETURN
);
RewriterVar
*
var
=
rewriter
.
get
()
->
call
(
true
,
(
void
*
)
createBoxedIterWrapper
,
rewriter
->
getArg
(
0
));
RewriterVar
*
var
=
rewriter
.
get
()
->
call
(
true
,
(
void
*
)
createBoxedIterWrapper
,
rewriter
->
getArg
(
0
));
if
(
rewrite_args
.
out_success
)
{
if
(
rewrite_args
.
out_success
)
{
rewriter
->
commitReturning
(
var
);
rewriter
->
commitReturning
(
var
);
...
@@ -5735,6 +5750,11 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
...
@@ -5735,6 +5750,11 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
r
=
m
->
getattr
(
name
,
&
rewrite_args
);
r
=
m
->
getattr
(
name
,
&
rewrite_args
);
if
(
!
rewrite_args
.
out_success
)
{
if
(
!
rewrite_args
.
out_success
)
{
rewriter
.
reset
(
NULL
);
rewriter
.
reset
(
NULL
);
}
else
{
if
(
r
)
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
else
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
NO_RETURN
);
}
}
if
(
r
)
{
if
(
r
)
{
if
(
rewriter
.
get
())
{
if
(
rewriter
.
get
())
{
...
@@ -5774,6 +5794,8 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
...
@@ -5774,6 +5794,8 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
if
(
!
rtn
||
!
rewrite_args
.
out_success
)
{
if
(
!
rtn
||
!
rewrite_args
.
out_success
)
{
rewriter
.
reset
(
NULL
);
rewriter
.
reset
(
NULL
);
}
else
{
assert
(
rewrite_args
.
out_return_convention
==
GetattrRewriteArgs
::
VALID_RETURN
);
}
}
if
(
rewriter
.
get
())
{
if
(
rewriter
.
get
())
{
...
...
src/runtime/types.cpp
View file @
f3494350
...
@@ -909,6 +909,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
...
@@ -909,6 +909,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
else
{
else
{
assert
(
new_attr
);
assert
(
new_attr
);
assert
(
grewrite_args
.
out_return_convention
=
GetattrRewriteArgs
::
VALID_RETURN
);
r_new
=
grewrite_args
.
out_rtn
;
r_new
=
grewrite_args
.
out_rtn
;
r_new
->
addGuard
((
intptr_t
)
new_attr
);
r_new
->
addGuard
((
intptr_t
)
new_attr
);
}
}
...
@@ -1051,8 +1052,11 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
...
@@ -1051,8 +1052,11 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
rewrite_args
=
NULL
;
rewrite_args
=
NULL
;
else
{
else
{
if
(
init_attr
)
{
if
(
init_attr
)
{
assert
(
grewrite_args
.
out_return_convention
=
GetattrRewriteArgs
::
VALID_RETURN
);
r_init
=
grewrite_args
.
out_rtn
;
r_init
=
grewrite_args
.
out_rtn
;
r_init
->
addGuard
((
intptr_t
)
init_attr
);
r_init
->
addGuard
((
intptr_t
)
init_attr
);
}
else
{
assert
(
grewrite_args
.
out_return_convention
=
GetattrRewriteArgs
::
NO_RETURN
);
}
}
}
}
}
else
{
}
else
{
...
...
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