diff options
author | Michal Cmarada <mcmarada@cisco.com> | 2019-05-29 11:08:49 +0200 |
---|---|---|
committer | Michal Cmarada <mcmarada@cisco.com> | 2019-05-29 11:08:49 +0200 |
commit | baa04244252b25cde53699116f74947b1389081c (patch) | |
tree | af3305041d95bf98b4520bd6b2da12dc3ea043f7 /java | |
parent | 5e0ae3d2f7e2723042c462c9851c0162df683556 (diff) |
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 <mcmarada@cisco.com>
Diffstat (limited to 'java')
-rwxr-xr-x | java/jvpp/gen/jvppgen/jni_common_gen.py | 42 |
1 files changed, 32 insertions, 10 deletions
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, "<init>", "()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 |