Skip to content

Commit

Permalink
Try to Avoid Missing Functions Issue on Windows
Browse files Browse the repository at this point in the history
Also:
- Make @hidden_op_in_java smarter so it doesn't require a argument for
  C++ code (thought it needs on because of IDL).
- Explicitly call Perl on Windows in Java build so it doesn't require the
  file association to be set.
- Add news.
  • Loading branch information
iguessthislldo committed May 10, 2024
1 parent 5e81702 commit 74cf880
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 59 deletions.
2 changes: 1 addition & 1 deletion MPC/config/optional_jni_check.mpb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

feature(jni_check) {

postbuild += $(DDS_ROOT)<%slash%>java<%slash%>build_scripts<%slash%>jni_check.pl <%libout%><%slash%><%sharedname%>
postbuild += perl $(DDS_ROOT)<%slash%>java<%slash%>build_scripts<%slash%>jni_check.pl <%libout%><%slash%><%sharedname%>

}
6 changes: 2 additions & 4 deletions dds/DdsDcpsTopic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ module DDS {
in string type_name);
string get_type_name();
#ifndef OPENDDS_SAFETY_PROFILE
// valuetype isn't supported in Java. This will exclude this operation
// from the generated Java code and return null in get_type method of
// the TAOPeer generated C++ class so it isn't a pure virtual function.
@OpenDDS::internal::hidden_op_in_java("return 0;")
// TODO: valuetype isn't supported in Java
@OpenDDS::internal::hidden_op_in_java(0)
DynamicType get_type();
#endif
};
Expand Down
9 changes: 3 additions & 6 deletions dds/idl/IDLTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ typedef sequence<<%SCOPED%>> <%TYPE%><%SEQ%>;
*/
local interface <%TYPE%>TypeSupport : OpenDDS::DCPS::TypeSupport {
#ifndef OPENDDS_SAFETY_PROFILE
// valuetype isn't supported in Java, so we can't use DynamicData. This
// will exclude this operation from the generated Java code and return null
// in get_type method of the TAOPeer generated C++ class so it isn't a pure
// virtual function.
@OpenDDS::internal::hidden_op_in_java("(void)(src); return 0;")
// TODO: valuetype isn't supported in Java.
@OpenDDS::internal::hidden_op_in_java(0)
<%SCOPED%> create_sample(in ::DDS::DynamicData src);
@OpenDDS::internal::hidden_op_in_java("(void)(src); return 0;")
@OpenDDS::internal::hidden_op_in_java(0)
::DDS::DynamicData create_dynamic_sample(in <%SCOPED%> src);
#endif

Expand Down
2 changes: 1 addition & 1 deletion dds/idl/be_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ BE_post_init(char*[], long)
// This annotation isn't used, but must match the one in idl2jni to avoid
// warnings or errors.
idl_global->eval(
"module OpenDDS {module internal {@annotation hidden_op_in_java {string impl;};};};\n");
"module OpenDDS {module internal {@annotation hidden_op_in_java {int8 dummy;};};};\n");
}
6 changes: 6 additions & 0 deletions docs/news.d/create-sample.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. news-prs: 4373
.. news-start-section: Additions
- Implemented the ``create_dynamic_sample`` and ``create_sample`` methods on ``TypeSupport`` to convert samples to and from ``DynamicData``.
Also documented the existing ``DynamicDataAdaptor`` class for wrapping IDL-generated types in a ``DynamicData``.
.. news-end-section
6 changes: 4 additions & 2 deletions java/idl2jni/codegen/be_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ BE_post_init(char *[], long)
DRV_cpp_putarg("-D__OPENDDS_IDL_HAS_ANNOTATIONS");
DRV_cpp_putarg("-DOPENDDS_HIDE_DYNAMIC_DATA");

// If adding or changing annotations here, they should also be copied into opendds_idl
// If adding or changing annotations here, they should also be copied into
// opendds_idl. dummy is there because IDL annotations can't be used before a
// scoped name starting with :: unless they have annotation parameters.
idl_global->eval(
"module OpenDDS {module internal {@annotation hidden_op_in_java {string impl;};};};\n");
"module OpenDDS {module internal {@annotation hidden_op_in_java {int8 dummy;};};};\n");
}
9 changes: 2 additions & 7 deletions java/idl2jni/codegen/idl_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ bool composite_mapping::gen_union(UTL_ScopedName *name,
return true;
}

bool is_hidden_op_in_java(AST_Operation* op, std::string* impl)
bool is_hidden_op_in_java(AST_Operation* op)
{
AST_Annotation_Appl* a = op->annotations().find("::OpenDDS::internal::@hidden_op_in_java");
if (a && impl) {
*impl = dynamic_cast<AST_Annotation_Member*>((*a)["impl"])->
value()->ev()->u.strval->get_string();
}
return a;
return op->annotations().find("::OpenDDS::internal::@hidden_op_in_java");
}
2 changes: 1 addition & 1 deletion java/idl2jni/codegen/idl_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ class idl_mapping_jni : public idl_mapping {
bool sequence, const std::string &length, bool elementIsObjref = false);
};

bool is_hidden_op_in_java(AST_Operation* op, std::string* impl = 0);
bool is_hidden_op_in_java(AST_Operation* op);

#endif
89 changes: 52 additions & 37 deletions java/idl2jni/codegen/im_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,12 +1300,12 @@ void write_native_operation(UTL_ScopedName *name, const char *javaStub,
{
const char *opname = op->local_name()->get_string();
string ret = "void",
cxx = idl_mapping_jni::scoped(name),
fnName = jni_function_name(javaStub, opname),
retval, retconv, ret_exception;
//for the JavaPeer (local interfaces only)
cxx = idl_mapping_jni::scoped(name),
fnName = jni_function_name(javaStub, opname),
retval, retconv, ret_exception;
// for the JavaPeer (local interfaces only)
string ret_jsig = "V", jniFn = "Void", tao_ret = "void",
tao_retval, tao_retconv, array_cast;
tao_retval, tao_retconv, array_cast;

if (!op->void_return_type()) {
ret = idl_mapping_jni::type(op->return_type());
Expand Down Expand Up @@ -1356,6 +1356,8 @@ void write_native_operation(UTL_ScopedName *name, const char *javaStub,
}
}

const bool hidden = is_hidden_op_in_java(op);

//for the JavaPeer (local interfaces only)
string tao_args, java_args, args_jsig, tao_argconv_in, tao_argconv_out;

Expand All @@ -1367,17 +1369,23 @@ void write_native_operation(UTL_ScopedName *name, const char *javaStub,
AST_Decl *item = it.item();

if (item->node_type() == AST_Decl::NT_argument) {
AST_Argument *arg = dynamic_cast<AST_Argument*>(item);
const char *argname = arg->local_name()->get_string();
bool in = arg->direction() == AST_Argument::dir_IN;
args += ", " + (in ? idl_mapping_jni::type(arg->field_type())
: "jobject")
+ ' ' + argname;
AST_Argument* const arg = dynamic_cast<AST_Argument*>(item);
const char* const argname = arg->local_name()->get_string();
const bool in = arg->direction() == AST_Argument::dir_IN;

args += ", " + (in ? idl_mapping_jni::type(arg->field_type()) : "jobject");
if (!hidden) {
args += std::string(" ") + argname;
}

if (tao_args != "") tao_args += ", ";
if (!tao_args.empty()) {
tao_args.append(", ");
}
tao_args += idl_mapping_jni::taoParam(arg->field_type(), arg->direction());
if (!hidden) {
tao_args += std::string(" ") + argname;
}

tao_args += idl_mapping_jni::taoParam(arg->field_type(),
arg->direction()) + ' ' + argname;
args_jsig += in
? idl_mapping_jni::jvmSignature(arg->field_type())
: "L" + idl_mapping::scoped_helper(arg->field_type()->name(),
Expand Down Expand Up @@ -1409,9 +1417,8 @@ void write_native_operation(UTL_ScopedName *name, const char *javaStub,
idl_mapping_jni::scoped_helper(name, "_") << "JavaPeer::" << opname_cxx <<
" (" << tao_args << ")\n"
"{\n";
std::string hidden_impl;
if (is_hidden_op_in_java(op, &hidden_impl)) {
be_global->stub_impl_ << " " << hidden_impl << "\n";
if (hidden) {
be_global->stub_impl_ << ret_exception;
} else {
be_global->stub_impl_ <<
" JNIThreadAttacher _jta (jvm_, cl_);\n"
Expand All @@ -1433,26 +1440,34 @@ void write_native_operation(UTL_ScopedName *name, const char *javaStub,
}

be_global->stub_impl_ <<
"extern \"C\" JNIEXPORT " << ret << " JNICALL\n" <<
fnName << " (JNIEnv *_jni, jobject _jthis" << args << ")\n"
"{\n"
" CORBA::Object_ptr _this_obj = recoverTaoObject (_jni, _jthis);\n"
" try\n"
" {\n"
" " << cxx << "_var _this = " << cxx << "::_narrow (_this_obj);\n"
<< argconv_in <<
" " << retval << "_this->" << (isCxxKeyword(opname) ? "_cxx_" : "")
<< opname << " (" << cxx_args << ");\n"
<< argconv_out
<< retconv <<
//FUTURE: catch declared user exceptions
" }\n"
" catch (const CORBA::SystemException &_se)\n"
" {\n"
" throw_java_exception (_jni, _se);\n"
" }\n"
<< ret_exception <<
"}\n\n";
"extern \"C\" JNIEXPORT " << ret << " JNICALL\n" <<
fnName << "(JNIEnv* _jni, jobject _jthis" << args << ")\n"
"{\n";
if (hidden) {
be_global->stub_impl_ <<
" (void)_jni;\n"
" (void)_jthis;\n";
} else {
be_global->stub_impl_ <<
" CORBA::Object_ptr _this_obj = recoverTaoObject (_jni, _jthis);\n"
" try\n"
" {\n"
" " << cxx << "_var _this = " << cxx << "::_narrow (_this_obj);\n"
<< argconv_in <<
" " << retval << "_this->" << (isCxxKeyword(opname) ? "_cxx_" : "")
<< opname << " (" << cxx_args << ");\n"
<< argconv_out
<< retconv <<
// FUTURE: catch declared user exceptions
" }\n"
" catch (const CORBA::SystemException &_se)\n"
" {\n"
" throw_java_exception (_jni, _se);\n"
" }\n";
}
be_global->stub_impl_
<< ret_exception
<< "}\n\n";
}

void recursive_bases(AST_Interface *interf, set<string> &bases,
Expand Down

0 comments on commit 74cf880

Please sign in to comment.