#if defined(WIN32) && defined (_MSC_VER)
#define LIBTEST_API __declspec(dllexport)
-#else
+#elif defined(__GNUC__)
+#define LIBTEST_API __attribute__ ((visibility ("default")))
+#else
#define LIBTEST_API
#endif
return a.i1;
}
+struct FI {
+ float f1;
+ float f2;
+ float f3;
+};
+
+struct NestedFloat {
+ struct FI fi;
+ float f4;
+};
+
+LIBTEST_API struct NestedFloat STDCALL
+mono_return_nested_float (void)
+{
+ struct NestedFloat f;
+ f.fi.f1 = 1.0;
+ f.fi.f2 = 2.0;
+ f.fi.f3 = 3.0;
+ f.f4 = 4.0;
+ return f;
+}
+
LIBTEST_API int STDCALL
mono_test_many_int_arguments (int a, int b, int c, int d, int e,
int f, int g, int h, int i, int j);
return 0;
}
-
LIBTEST_API int STDCALL
mono_test_empty_pinvoke (int i)
{
return 0;
}
+LIBTEST_API int STDCALL
+mono_test_marshal_out_byref_array_out_size_param (int **out_arr, int *out_len)
+{
+ int *arr;
+ int i, len;
+
+ len = 4;
+ arr = marshal_alloc (sizeof (gint32) * len);
+ for (i = 0; i < len; ++i)
+ arr [i] = i;
+ *out_arr = arr;
+ *out_len = len;
+
+ return 0;
+}
+
LIBTEST_API int STDCALL
mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
{
return 1;
}
+typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
+
+LIBTEST_API int STDCALL
+mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
+{
+ simplestruct ss2;
+ int res;
+
+ memcpy (&ss2, ss, sizeof (simplestruct));
+
+ res = func (a, ss, b);
+ if (res) {
+ printf ("mono_test_marshal_in_struct () failed: %d\n", res);
+ return 1;
+ }
+
+ /* Check that no modifications is made to the struct */
+ if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
+ return 0;
+ else
+ return 1;
+}
+
typedef struct {
int a;
SimpleDelegate func, func2, func3;
LIBTEST_API int STDCALL
mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
{
- int res;
-
- res = delegate (NULL);
-
+ delegate (NULL);
return 0;
}
}
LIBTEST_API int STDCALL
-mono_test_marshal_stringbuilder2 (char *s, int n)
+mono_test_marshal_stringbuilder_append (char *s, int length)
{
- const char m[] = "EFGH";
+ const char out_sentinel[] = "CSHARP_";
+ const char out_len = strlen (out_sentinel);
+
+ for (int i=0; i < length; i++) {
+ s [i] = out_sentinel [i % out_len];
+ }
+
+ s [length] = '\0';
+
- strncpy(s, m, n);
- s [n] = '\0';
return 0;
}
#endif
}
+LIBTEST_API EmptyStruct STDCALL
+mono_test_return_empty_struct (int a)
+{
+ EmptyStruct s;
+
+ g_assert (a == 42);
+
+ return s;
+}
+
typedef struct {
char a[100];
} ByValStrStruct;
return a + b + c;
}
+LIBTEST_API int
+mono_test_stdcall_mismatch_1 (int a, int b, int c)
+{
+ return a + b + c;
+}
+
+LIBTEST_API int STDCALL
+mono_test_stdcall_mismatch_2 (int a, int b, int c)
+{
+ return a + b + c;
+}
+
/*
* PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
*/
{
variant->vt = VT_BSTR|VT_BYREF;
variant->byref = marshal_alloc(sizeof(gpointer));
- *((gunichar**)variant->byref) = marshal_bstr_alloc("PI");
+ *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
return 0;
}
gpointer test_method, ex = NULL;
gpointer (STDCALL *CreateObject)(gpointer*);
-
if (!mono_method_get_unmanaged_thunk)
return 1;
return res;
}
+
+typedef struct {
+ double d;
+} SingleDoubleStruct;
+
+LIBTEST_API SingleDoubleStruct STDCALL
+mono_test_marshal_return_single_double_struct (void)
+{
+ SingleDoubleStruct res;
+
+ res.d = 3.0;
+
+ return res;
+}
+
+
+#ifndef TARGET_X86
+
+LIBTEST_API int STDCALL
+mono_test_has_thiscall (void)
+{
+ return 1;
+}
+
+LIBTEST_API int
+_mono_test_native_thiscall1 (int arg)
+{
+ return arg;
+}
+
+LIBTEST_API int
+_mono_test_native_thiscall2 (int arg, int arg2)
+{
+ return arg + (arg2^1);
+}
+
+LIBTEST_API int
+_mono_test_native_thiscall3 (int arg, int arg2, int arg3)
+{
+ return arg + (arg2^1) + (arg3^2);
+}
+
+#elif defined(__GNUC__)
+
+LIBTEST_API int STDCALL
+mono_test_has_thiscall (void)
+{
+ return 1;
+}
+
+#define def_asm_fn(name) \
+ "\t.align 4\n" \
+ "\t.globl _" #name "\n" \
+ "_" #name ":\n" \
+ "\t.globl __" #name "\n" \
+ "__" #name ":\n"
+
+asm(".text\n"
+
+def_asm_fn(mono_test_native_thiscall1)
+"\tmovl %ecx,%eax\n"
+"\tret\n"
+
+def_asm_fn(mono_test_native_thiscall2)
+"\tmovl %ecx,%eax\n"
+"\tmovl 4(%esp),%ecx\n"
+"\txorl $1,%ecx\n"
+"\taddl %ecx,%eax\n"
+"\tret $4\n"
+
+def_asm_fn(mono_test_native_thiscall3)
+"\tmovl %ecx,%eax\n"
+"\tmovl 4(%esp),%ecx\n"
+"\txorl $1,%ecx\n"
+"\taddl %ecx,%eax\n"
+"\tmovl 8(%esp),%ecx\n"
+"\txorl $2,%ecx\n"
+"\taddl %ecx,%eax\n"
+"\tret $8\n"
+
+);
+
+#else
+
+LIBTEST_API int STDCALL
+mono_test_has_thiscall (void)
+{
+ return 0;
+}
+
+#endif
+