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
c79cce9f
Commit
c79cce9f
authored
Mar 29, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get assertInitNone working
parent
d30d7780
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
src/runtime/types.cpp
src/runtime/types.cpp
+14
-5
test/tests/init_must_return_none.py
test/tests/init_must_return_none.py
+5
-4
No files found.
src/runtime/types.cpp
View file @
c79cce9f
...
...
@@ -632,10 +632,13 @@ static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args
}
// For use on __init__ return values
static
void
assertInitNone
(
Box
*
obj
)
{
if
(
obj
!=
None
)
{
raiseExcHelper
(
TypeError
,
"__init__() should return None, not '%s'"
,
getTypeName
(
obj
));
static
Box
*
assertInitNone
(
STOLEN
(
Box
*
)
rtn
,
STOLEN
(
Box
*
)
obj
)
{
AUTO_DECREF
(
rtn
);
if
(
rtn
!=
None
)
{
Py_DECREF
(
obj
);
raiseExcHelper
(
TypeError
,
"__init__() should return None, not '%s'"
,
getTypeName
(
rtn
));
}
return
obj
;
}
static
PyObject
*
cpythonTypeCall
(
BoxedClass
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
...
...
@@ -1218,7 +1221,12 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
rewrite_args
=
NULL
;
}
else
{
assert
(
S
==
CXX
&&
"this need to be converted"
);
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
assertInitNone
,
srewrite_args
.
out_rtn
);
auto
new_r_made
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
assertInitNone
,
srewrite_args
.
out_rtn
,
r_made
);
r_made
->
refConsumed
();
new_r_made
->
setType
(
RefType
::
OWNED
);
r_made
=
new_r_made
;
srewrite_args
.
out_rtn
->
refConsumed
();
}
}
else
{
initrtn
=
runtimeCallInternal
<
S
,
NOT_REWRITABLE
>
(
init_attr
,
NULL
,
argspec
,
made
,
arg2
,
arg3
,
args
,
...
...
@@ -1240,7 +1248,8 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
return
NULL
;
}
}
else
assertInitNone
(
autoDecref
(
initrtn
));
made
=
assertInitNone
(
initrtn
,
made
);
// assertInitNone is optimized for the rewriter case; this call
// here could be improved if it is an issue.
}
else
{
// Otherwise, just call tp_init. This will work out well for extension classes, and no worse
// than failing the rewrite for Python non-extension non-functions (when does that happen?).
...
...
test/tests/init_must_return_none.py
View file @
c79cce9f
# expected: reffail
# should_error
# As the test filename says, init functions must return None.
# This file tests that; it also makes sure that it gets tested
# when in a patchpoint.
...
...
@@ -12,5 +10,8 @@ class C(object):
# Call it in a loop to make sure that the constructor gets inlined:
for
i
in
xrange
(
1000
):
c
=
C
(
i
)
print
c
.
n
try
:
c
=
C
(
i
)
print
c
.
n
except
Exception
as
e
:
print
e
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