Change in default behaviour wrapping C++ bool for Python.
Only a Python True or False will now work for C++ bool parameters. This fixes overloading bool with other types.
This commit is contained in:
parent
7f45cbd178
commit
504c2030bb
11 changed files with 251 additions and 11 deletions
|
|
@ -17,10 +17,10 @@ halve_in_place(dv)
|
|||
|
||||
|
||||
bv = BoolVector(4)
|
||||
bv[0]= 1
|
||||
bv[1]= 0
|
||||
bv[2]= 4
|
||||
bv[3]= 0
|
||||
bv[0]= bool(1)
|
||||
bv[1]= bool(0)
|
||||
bv[2]= bool(4)
|
||||
bv[3]= bool(0)
|
||||
|
||||
if bv[0] != bv[2]:
|
||||
raise RuntimeError,"bad std::vector<bool> mapping"
|
||||
|
|
|
|||
55
Examples/test-suite/python/overload_bool_runme.py
Normal file
55
Examples/test-suite/python/overload_bool_runme.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import overload_bool
|
||||
|
||||
# Overloading bool, int, string
|
||||
if overload_bool.overloaded(True) != "bool":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded(False) != "bool":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
if overload_bool.overloaded(0) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded(1) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded(2) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
if overload_bool.overloaded("1234") != "string":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
# Test bool masquerading as int
|
||||
if overload_bool.intfunction(True) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.intfunction(False) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
# Test int masquerading as bool
|
||||
# Not possible
|
||||
|
||||
|
||||
#############################################
|
||||
|
||||
# Overloading bool, int, string
|
||||
if overload_bool.overloaded_ref(True) != "bool":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded_ref(False) != "bool":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
if overload_bool.overloaded_ref(0) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded_ref(1) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.overloaded_ref(2) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
if overload_bool.overloaded_ref("1234") != "string":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
# Test bool masquerading as int
|
||||
if overload_bool.intfunction_ref(True) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
if overload_bool.intfunction_ref(False) != "int":
|
||||
raise RuntimeError("wrong!")
|
||||
|
||||
# Test int masquerading as bool
|
||||
# Not possible
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ if ref_float(3.5) != 3.5:
|
|||
if ref_double(3.5) != 3.5:
|
||||
raise RuntimeError
|
||||
|
||||
if ref_bool(1) != 1:
|
||||
if ref_bool(True) != True:
|
||||
raise RuntimeError
|
||||
|
||||
if ref_char('x') != 'x':
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ if getconstTC().num != 33:
|
|||
raise RuntimeError
|
||||
|
||||
# primitive reference variables
|
||||
cvar.var_bool = createref_bool(0)
|
||||
if value_bool(cvar.var_bool) != 0:
|
||||
cvar.var_bool = createref_bool(False)
|
||||
if value_bool(cvar.var_bool) != False:
|
||||
raise RuntimeError
|
||||
|
||||
cvar.var_bool = createref_bool(1)
|
||||
if value_bool(cvar.var_bool) != 1:
|
||||
cvar.var_bool = createref_bool(True)
|
||||
if value_bool(cvar.var_bool) != True:
|
||||
raise RuntimeError
|
||||
|
||||
cvar.var_char = createref_char('w')
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ for i in range(0,len(m)):
|
|||
if m[i][j] != im[i][j]:
|
||||
raise RuntimeError, "bad getslice"
|
||||
|
||||
m = ((1,0,1),(1,1),(1,1))
|
||||
m = ((True,False,True),(True,True),(True,True))
|
||||
im = std_containers.midentb(m)
|
||||
for i in range(0,len(m)):
|
||||
for j in range(0,len(m[i])):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue