Commit 7f36b856 authored by Stefan Behnel's avatar Stefan Behnel

consider void* the independent spanning type of any two incompatible pointer types

parent 8dabe05f
...@@ -3711,6 +3711,9 @@ def independent_spanning_type(type1, type2): ...@@ -3711,6 +3711,9 @@ def independent_spanning_type(type1, type2):
return py_object_type return py_object_type
span_type = _spanning_type(type1, type2) span_type = _spanning_type(type1, type2)
if span_type is None: if span_type is None:
if type1.is_ptr and type2.is_ptr:
# incompatible pointers, void* will do as a result
return c_void_ptr_type
return error_type return error_type
return span_type return span_type
......
cimport cython
cdef char* c_string = b'abcdefg' cdef char* c_string = b'abcdefg'
cdef void* void_ptr = c_string cdef void* void_ptr = c_string
...@@ -60,3 +61,29 @@ def bool_binop_truth(int x): ...@@ -60,3 +61,29 @@ def bool_binop_truth(int x):
print True print True
if c_string and x or not (void_ptr or int_ptr and float_ptr) or x: if c_string and x or not (void_ptr or int_ptr and float_ptr) or x:
print True print True
def binop_voidptr(int x, long y, char* z):
"""
>>> binop_voidptr(1, 3, b'abc')
'void *'
"""
result = &x and &y and z
return cython.typeof(result)
def cond_expr_voidptr(int x, long y, char* z):
"""
>>> cond_expr_voidptr(0, -1, b'abc')
('void *', 0)
>>> cond_expr_voidptr(-1, 0, b'abc')
('void *', -1)
>>> cond_expr_voidptr(-1, 0, b'')
('void *', 0)
>>> cond_expr_voidptr(0, -1, b'')
('void *', -1)
"""
result = &x if len(z) else &y
assert sizeof(long) >= sizeof(int)
assert -1 == <int>(-1L)
return cython.typeof(result), (<int*>result)[0]
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