From 3c5efa1e8dfee3d619e1b4fc6f23d6ae29085000 Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Thu, 30 Nov 2017 17:49:35 -0300 Subject: [PATCH] efl_mono: Fix eina_value_set. Instead of messing around with varargs, create individual wrappers for each type supported. The va_list approach was getting problems with float/double on Windows. --- src/bindings/mono/eina_mono/eina_value.cs | 47 +++++++++++----------- src/lib/efl_mono/efl_custom_exports_mono.c | 23 +++++++---- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs index 4ded15b10e..1c9a78ce8d 100644 --- a/src/bindings/mono/eina_mono/eina_value.cs +++ b/src/bindings/mono/eina_mono/eina_value.cs @@ -46,51 +46,51 @@ static internal class UnsafeNativeMethods { [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, string value); + internal static extern bool eina_value_set_wrapper_string(IntPtr handle, string value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, byte value); + internal static extern bool eina_value_set_wrapper_uchar(IntPtr handle, byte value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, sbyte value); + internal static extern bool eina_value_set_wrapper_char(IntPtr handle, sbyte value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, short value); + internal static extern bool eina_value_set_wrapper_short(IntPtr handle, short value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, ushort value); + internal static extern bool eina_value_set_wrapper_ushort(IntPtr handle, ushort value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, int value); + internal static extern bool eina_value_set_wrapper_int(IntPtr handle, int value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, uint value); + internal static extern bool eina_value_set_wrapper_uint(IntPtr handle, uint value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, long value); + internal static extern bool eina_value_set_wrapper_long(IntPtr handle, long value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, ulong value); + internal static extern bool eina_value_set_wrapper_ulong(IntPtr handle, ulong value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, float value); + internal static extern bool eina_value_set_wrapper_float(IntPtr handle, float value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, double value); + internal static extern bool eina_value_set_wrapper_double(IntPtr handle, double value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] - internal static extern bool eina_value_set_wrapper(IntPtr handle, IntPtr value); + internal static extern bool eina_value_set_wrapper_ptr(IntPtr handle, IntPtr value); [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] @@ -908,7 +908,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_uchar(this.Handle, value); } public bool Set(sbyte value) @@ -923,7 +923,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_char(this.Handle, value); } public bool Set(short value) @@ -938,7 +938,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_short(this.Handle, value); } public bool Set(ushort value) @@ -953,7 +953,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_ushort(this.Handle, value); } /// Stores the given uint value. @@ -969,7 +969,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_uint(this.Handle, value); } /// Stores the given int value. @@ -985,7 +985,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_int(this.Handle, value); } /// Stores the given ulong value. @@ -1001,7 +1001,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_ulong(this.Handle, value); } /// Stores the given int value. @@ -1017,7 +1017,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_long(this.Handle, value); } /// Stores the given int value. @@ -1034,8 +1034,7 @@ public class Value : IDisposable, IComparable, IEquatable throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - Console.WriteLine("Wrapper Set({0})", value); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_float(this.Handle, value); } /// Stores the given int value. @@ -1051,7 +1050,7 @@ public class Value : IDisposable, IComparable, IEquatable if (!GetValueType().IsNumeric()) throw (new ArgumentException( "Trying to set numeric value on a non-numeric eina.Value")); - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_double(this.Handle, value); } /// Stores the given string value. @@ -1068,7 +1067,7 @@ public class Value : IDisposable, IComparable, IEquatable throw (new ArgumentException( "Trying to set non-string value on a string eina.Value")); // No need to worry about ownership as eina_value_set will copy the passed string. - return eina_value_set_wrapper(this.Handle, value); + return eina_value_set_wrapper_string(this.Handle, value); } /// Stores the given value into this value. The target value must be an optional. diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c index 16b2977db9..ac38ac7fa9 100644 --- a/src/lib/efl_mono/efl_custom_exports_mono.c +++ b/src/lib/efl_mono/efl_custom_exports_mono.c @@ -323,15 +323,24 @@ EAPI size_t eina_value_sizeof() return sizeof(Eina_Value); } -EAPI Eina_Bool eina_value_set_wrapper(Eina_Value *value, ...) -{ - va_list argp; - va_start(argp, value); - Eina_Bool ret = eina_value_vset(value, argp); - va_end(argp); - return ret; +#define EINA_SET_WRAPPER(N, T) EAPI Eina_Bool eina_value_set_wrapper_##N(Eina_Value *value, T new_value) \ +{ \ + return eina_value_set(value, new_value); \ } +EINA_SET_WRAPPER(char, char) +EINA_SET_WRAPPER(uchar, unsigned char) +EINA_SET_WRAPPER(short, short) +EINA_SET_WRAPPER(ushort, unsigned short) +EINA_SET_WRAPPER(int, int) +EINA_SET_WRAPPER(uint, unsigned int) +EINA_SET_WRAPPER(long, long) +EINA_SET_WRAPPER(ulong, unsigned long) +EINA_SET_WRAPPER(float, float) +EINA_SET_WRAPPER(double, double) +EINA_SET_WRAPPER(string, const char *) +EINA_SET_WRAPPER(ptr, void *) + EAPI Eina_Bool eina_value_setup_wrapper(Eina_Value *value, const Eina_Value_Type *type) {