aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/efl_mono/libefl_mono_native_test.c
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-03-15 20:32:39 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2018-03-16 11:12:49 -0300
commit2705ea853108a64edc9264c8e5d4c79e55aea001 (patch)
tree7cbb95f4667ce4fa3d6c44a7b8e0e196a1ca757c /src/tests/efl_mono/libefl_mono_native_test.c
parentcsharp: Change policy on ptr(struct) owned calls (diff)
downloadefl-2705ea853108a64edc9264c8e5d4c79e55aea001.tar.gz
csharp: Fix support for ptr(structs)
In general, ptr(struct) parameters behavior depends whether the parameter has the @owned modifier or not. If there is no @owned parameter (meaning no transfer of ownership happens) and it is a "complex" struct, with reference type fields (like strings), the struct is converted to the respective <Struct>Internal struct and passed with "ref" to the DllImport'd function. For @in parameters, after the function it returns, this intermediate struct is converted to the public struct type and assigned to the original parameter, updating it to the external world. When we have ownership transfers, the structure is copied to unmanaged memory and given to the callee. We can't send managed memory directly as the callee may try to free it. On the managed side, the original struct is left to be garbage collected normally.
Diffstat (limited to 'src/tests/efl_mono/libefl_mono_native_test.c')
-rw-r--r--src/tests/efl_mono/libefl_mono_native_test.c124
1 files changed, 104 insertions, 20 deletions
diff --git a/src/tests/efl_mono/libefl_mono_native_test.c b/src/tests/efl_mono/libefl_mono_native_test.c
index f96666380b..04fd12053f 100644
--- a/src/tests/efl_mono/libefl_mono_native_test.c
+++ b/src/tests/efl_mono/libefl_mono_native_test.c
@@ -44,7 +44,8 @@ typedef struct Test_Testing_Data
Eina_Free_Cb free_cb;
Eina_Error error_code;
Eina_Value *stored_value;
-
+ Test_StructSimple stored_struct;
+ int stored_int;
} Test_Testing_Data;
typedef struct Test_Numberwrapper_Data
@@ -100,6 +101,17 @@ Efl_Object *_test_testing_return_object(Eo *obj, EINA_UNUSED Test_Testing_Data *
return obj;
}
+void _test_testing_int_out(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, int x, int *y)
+{
+ *y = -x;
+}
+
+void _test_testing_int_ptr_out(EINA_UNUSED Eo *obj, Test_Testing_Data *pd, int x, int **y)
+{
+ pd->stored_int = x * 2;
+ *y = &pd->stored_int;
+}
+
const char *_test_testing_in_string(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, const char *str)
{
const char *ret = malloc(sizeof(char)*(strlen(str) + 1));
@@ -3342,20 +3354,34 @@ Eina_Bool _test_testing_struct_simple_in(EINA_UNUSED Eo *obj, EINA_UNUSED Test_T
return check_and_modify_struct_simple(&simple);
}
+static void _reverse_string(char *str)
+{
+ int len = strlen(str);
+ if (len > 0) {
+ for (int i=0, k=len-1; i < len/2; i++, k--) {
+ char tmp = str[k];
+ str[k] = str[i];
+ str[i] = tmp;
+ }
+ }
+}
+
EOLIAN
Eina_Bool _test_testing_struct_simple_ptr_in(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
{
- (void) simple;
- EINA_LOG_ERR("Not implemented!");
- return EINA_FALSE;
+ simple->fint = -simple->fint;
+ _reverse_string(simple->fstring);
+ return EINA_TRUE;
}
EOLIAN
-Eina_Bool _test_testing_struct_simple_ptr_in_own(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
+Test_StructSimple _test_testing_struct_simple_ptr_in_own(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
{
- (void) simple;
- EINA_LOG_ERR("Not implemented!");
- return EINA_FALSE;
+ Test_StructSimple ret = *simple;
+ free(simple);
+ ret.fint = -ret.fint;
+ _reverse_string(ret.fstring);
+ return ret;
}
EOLIAN
@@ -3373,19 +3399,20 @@ Eina_Bool _test_testing_struct_simple_out(EINA_UNUSED Eo *obj, EINA_UNUSED Test_
}
EOLIAN
-Eina_Bool _test_testing_struct_simple_ptr_out(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple **simple)
+Test_StructSimple _test_testing_struct_simple_ptr_out(EINA_UNUSED Eo *obj, Test_Testing_Data *pd, Test_StructSimple **simple)
{
- (void) simple;
- EINA_LOG_ERR("Not implemented!");
- return EINA_FALSE;
+ struct_simple_with_values(&pd->stored_struct);
+ *simple = &pd->stored_struct;
+ return **simple;
}
EOLIAN
-Eina_Bool _test_testing_struct_simple_ptr_out_own(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple **simple)
+Test_StructSimple _test_testing_struct_simple_ptr_out_own(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple **simple)
{
- (void) simple;
- EINA_LOG_ERR("Not implemented!");
- return EINA_FALSE;
+ *simple = malloc(sizeof(Test_StructSimple));
+ struct_simple_with_values(*simple);
+ (*simple)->fstring = "Ptr Out Own";
+ return **simple;
}
EOLIAN
@@ -3399,15 +3426,72 @@ Test_StructSimple _test_testing_struct_simple_return(EINA_UNUSED Eo *obj, EINA_U
EOLIAN
Test_StructSimple *_test_testing_struct_simple_ptr_return(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd)
{
- EINA_LOG_ERR("Not implemented!");
- return NULL;
+ struct_simple_with_values(&pd->stored_struct);
+ pd->stored_struct.fstring = "Ret Ptr";
+ return &pd->stored_struct;
}
EOLIAN
Test_StructSimple *_test_testing_struct_simple_ptr_return_own(EINA_UNUSED Eo *obj, EINA_UNUSED Test_Testing_Data *pd)
{
- EINA_LOG_ERR("Not implemented!");
- return NULL;
+ Test_StructSimple *ret = malloc(sizeof(Test_StructSimple));
+ struct_simple_with_values(ret);
+ ret->fstring = "Ret Ptr Own";
+ return ret;
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_in(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple simple)
+{
+ test_testing_struct_simple_in(obj, simple);
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_ptr_in(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
+{
+ test_testing_struct_simple_ptr_in(obj, simple);
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_ptr_in_own(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
+{
+ test_testing_struct_simple_ptr_in_own(obj, simple);
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_out(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple *simple)
+{
+ test_testing_struct_simple_out(obj, simple);
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_ptr_out(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple **simple)
+{
+ test_testing_struct_simple_ptr_out(obj, simple);
+}
+
+EOLIAN
+void _test_testing_call_struct_simple_ptr_out_own(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Test_StructSimple **simple)
+{
+ test_testing_struct_simple_ptr_out_own(obj, simple);
+}
+
+EOLIAN
+Test_StructSimple _test_testing_call_struct_simple_return(Eo *obj, EINA_UNUSED Test_Testing_Data *pd)
+{
+ return test_testing_struct_simple_return(obj);
+}
+
+EOLIAN
+Test_StructSimple *_test_testing_call_struct_simple_ptr_return(Eo *obj, EINA_UNUSED Test_Testing_Data *pd)
+{
+ return test_testing_struct_simple_ptr_return(obj);
+}
+
+EOLIAN
+Test_StructSimple *_test_testing_call_struct_simple_ptr_return_own(Eo *obj, EINA_UNUSED Test_Testing_Data *pd)
+{
+ return test_testing_struct_simple_ptr_return_own(obj);
}
// with complex types