summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-08-05 19:06:11 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-08-05 19:15:35 -0300
commitc1b76d3008ecb7c558ad4ad8de02f1e03ffddf68 (patch)
tree631410fd51486827d2fb36954fd03f34ce4e687c
parente6a52ef371430c69da7ce3e7b22f1455a64f1637 (diff)
csharp: fix ownership of value types in arrays and lists
Summary: `eolian_mono` now considers the implicit ownership of value types in arrays and lists when generating ownership flags. Also, update manual bindings for arrays and lists to no longer free elements in the `Dispose` method when the container has ownership of the elements but C# itself does not have ownership of the container; the elements will be freed by whoever owns the container. Modifying and removing elements will still free them though. Re-enabled unit tests that required ownership of value type elements. Reviewers: felipealmeida, q66, vitor.sousa Reviewed By: felipealmeida Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9457
-rw-r--r--src/bin/eolian_mono/eolian/mono/parameter.hh15
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs2
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp2
-rw-r--r--src/tests/efl_mono/Eina.cs12
-rw-r--r--src/tests/efl_mono/dummy_test_object.eo12
6 files changed, 13 insertions, 32 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh
index e1e8661bcb..954ac25c70 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -612,7 +612,7 @@ struct native_convert_in_variable_generator
612 return as_generator( 612 return as_generator(
613 "var " << string << " = new " << type << "(" << escape_keyword(param.param_name) 613 "var " << string << " = new " << type << "(" << escape_keyword(param.param_name)
614 << ", " << (param.type.has_own ? "true" : "false") 614 << ", " << (param.type.has_own ? "true" : "false")
615 << ", " << (complex->subtypes.front().has_own ? "true" : "false") 615 << ", " << (complex->subtypes.front().is_value_type || complex->subtypes.front().has_own ? "true" : "false")
616 << ");\n" 616 << ");\n"
617 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.type), context); 617 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.type), context);
618 } 618 }
@@ -724,7 +724,8 @@ struct convert_in_variable_generator
724 ) 724 )
725 return true; 725 return true;
726 726
727 if (complex->subtypes.front().has_own && !as_generator( 727 if (!complex->subtypes.front().is_value_type && complex->subtypes.front().has_own
728 && !as_generator(
728 escape_keyword(param.param_name) << ".OwnContent = false;\n" 729 escape_keyword(param.param_name) << ".OwnContent = false;\n"
729 ).generate(sink, attributes::unused, context)) 730 ).generate(sink, attributes::unused, context))
730 return false; 731 return false;
@@ -963,7 +964,7 @@ struct convert_out_assign_generator
963 return as_generator( 964 return as_generator(
964 string << " = new " << type << "(" << string 965 string << " = new " << type << "(" << string
965 << ", " << (param.type.has_own ? "true" : "false") 966 << ", " << (param.type.has_own ? "true" : "false")
966 << ", " << (complex->subtypes.front().has_own ? "true" : "false") 967 << ", " << (complex->subtypes.front().is_value_type || complex->subtypes.front().has_own ? "true" : "false")
967 << ");\n" 968 << ");\n"
968 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type, out_variable_name(param.param_name)), context); 969 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type, out_variable_name(param.param_name)), context);
969 } 970 }
@@ -1092,7 +1093,7 @@ struct convert_return_generator
1092 if (!complex) 1093 if (!complex)
1093 return false; 1094 return false;
1094 if (!as_generator("return new " << type << "(_ret_var, " << std::string{ret_type.has_own ? "true" : "false"} 1095 if (!as_generator("return new " << type << "(_ret_var, " << std::string{ret_type.has_own ? "true" : "false"}
1095 << ", " << (complex->subtypes.front().has_own ? "true" : "false") 1096 << ", " << (complex->subtypes.front().is_value_type || complex->subtypes.front().has_own ? "true" : "false")
1096 << ");\n") 1097 << ");\n")
1097 .generate(sink, ret_type, context)) 1098 .generate(sink, ret_type, context))
1098 return false; 1099 return false;
@@ -1244,7 +1245,8 @@ struct native_convert_out_assign_generator
1244 ) 1245 )
1245 return true; 1246 return true;
1246 1247
1247 if (complex->subtypes.front().has_own && !as_generator( 1248 if (!complex->subtypes.front().is_value_type && complex->subtypes.front().has_own
1249 && !as_generator(
1248 string << ".OwnContent = false;\n" 1250 string << ".OwnContent = false;\n"
1249 ).generate(sink, outvar, context)) 1251 ).generate(sink, outvar, context))
1250 return false; 1252 return false;
@@ -1370,7 +1372,8 @@ struct native_convert_return_generator
1370 && ret_type.c_type != "Eina_Accessor *" && ret_type.c_type != "const Eina_Accessor *" 1372 && ret_type.c_type != "Eina_Accessor *" && ret_type.c_type != "const Eina_Accessor *"
1371 ) 1373 )
1372 { 1374 {
1373 if (complex->subtypes.front().has_own && !as_generator("_ret_var.OwnContent = false; ") 1375 if (!complex->subtypes.front().is_value_type && complex->subtypes.front().has_own
1376 && !as_generator("_ret_var.OwnContent = false; ")
1374 .generate(sink, attributes::unused, context)) 1377 .generate(sink, attributes::unused, context))
1375 return false; 1378 return false;
1376 } 1379 }
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index e75ca6ae7a..8c09557098 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -138,7 +138,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
138 return; 138 return;
139 } 139 }
140 140
141 if (OwnContent) 141 if (Own && OwnContent)
142 { 142 {
143 int len = (int)eina_array_count_custom_export_mono(h); 143 int len = (int)eina_array_count_custom_export_mono(h);
144 for (int i = 0; i < len; ++i) 144 for (int i = 0; i < len; ++i)
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index 4c25c25e62..9fe5e90d77 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -182,7 +182,7 @@ public class List<T> : IEnumerable<T>, IDisposable
182 return; 182 return;
183 } 183 }
184 184
185 if (OwnContent) 185 if (Own && OwnContent)
186 { 186 {
187 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) 187 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
188 { 188 {
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index 9157cfd5b1..4d6d4ea79f 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -376,6 +376,7 @@ struct type_def
376 bool is_ptr; 376 bool is_ptr;
377 bool is_beta; 377 bool is_beta;
378 std::string doc_summary; 378 std::string doc_summary;
379 bool is_value_type;
379 380
380 type_def() = default; 381 type_def() = default;
381 type_def(variant_type original_type, std::string c_type, bool has_own, bool is_ptr, bool is_beta, std::string doc_summary) 382 type_def(variant_type original_type, std::string c_type, bool has_own, bool is_ptr, bool is_beta, std::string doc_summary)
@@ -428,6 +429,7 @@ type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_n
428inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype) 429inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype)
429{ 430{
430 c_type = ::eolian_type_c_type_get(eolian_type, ctype); 431 c_type = ::eolian_type_c_type_get(eolian_type, ctype);
432 is_value_type = ('*' != c_type.back());
431 // ::eina_stringshare_del(stringshare); // this crashes 433 // ::eina_stringshare_del(stringshare); // this crashes
432 Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); 434 Eolian_Type const* stp = eolian_type_base_type_get(eolian_type);
433 has_own = !!::eolian_type_is_owned(eolian_type); 435 has_own = !!::eolian_type_is_owned(eolian_type);
diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs
index 07dfd1bed2..0f6d9774bc 100644
--- a/src/tests/efl_mono/Eina.cs
+++ b/src/tests/efl_mono/Eina.cs
@@ -838,7 +838,6 @@ class TestEinaArray
838 Test.Assert(arr.Handle == IntPtr.Zero); 838 Test.Assert(arr.Handle == IntPtr.Zero);
839 } 839 }
840 840
841 /*
842 public static void test_eina_array_int_in_own() 841 public static void test_eina_array_int_in_own()
843 { 842 {
844 var t = new Dummy.TestObject(); 843 var t = new Dummy.TestObject();
@@ -851,7 +850,6 @@ class TestEinaArray
851 Test.Assert(arr.Handle == IntPtr.Zero); 850 Test.Assert(arr.Handle == IntPtr.Zero);
852 Test.Assert(t.CheckEinaArrayIntInOwn()); 851 Test.Assert(t.CheckEinaArrayIntInOwn());
853 } 852 }
854 */
855 853
856 public static void test_eina_array_int_out() 854 public static void test_eina_array_int_out()
857 { 855 {
@@ -866,7 +864,6 @@ class TestEinaArray
866 Test.Assert(t.CheckEinaArrayIntOut()); 864 Test.Assert(t.CheckEinaArrayIntOut());
867 } 865 }
868 866
869 /*
870 public static void test_eina_array_int_out_own() 867 public static void test_eina_array_int_out_own()
871 { 868 {
872 var t = new Dummy.TestObject(); 869 var t = new Dummy.TestObject();
@@ -878,7 +875,6 @@ class TestEinaArray
878 arr.Dispose(); 875 arr.Dispose();
879 Test.Assert(arr.Handle == IntPtr.Zero); 876 Test.Assert(arr.Handle == IntPtr.Zero);
880 } 877 }
881 */
882 878
883 public static void test_eina_array_int_return() 879 public static void test_eina_array_int_return()
884 { 880 {
@@ -892,7 +888,6 @@ class TestEinaArray
892 Test.Assert(t.CheckEinaArrayIntReturn()); 888 Test.Assert(t.CheckEinaArrayIntReturn());
893 } 889 }
894 890
895 /*
896 public static void test_eina_array_int_return_own() 891 public static void test_eina_array_int_return_own()
897 { 892 {
898 var t = new Dummy.TestObject(); 893 var t = new Dummy.TestObject();
@@ -903,7 +898,6 @@ class TestEinaArray
903 arr.Dispose(); 898 arr.Dispose();
904 Test.Assert(arr.Handle == IntPtr.Zero); 899 Test.Assert(arr.Handle == IntPtr.Zero);
905 } 900 }
906 */
907 901
908 // String // 902 // String //
909 public static void test_eina_array_str_in() 903 public static void test_eina_array_str_in()
@@ -1902,7 +1896,6 @@ class TestEinaList
1902 Test.Assert(lst.Handle == IntPtr.Zero); 1896 Test.Assert(lst.Handle == IntPtr.Zero);
1903 } 1897 }
1904 1898
1905 /*
1906 public static void test_eina_list_int_in_own() 1899 public static void test_eina_list_int_in_own()
1907 { 1900 {
1908 var t = new Dummy.TestObject(); 1901 var t = new Dummy.TestObject();
@@ -1914,7 +1907,6 @@ class TestEinaList
1914 Test.Assert(lst.Handle == IntPtr.Zero); 1907 Test.Assert(lst.Handle == IntPtr.Zero);
1915 Test.Assert(t.CheckEinaListIntInOwn()); 1908 Test.Assert(t.CheckEinaListIntInOwn());
1916 } 1909 }
1917 */
1918 1910
1919 public static void test_eina_list_int_out() 1911 public static void test_eina_list_int_out()
1920 { 1912 {
@@ -1928,7 +1920,6 @@ class TestEinaList
1928 Test.Assert(t.CheckEinaListIntOut()); 1920 Test.Assert(t.CheckEinaListIntOut());
1929 } 1921 }
1930 1922
1931 /*
1932 public static void test_eina_list_int_out_own() 1923 public static void test_eina_list_int_out_own()
1933 { 1924 {
1934 var t = new Dummy.TestObject(); 1925 var t = new Dummy.TestObject();
@@ -1940,7 +1931,6 @@ class TestEinaList
1940 lst.Dispose(); 1931 lst.Dispose();
1941 Test.Assert(lst.Handle == IntPtr.Zero); 1932 Test.Assert(lst.Handle == IntPtr.Zero);
1942 } 1933 }
1943 */
1944 1934
1945 public static void test_eina_list_int_return() 1935 public static void test_eina_list_int_return()
1946 { 1936 {
@@ -1953,7 +1943,6 @@ class TestEinaList
1953 Test.Assert(t.CheckEinaListIntReturn()); 1943 Test.Assert(t.CheckEinaListIntReturn());
1954 } 1944 }
1955 1945
1956 /*
1957 public static void test_eina_list_int_return_own() 1946 public static void test_eina_list_int_return_own()
1958 { 1947 {
1959 var t = new Dummy.TestObject(); 1948 var t = new Dummy.TestObject();
@@ -1964,7 +1953,6 @@ class TestEinaList
1964 lst.Dispose(); 1953 lst.Dispose();
1965 Test.Assert(lst.Handle == IntPtr.Zero); 1954 Test.Assert(lst.Handle == IntPtr.Zero);
1966 } 1955 }
1967 */
1968 1956
1969 // String // 1957 // String //
1970 public static void test_eina_list_str_in() 1958 public static void test_eina_list_str_in()
diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo
index 47ec4c6b27..e25f7b29bb 100644
--- a/src/tests/efl_mono/dummy_test_object.eo
+++ b/src/tests/efl_mono/dummy_test_object.eo
@@ -385,7 +385,6 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
385 return: bool; 385 return: bool;
386 } 386 }
387 387
388 /*
389 eina_array_int_in_own { 388 eina_array_int_in_own {
390 params { 389 params {
391 @in arr: array<int> @owned; // <int @owned> 390 @in arr: array<int> @owned; // <int @owned>
@@ -395,7 +394,6 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
395 check_eina_array_int_in_own { 394 check_eina_array_int_in_own {
396 return: bool; 395 return: bool;
397 } 396 }
398 */
399 397
400 eina_array_int_out { 398 eina_array_int_out {
401 params { 399 params {
@@ -407,14 +405,12 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
407 return: bool; 405 return: bool;
408 } 406 }
409 407
410 /*
411 eina_array_int_out_own { 408 eina_array_int_out_own {
412 params { 409 params {
413 @out arr: array<int> @owned; // <int @owned> 410 @out arr: array<int> @owned; // <int @owned>
414 } 411 }
415 return: bool; 412 return: bool;
416 } 413 }
417 */
418 414
419 eina_array_int_return { 415 eina_array_int_return {
420 return: array<int>; 416 return: array<int>;
@@ -423,11 +419,9 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
423 return: bool; 419 return: bool;
424 } 420 }
425 421
426 /*
427 eina_array_int_return_own { 422 eina_array_int_return_own {
428 return: array<int> @owned; // <int @owned> 423 return: array<int> @owned; // <int @owned>
429 } 424 }
430 */
431 425
432 /* String */ 426 /* String */
433 eina_array_str_in { 427 eina_array_str_in {
@@ -584,7 +578,6 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
584 return: bool; 578 return: bool;
585 } 579 }
586 580
587 /*
588 eina_list_int_in_own { 581 eina_list_int_in_own {
589 params { 582 params {
590 @in lst: list<int> @owned; // <int @owned> 583 @in lst: list<int> @owned; // <int @owned>
@@ -594,7 +587,6 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
594 check_eina_list_int_in_own { 587 check_eina_list_int_in_own {
595 return: bool; 588 return: bool;
596 } 589 }
597 */
598 590
599 eina_list_int_out { 591 eina_list_int_out {
600 params { 592 params {
@@ -606,14 +598,12 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
606 return: bool; 598 return: bool;
607 } 599 }
608 600
609 /*
610 eina_list_int_out_own { 601 eina_list_int_out_own {
611 params { 602 params {
612 @out lst: list<int> @owned; // <int @owned> 603 @out lst: list<int> @owned; // <int @owned>
613 } 604 }
614 return: bool; 605 return: bool;
615 } 606 }
616 */
617 607
618 eina_list_int_return { 608 eina_list_int_return {
619 return: list<int>; 609 return: list<int>;
@@ -622,11 +612,9 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
622 return: bool; 612 return: bool;
623 } 613 }
624 614
625 /*
626 eina_list_int_return_own { 615 eina_list_int_return_own {
627 return: list<int> @owned; // <int @owned> 616 return: list<int> @owned; // <int @owned>
628 } 617 }
629 */
630 618
631 /* String */ 619 /* String */
632 eina_list_str_in { 620 eina_list_str_in {