diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2011-01-24 19:27:06 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2011-01-24 19:27:06 +0000 |
commit | 2f0dc16b2e011edcc3427c660a89a055d3e4ad4e (patch) | |
tree | ee041985ac5804d5542ca9b8cd5d9a7576761134 | |
parent | 2a449306f18ec59c81d06072a5a3ab4799029ec1 (diff) | |
download | swig-2f0dc16b2e011edcc3427c660a89a055d3e4ad4e.tar.gz |
Fix C# typemaps.i so that %apply works doesn't break function returns using the same types, for example, %apply int &INPUT { int & } won't break 'int &foo(int &x);'
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12400 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Examples/test-suite/li_typemaps_apply.i | 46 | ||||
-rw-r--r-- | Lib/csharp/typemaps.i | 21 |
2 files changed, 55 insertions, 12 deletions
diff --git a/Examples/test-suite/li_typemaps_apply.i b/Examples/test-suite/li_typemaps_apply.i new file mode 100644 index 000000000..ecb3f87b6 --- /dev/null +++ b/Examples/test-suite/li_typemaps_apply.i @@ -0,0 +1,46 @@ +%module li_typemaps_apply + +// Test %apply to global primitive type references/pointers to make sure the return types are still okay... mainly for the strongly typed languages. + +%include "typemaps.i" + +#if !defined(SWIGJAVA) // Needs asymmetric type marshalling support for this testcase to work + +%define TMAPS(PRIMTYPE, NAME) +%apply PRIMTYPE *INPUT { PRIMTYPE * } +%apply PRIMTYPE &INPUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *input_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; return &stat; } +PRIMTYPE &input_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; return stat; } +%} + +%apply PRIMTYPE *OUTPUT { PRIMTYPE * } +%apply PRIMTYPE &OUTPUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *output_ptr_##NAME(PRIMTYPE x, PRIMTYPE *v) { static PRIMTYPE stat; stat = x; *v = x; return &stat; } +PRIMTYPE &output_ref_##NAME(PRIMTYPE x, PRIMTYPE &v) { static PRIMTYPE stat; stat = x; v = x; return stat; } +%} + +%apply PRIMTYPE *INOUT { PRIMTYPE * } +%apply PRIMTYPE &INOUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *inout_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; *v = *v; return &stat; } +PRIMTYPE &inout_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; v = v; return stat; } +%} +%enddef + +TMAPS(bool, bool) +TMAPS(int, int) +TMAPS(short, short) +TMAPS(long, long) +TMAPS(unsigned int, uint) +TMAPS(unsigned short, ushort) +TMAPS(unsigned long, ulong) +TMAPS(unsigned char, uchar) +TMAPS(signed char, schar) +TMAPS(float, float) +TMAPS(double, double) +TMAPS(long long, longlong) +TMAPS(unsigned long long, ulonglong) + +#endif diff --git a/Lib/csharp/typemaps.i b/Lib/csharp/typemaps.i index d50e5c46d..7bca83c12 100644 --- a/Lib/csharp/typemaps.i +++ b/Lib/csharp/typemaps.i @@ -51,13 +51,12 @@ or you can use the %apply directive : In C# you could then use it like this: double answer = modulename.fadd(10.0, 20.0); - */ %define INPUT_TYPEMAP(TYPE, CTYPE, CSTYPE) -%typemap(ctype) TYPE *INPUT, TYPE &INPUT "CTYPE" -%typemap(imtype) TYPE *INPUT, TYPE &INPUT "CSTYPE" -%typemap(cstype) TYPE *INPUT, TYPE &INPUT "CSTYPE" +%typemap(ctype, out="void *") TYPE *INPUT, TYPE &INPUT "CTYPE" +%typemap(imtype, out="IntPtr") TYPE *INPUT, TYPE &INPUT "CSTYPE" +%typemap(cstype, out="$csclassname") TYPE *INPUT, TYPE &INPUT "CSTYPE" %typemap(csin) TYPE *INPUT, TYPE &INPUT "$csinput" %typemap(csdirectorin) TYPE *INPUT, TYPE &INPUT "$iminput" %typemap(csdirectorout) TYPE *INPUT, TYPE &INPUT "$cscall" @@ -143,18 +142,16 @@ value returned in the second output parameter. In C# you would use it like this: double dptr; double fraction = modulename.modf(5, out dptr); - */ %define OUTPUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE) -%typemap(ctype) TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *" -%typemap(imtype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" -%typemap(cstype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" +%typemap(ctype, out="void *") TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *" +%typemap(imtype, out="IntPtr") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" +%typemap(cstype, out="$csclassname") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE" %typemap(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput" %typemap(csdirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$iminput" %typemap(csdirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$cscall" - %typemap(in) TYPE *OUTPUT, TYPE &OUTPUT %{ $1 = ($1_ltype)$input; %} @@ -250,9 +247,9 @@ of the function return value. */ %define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE) -%typemap(ctype) TYPE *INOUT, TYPE &INOUT "CTYPE *" -%typemap(imtype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE" -%typemap(cstype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE" +%typemap(ctype, out="void *") TYPE *INOUT, TYPE &INOUT "CTYPE *" +%typemap(imtype, out="IntPtr") TYPE *INOUT, TYPE &INOUT "ref CSTYPE" +%typemap(cstype, out="$csclassname") TYPE *INOUT, TYPE &INOUT "ref CSTYPE" %typemap(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput" %typemap(csdirectorin) TYPE *INOUT, TYPE &INOUT "$iminput" %typemap(csdirectorout) TYPE *INOUT, TYPE &INOUT "$cscall" |