Commit ac3536e9 authored by Stefan Behnel's avatar Stefan Behnel

add a None check, except for plain extension type names

parent 80359387
...@@ -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
) )
......
...@@ -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 = t1.__new__(t2) m = t.__new__(t)
return m return m
@cython.test_assert_path_exists('//SimpleCallNode/AttributeNode') @cython.test_assert_path_exists('//SimpleCallNode/AttributeNode')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment