summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2020-04-20 13:47:55 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-04-20 13:48:53 +0200
commit3cc46853a7c04eb78683e9cc2a7356db54ebfb5e (patch)
treeb396006d4eaa7a6553ecb21b9b4d8b920f19bed6
parent1c73b4380fb1611af951ca179527a7763787f915 (diff)
correct Object references for builtins
-rw-r--r--java/generator_jni.c59
-rw-r--r--java/jni-bindings-native-to-jni.h48
2 files changed, 91 insertions, 16 deletions
diff --git a/java/generator_jni.c b/java/generator_jni.c
index 6764377..3e07f97 100644
--- a/java/generator_jni.c
+++ b/java/generator_jni.c
@@ -456,7 +456,7 @@ _get_jni_to_native_converter(const Eolian_Type *type, Eina_Bool param_as_ptr)
456} 456}
457 457
458static const char* 458static const char*
459_get_native_to_jni_converter(const Eolian_Type *type, Eina_Bool this_is_return, Eina_Bool return_is_by_ref) 459_get_native_to_jni_converter(const Eolian_Type *type, Eina_Bool this_is_return, Eina_Bool return_is_by_ref, Eina_Bool force_object_usage)
460{ 460{
461 const Eolian_Typedecl *td = eolian_type_typedecl_get(type); 461 const Eolian_Typedecl *td = eolian_type_typedecl_get(type);
462 Eolian_Type_Type ttype; 462 Eolian_Type_Type ttype;
@@ -501,7 +501,10 @@ _get_native_to_jni_converter(const Eolian_Type *type, Eina_Bool this_is_return,
501#define MAP(t, object_type) \ 501#define MAP(t, object_type) \
502 if (btype == t) \ 502 if (btype == t) \
503 { \ 503 { \
504 return "NATIVE_TO_JNI_"object_type; \ 504 if (force_object_usage) \
505 return "NATIVE_TO_JNI_OBJECT_"object_type; \
506 else \
507 return "NATIVE_TO_JNI_"object_type; \
505 } 508 }
506 MAP(EOLIAN_TYPE_BUILTIN_BYTE, "BYTE") 509 MAP(EOLIAN_TYPE_BUILTIN_BYTE, "BYTE")
507 MAP(EOLIAN_TYPE_BUILTIN_UBYTE, "UBYTE") 510 MAP(EOLIAN_TYPE_BUILTIN_UBYTE, "UBYTE")
@@ -512,8 +515,6 @@ _get_native_to_jni_converter(const Eolian_Type *type, Eina_Bool this_is_return,
512 MAP(EOLIAN_TYPE_BUILTIN_UINT, "UINT") 515 MAP(EOLIAN_TYPE_BUILTIN_UINT, "UINT")
513 MAP(EOLIAN_TYPE_BUILTIN_LONG, "LONG") 516 MAP(EOLIAN_TYPE_BUILTIN_LONG, "LONG")
514 MAP(EOLIAN_TYPE_BUILTIN_ULONG, "ULONG") 517 MAP(EOLIAN_TYPE_BUILTIN_ULONG, "ULONG")
515 MAP(EOLIAN_TYPE_BUILTIN_LLONG, "LLONG")
516 MAP(EOLIAN_TYPE_BUILTIN_ULLONG, "ULLONG")
517 518
518 MAP(EOLIAN_TYPE_BUILTIN_INT8, "INT8") 519 MAP(EOLIAN_TYPE_BUILTIN_INT8, "INT8")
519 MAP(EOLIAN_TYPE_BUILTIN_UINT8, "UINT8") 520 MAP(EOLIAN_TYPE_BUILTIN_UINT8, "UINT8")
@@ -533,7 +534,12 @@ _get_native_to_jni_converter(const Eolian_Type *type, Eina_Bool this_is_return,
533 MAP(EOLIAN_TYPE_BUILTIN_DOUBLE, "DOUBLE") 534 MAP(EOLIAN_TYPE_BUILTIN_DOUBLE, "DOUBLE")
534 MAP(EOLIAN_TYPE_BUILTIN_BOOL, "BOOLEAN") 535 MAP(EOLIAN_TYPE_BUILTIN_BOOL, "BOOLEAN")
535 MAP(EOLIAN_TYPE_BUILTIN_VOID_PTR, "VOID_PTR") 536 MAP(EOLIAN_TYPE_BUILTIN_VOID_PTR, "VOID_PTR")
536 537#undef MAP
538#define MAP(t, object_type) \
539 if (btype == t) \
540 { \
541 return "NATIVE_TO_JNI_"object_type; \
542 }
537 MAP(EOLIAN_TYPE_BUILTIN_UINT64, "UINT64") 543 MAP(EOLIAN_TYPE_BUILTIN_UINT64, "UINT64")
538 MAP(EOLIAN_TYPE_BUILTIN_INT128, "INT128") 544 MAP(EOLIAN_TYPE_BUILTIN_INT128, "INT128")
539 MAP(EOLIAN_TYPE_BUILTIN_UINT128, "UINT128") 545 MAP(EOLIAN_TYPE_BUILTIN_UINT128, "UINT128")
@@ -780,7 +786,9 @@ _generate_java_return_fields(Eina_Strbuf *buf, const Eolian_Function_Type ftype,
780 { 786 {
781 if (values_in_return > 1) 787 if (values_in_return > 1)
782 _generate_jni_types(buf, eolian_property_values_get(func, ftype)); 788 _generate_jni_types(buf, eolian_property_values_get(func, ftype));
783 if (ret_type) 789 if (ret_type && values_in_return > 0)
790 eina_strbuf_append_printf(buf, " jobject ret;\n"); //we need to get the return type as object, and generate the int type to that
791 else if (ret_type)
784 eina_strbuf_append_printf(buf, " %s ret;\n", _get_jni_type(ret_type)); 792 eina_strbuf_append_printf(buf, " %s ret;\n", _get_jni_type(ret_type));
785 if (values_in_return > 1) 793 if (values_in_return > 1)
786 { 794 {
@@ -792,7 +800,12 @@ _generate_java_return_fields(Eina_Strbuf *buf, const Eolian_Function_Type ftype,
792 eina_strbuf_append_printf(buf, " if (!wrapper_klass_constructor) wrapper_klass_constructor = (*jenv)->GetMethodID(jenv, wrapper_klass, \"<init>\", \"(%s)V\");\n", "asdf"); //FIXME 800 eina_strbuf_append_printf(buf, " if (!wrapper_klass_constructor) wrapper_klass_constructor = (*jenv)->GetMethodID(jenv, wrapper_klass, \"<init>\", \"(%s)V\");\n", "asdf"); //FIXME
793 } 801 }
794 else if (values_in_return == 1) 802 else if (values_in_return == 1)
795 eina_strbuf_append_printf(buf, " %s %s;\n", _get_jni_type(first_property_value), first_property_name); 803 {
804 if (ret_type)
805 eina_strbuf_append_printf(buf, " jobject %s;\n", first_property_name);
806 else
807 eina_strbuf_append_printf(buf, " %s %s;\n", _get_jni_type(first_property_value), first_property_name);
808 }
796 if (ret_type && values_in_return != 0) 809 if (ret_type && values_in_return != 0)
797 eina_strbuf_append_printf(buf, " jobject ret_type_wrapper;\n"); 810 eina_strbuf_append_printf(buf, " jobject ret_type_wrapper;\n");
798 } 811 }
@@ -825,7 +838,7 @@ _generate_native_call(Eina_Strbuf *buf, const Eolian_Function_Type ftype, const
825 } 838 }
826 else if (ftype == EOLIAN_PROP_GET) 839 else if (ftype == EOLIAN_PROP_GET)
827 { 840 {
828 if (ret_type && values_in_return != 1) 841 if (ret_type)
829 eina_strbuf_append(buf, " native_ret = "); 842 eina_strbuf_append(buf, " native_ret = ");
830 else if (!ret_type && values_in_return == 1) 843 else if (!ret_type && values_in_return == 1)
831 eina_strbuf_append_printf(buf, " %s native_%s = ", first_property_value_name, first_property_name); 844 eina_strbuf_append_printf(buf, " %s native_%s = ", first_property_value_name, first_property_name);
@@ -870,7 +883,7 @@ _generate_return(Eina_Strbuf *buf, const Eolian_Function_Type ftype, const Eolia
870 else if (ret_type && values_in_return > 0) 883 else if (ret_type && values_in_return > 0)
871 { 884 {
872 //return ret type wrapper which contains ret type *and* the wrapper 885 //return ret type wrapper which contains ret type *and* the wrapper
873 eina_strbuf_append_printf(buf, " ret_type_wrapper = (*jenv)->NewObject(jenv, returnType, returnTypeConstructor, NULL, %s);\n", values_in_return > 1 ? "wrapper" : first_property_name); 886 eina_strbuf_append_printf(buf, " ret_type_wrapper = (*jenv)->NewObject(jenv, returnType, returnTypeConstructor, ret, %s);\n", values_in_return > 1 ? "wrapper" : first_property_name);
874 eina_strbuf_append_printf(buf, " return ret_type_wrapper;\n"); 887 eina_strbuf_append_printf(buf, " return ret_type_wrapper;\n");
875 } 888 }
876 else if (!ret_type && values_in_return > 1) 889 else if (!ret_type && values_in_return > 1)
@@ -913,7 +926,7 @@ _generate_native_to_jni_converts_params(Eina_Strbuf *buf, Eina_Iterator *params)
913 { 926 {
914 const char *name = _sanitize_name(eolian_parameter_name_get(param)); 927 const char *name = _sanitize_name(eolian_parameter_name_get(param));
915 const Eolian_Type *type = eolian_parameter_type_get(param); 928 const Eolian_Type *type = eolian_parameter_type_get(param);
916 eina_strbuf_append_printf(buf, " %s(jenv, native_%s, %s);\n", _get_native_to_jni_converter(type, EINA_FALSE, eolian_parameter_is_by_ref(param)), name, name); 929 eina_strbuf_append_printf(buf, " %s(jenv, native_%s, %s);\n", _get_native_to_jni_converter(type, EINA_FALSE, eolian_parameter_is_by_ref(param), EINA_FALSE), name, name);
917 } 930 }
918 eina_iterator_free(params); 931 eina_iterator_free(params);
919} 932}
@@ -924,19 +937,33 @@ _generate_native_to_jni_converts(Eina_Strbuf *buf, const Eolian_Function_Type ft
924 if (ftype == EOLIAN_METHOD) 937 if (ftype == EOLIAN_METHOD)
925 { 938 {
926 if (ret_type) 939 if (ret_type)
927 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype))); 940 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype), EINA_FALSE));
928 } 941 }
929 else if (ftype == EOLIAN_PROP_SET) 942 else if (ftype == EOLIAN_PROP_SET)
930 { 943 {
931 if (ret_type) 944 if (ret_type)
932 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype))); 945 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype), EINA_FALSE));
933 } 946 }
934 else if (ftype == EOLIAN_PROP_GET) 947 else if (ftype == EOLIAN_PROP_GET)
935 { 948 {
936 if (values_in_return == 1) 949 if (ret_type && values_in_return > 0)
937 eina_strbuf_append_printf(buf, " %s(jenv, native_%s, %s);\n", _get_native_to_jni_converter(first_property_value, EINA_TRUE, first_property_by_ref), first_property_name, first_property_name); 950 {
938 if (ret_type && values_in_return == 0) 951 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype), EINA_TRUE));
939 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype))); 952 }
953 else if (ret_type && values_in_return == 0)
954 {
955 eina_strbuf_append_printf(buf, " %s(jenv, native_ret, ret);\n", _get_native_to_jni_converter(ret_type, EINA_TRUE, eolian_function_return_is_by_ref(func, ftype), EINA_FALSE));
956 }
957
958 if (ret_type && values_in_return == 1)
959 {
960 eina_strbuf_append_printf(buf, " %s(jenv, native_%s, %s);\n", _get_native_to_jni_converter(first_property_value, EINA_TRUE, first_property_by_ref, EINA_TRUE), first_property_name, first_property_name);
961 }
962 else if (!ret_type && values_in_return == 1)
963 {
964 eina_strbuf_append_printf(buf, " %s(jenv, native_%s, %s);\n", _get_native_to_jni_converter(first_property_value, EINA_TRUE, first_property_by_ref, EINA_FALSE), first_property_name, first_property_name);
965 }
966
940 if (values_in_return > 1) 967 if (values_in_return > 1)
941 _generate_native_to_jni_converts_params(buf, eolian_property_values_get(func, ftype)); 968 _generate_native_to_jni_converts_params(buf, eolian_property_values_get(func, ftype));
942 } 969 }
diff --git a/java/jni-bindings-native-to-jni.h b/java/jni-bindings-native-to-jni.h
index 59f3c5a..c6d0fff 100644
--- a/java/jni-bindings-native-to-jni.h
+++ b/java/jni-bindings-native-to-jni.h
@@ -50,6 +50,54 @@
50#define NATIVE_TO_JNI_VOID_PTR(env, from, GOAL) \ 50#define NATIVE_TO_JNI_VOID_PTR(env, from, GOAL) \
51 GOAL = (jlong)from 51 GOAL = (jlong)from
52 52
53#define CREATE_BUILTIN_CLASS_INSTANCE(env, kname, signature, from, GOAL) \
54 do { \
55 jclass klass = (*env)->FindClass(env, kname); \
56 jmethodID value_of = (*env)->GetStaticMethodID(env, klass, "valueOf", "("signature")L"kname";"); \
57 GOAL = (*env)->CallStaticObjectMethod(env, klass, value_of, from); \
58 } while(0);
59
60#define NATIVE_TO_JNI_OBJECT_BYTE(env, from, GOAL) \
61 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Byte", "B", from, GOAL);
62#define NATIVE_TO_JNI_OBJECT_UBYTE(env, from, GOAL) \
63 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Byte", "B", from, GOAL);
64#define NATIVE_TO_JNI_OBJECT_CHAR(env, from, GOAL) \
65 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Character", "C", from, GOAL);
66#define NATIVE_TO_JNI_OBJECT_SHORT(env, from, GOAL) \
67 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Short", "S", from, GOAL);
68#define NATIVE_TO_JNI_OBJECT_USHORT(env, from, GOAL) \
69 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Short", "S", from, GOAL);
70#define NATIVE_TO_JNI_OBJECT_INT(env, from, GOAL) \
71 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
72#define NATIVE_TO_JNI_OBJECT_UINT(env, from, GOAL) \
73 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
74#define NATIVE_TO_JNI_OBJECT_LONG(env, from, GOAL) \
75 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Long", "J", from, GOAL);
76#define NATIVE_TO_JNI_OBJECT_ULONG(env, from, GOAL) \
77 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Long", "J", from, GOAL);
78#define NATIVE_TO_JNI_OBJECT_INT8(env, from, GOAL) \
79 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
80#define NATIVE_TO_JNI_OBJECT_UINT8(env, from, GOAL) \
81 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
82#define NATIVE_TO_JNI_OBJECT_INT16(env, from, GOAL) \
83 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
84#define NATIVE_TO_JNI_OBJECT_UINT16(env, from, GOAL) \
85 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
86#define NATIVE_TO_JNI_OBJECT_INT32(env, from, GOAL) \
87 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
88#define NATIVE_TO_JNI_OBJECT_UINT32(env, from, GOAL) \
89 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
90#define NATIVE_TO_JNI_OBJECT_INT64(env, from, GOAL) \
91 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Integer", "I", from, GOAL);
92#define NATIVE_TO_JNI_OBJECT_FLOAT(env, from, GOAL) \
93 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Float", "F", from, GOAL);
94#define NATIVE_TO_JNI_OBJECT_DOUBLE(env, from, GOAL) \
95 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Double", "D", from, GOAL);
96#define NATIVE_TO_JNI_OBJECT_BOOLEAN(env, from, GOAL) \
97 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Boolean", "Z", from, GOAL);
98#define NATIVE_TO_JNI_OBJECT_VOID_PTR(env, from, GOAL) \
99 CREATE_BUILTIN_CLASS_INSTANCE(env, "java/lang/Long", "J", from, GOAL);
100
53#define NATIVE_TO_JNI_STRING(env, from, GOAL) \ 101#define NATIVE_TO_JNI_STRING(env, from, GOAL) \
54 GOAL = (*env)->NewStringUTF(env, from); 102 GOAL = (*env)->NewStringUTF(env, from);
55 103