From baa04244252b25cde53699116f74947b1389081c Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Wed, 29 May 2019 11:08:49 +0200 Subject: fix union and object type collision if Union is enclosed in an object with the same name two variables with same name are generated in translate function. This fixes this issue by adding "Union" suffix to union class variable Change-Id: I4158083c5f0efc409a9d4bedeca2ebedb517692e Signed-off-by: Michal Cmarada --- java/jvpp/gen/jvppgen/jni_common_gen.py | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'java') diff --git a/java/jvpp/gen/jvppgen/jni_common_gen.py b/java/jvpp/gen/jvppgen/jni_common_gen.py index 120241a..929a197 100755 --- a/java/jvpp/gen/jvppgen/jni_common_gen.py +++ b/java/jvpp/gen/jvppgen/jni_common_gen.py @@ -380,16 +380,28 @@ def _generate_c2j_scalar_swap(msg_java_name, field, object_ref_name, struct_ref_ def _generate_c2j_object_swap(msg_java_name, field, object_ref_name, struct_ref_name): field_type = field.type - return _C2J_OBJECT_SWAP_TEMPLATE.substitute( - java_name=field.java_name, - class_ref_name=msg_java_name, - jni_signature=field_type.jni_signature, - jni_name=field_type.jni_name, - jni_accessor=field_type.jni_accessor, - object_ref_name=object_ref_name, - struct_ref_name=struct_ref_name, - net_to_host_function=field_type.net_to_host_function, - c_name=field.name) + if "Union" in field_type.jni_name: + return _C2J_UNION_SWAP_TEMPLATE.substitute( + java_name=field.java_name, + class_ref_name=msg_java_name, + jni_signature=field_type.jni_signature, + jni_name=field_type.jni_name, + jni_accessor=field_type.jni_accessor, + object_ref_name=object_ref_name, + struct_ref_name=struct_ref_name, + net_to_host_function=field_type.net_to_host_function, + c_name=field.name) + else: + return _C2J_OBJECT_SWAP_TEMPLATE.substitute( + java_name=field.java_name, + class_ref_name=msg_java_name, + jni_signature=field_type.jni_signature, + jni_name=field_type.jni_name, + jni_accessor=field_type.jni_accessor, + object_ref_name=object_ref_name, + struct_ref_name=struct_ref_name, + net_to_host_function=field_type.net_to_host_function, + c_name=field.name) _C2J_OBJECT_SWAP_TEMPLATE = Template(""" jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, ${class_ref_name}Class, "${java_name}", "${jni_signature}"); @@ -401,6 +413,16 @@ _C2J_OBJECT_SWAP_TEMPLATE = Template(""" (*env)->DeleteLocalRef(env, ${java_name}); """) +_C2J_UNION_SWAP_TEMPLATE = Template(""" + jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, ${class_ref_name}Class, "${java_name}", "${jni_signature}"); + jclass ${java_name}UnionClass = (*env)->FindClass(env, "${jni_name}"); + jmethodID ${java_name}Constructor = (*env)->GetMethodID(env, ${java_name}UnionClass, "", "()V"); + jobject ${java_name} = (*env)->NewObject(env, ${java_name}UnionClass, ${java_name}Constructor); + ${net_to_host_function}(env, &(${struct_ref_name}->${c_name}), ${java_name}); + (*env)->Set${jni_accessor}Field(env, ${object_ref_name}, ${java_name}FieldId, ${java_name}); + (*env)->DeleteLocalRef(env, ${java_name}); +""") + def _generate_c2j_enum_swap(msg_java_name, field, object_ref_name, struct_ref_name): field_type = field.type -- cgit 1.2.3-korg