%implicitconv will now accept None where the implicit conversion takes a C/C++ pointer.
Problem highlighted by Bo Peng on the swig-user mailing list. SF patch #230.
This commit is contained in:
parent
628b4710e5
commit
1cc735df5e
4 changed files with 79 additions and 5 deletions
|
|
@ -46,7 +46,6 @@
|
|||
Foo(double){ ii = 2;}
|
||||
explicit Foo(char *s){ii = 3;}
|
||||
Foo(const Foo& f){ ii = f.ii;}
|
||||
|
||||
};
|
||||
|
||||
struct Bar
|
||||
|
|
@ -57,11 +56,31 @@
|
|||
Bar(const Foo& ff){ ii = ff.ii;}
|
||||
};
|
||||
|
||||
|
||||
int get_b(const Bar&b) { return b.ii; }
|
||||
|
||||
Foo foo;
|
||||
|
||||
}
|
||||
|
||||
%template(A_int) A_T<int>;
|
||||
|
||||
|
||||
/****************** None handling *********************/
|
||||
|
||||
%inline
|
||||
{
|
||||
struct BB {};
|
||||
struct AA
|
||||
{
|
||||
int ii;
|
||||
AA(int i) { ii = 1; }
|
||||
AA(double d) { ii = 2; }
|
||||
AA(const B* b) { ii = 3; }
|
||||
explicit AA(char *s) { ii = 4; }
|
||||
AA(const BB& b) { ii = 5; }
|
||||
|
||||
int get() const { return ii; }
|
||||
};
|
||||
|
||||
int get_AA_val(AA a) { return a.ii; }
|
||||
int get_AA_ref(const AA& a) { return a.ii; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,14 @@ check(1, A(1).get())
|
|||
check(2, A(1.0).get())
|
||||
check(3, A(B()).get())
|
||||
check(4, A("hello").get())
|
||||
try:
|
||||
check(3, A(None).get())
|
||||
raise RuntimeError
|
||||
except ValueError:
|
||||
# ValueError: invalid null reference in method 'new_A', argument 1 of type 'B const &'
|
||||
# Arguably A(char *) should be chosen, but there is a bug to do with None passed to methods overloaded by value,
|
||||
# references and pointers to different types, where pointers ought to be given a slightly higher precedence.
|
||||
pass
|
||||
|
||||
check(1, get(1))
|
||||
check(2, get(1.0))
|
||||
|
|
@ -71,3 +79,38 @@ try:
|
|||
except TypeError:
|
||||
pass
|
||||
|
||||
#### Class testing None ####
|
||||
|
||||
# No implicit conversion
|
||||
check(1, AA(1).get())
|
||||
check(2, AA(1.0).get())
|
||||
check(3, AA(B()).get())
|
||||
check(3, AA(None).get())
|
||||
check(4, AA("hello").get())
|
||||
check(5, AA(BB()).get())
|
||||
|
||||
check(1, get_AA_val(1))
|
||||
check(2, get_AA_val(1.0))
|
||||
check(3, get_AA_val(B()))
|
||||
check(3, get_AA_val(None))
|
||||
check(5, get_AA_val(BB()))
|
||||
|
||||
# Explicit constructor:
|
||||
try:
|
||||
check(4, get_AA_val("hello"))
|
||||
raise RuntimeError
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
check(1, get_AA_ref(1))
|
||||
check(2, get_AA_ref(1.0))
|
||||
check(3, get_AA_ref(B()))
|
||||
check(3, get_AA_ref(None))
|
||||
check(5, get_AA_ref(BB()))
|
||||
|
||||
# Explicit constructor:
|
||||
try:
|
||||
check(4, get_AA_ref("hello"))
|
||||
raise RuntimeError
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue