Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
ac3536e9
Commit
ac3536e9
authored
Oct 31, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a None check, except for plain extension type names
parent
80359387
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+7
-1
tests/run/tp_new.pyx
tests/run/tp_new.pyx
+13
-13
No files found.
Cython/Compiler/Optimize.py
View file @
ac3536e9
...
@@ -1076,9 +1076,15 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
...
@@ -1076,9 +1076,15 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyrexTypes
.
py_object_type
,
None
)
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyrexTypes
.
py_object_type
,
None
)
])
])
if
not
type_arg
.
type_entry
:
# arbitrary variable, needs a None check for safety
type_arg
=
ExprNodes
.
NoneCheckNode
(
type_arg
,
"PyExc_TypeError"
,
"object.__new__(X): X is not a type object (NoneType)"
)
return
ExprNodes
.
PythonCapiCallNode
(
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_tp_new"
,
func_type
,
node
.
pos
,
"__Pyx_tp_new"
,
func_type
,
args
=
args
,
args
=
[
type_arg
]
,
utility_code
=
tpnew_utility_code
,
utility_code
=
tpnew_utility_code
,
is_temp
=
node
.
is_temp
is_temp
=
node
.
is_temp
)
)
...
...
tests/run/tp_new.pyx
View file @
ac3536e9
...
@@ -41,6 +41,17 @@ def make_new_builtin():
...
@@ -41,6 +41,17 @@ def make_new_builtin():
m
=
tuple
.
__new__
(
tuple
)
m
=
tuple
.
__new__
(
tuple
)
return
m
return
m
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
make_new_none
(
type
t
=
None
):
"""
>>> isinstance(make_new_none(), MyType)
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
m
=
t
.
__new__
(
t
)
return
m
# these cannot:
# these cannot:
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
...
@@ -81,24 +92,13 @@ def make_new_args(type t1=None, type t2=None):
...
@@ -81,24 +92,13 @@ def make_new_args(type t1=None, type t2=None):
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_none
(
type
t1
=
None
,
type
t2
=
None
):
def
make_new_none_typed
(
tuple
t
=
None
):
"""
>>> isinstance(make_new_none(), MyType)
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
m
=
t1
.
__new__
(
t2
)
return
m
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_none_typed
(
tuple
t1
=
None
,
tuple
t2
=
None
):
"""
"""
>>> isinstance(make_new_none(), MyType)
>>> isinstance(make_new_none(), MyType)
Traceback (most recent call last):
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
"""
m
=
t
1
.
__new__
(
t2
)
m
=
t
.
__new__
(
t
)
return
m
return
m
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
...
...
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