Skip to content

Commit

Permalink
Minor Adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
xevor11 committed Sep 15, 2024
1 parent 3cfe83d commit bb76d66
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

2024-07-12 Vedant Tewari <[email protected]>

* ax_prog_java.m4: Added macro for jni check
* ax_jni_include_dir.m4: Added macro for jni check
* configure.ac: added support for Java interoperability through JNI
* m4/ax_prog_java.m4, m4/ax_jni_include_dir.m4: Added macros for JNI checks
* configure.ac: Added support for Java interoperability through JNI, extending GnuCOBOL ability to interact with external Java libraries
* NEWS, DEPENDENCIES: Updated to reflect support for JNI

2023-02-25 Ron Norman <[email protected]>

Expand Down
26 changes: 25 additions & 1 deletion cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static struct literal_list *literal_cache = NULL;
static struct field_list *field_cache = NULL;
static struct field_list *local_field_cache = NULL;
static struct call_list *call_cache = NULL;
static struct call_list *call_java_cache = NULL;
static struct call_list *call_java_cache = NULL;
static struct call_list *func_call_cache = NULL;
static struct static_call_list *static_call_cache = NULL;
static struct base_list *base_cache = NULL;
Expand Down Expand Up @@ -7090,6 +7090,28 @@ output_field_constant (cb_tree x, int n, const char *flagname)
output_newline ();
}

static void
output_exception_handling(struct cb_call *p)
{
if (p->stmt1) {
output_line("cob_glob_ptr->cob_stmt_exception = 1;");
output_line("COB_RESET_EXCEPTION(0);");
} else {
output_line("cob_glob_ptr->cob_stmt_exception = 0;");
}

output_line("if ((cob_glob_ptr->cob_exception_code & 0xff00) != 0) {");
output_block_open();

if (p->stmt1) {
output_stmt(p->stmt1);
} else if (p->stmt2) {
output_stmt(p->stmt2);
}
output_block_close();
output_line("COB_RESET_EXCEPTION(0);");
}

static void
output_java_call (struct cb_call *p)
{
Expand Down Expand Up @@ -7127,6 +7149,7 @@ output_java_call (struct cb_call *p)
output_line("cob_call_java(call_java_%s);\n", mangled);
output_newline();
output_block_close();
output_exception_handling(p);
}

static void
Expand Down Expand Up @@ -7160,6 +7183,7 @@ output_call (struct cb_call *p)

if (p->convention & CB_CONV_JAVA) {
output_java_call(p);
output_exception_handling(p);
return;
}

Expand Down
9 changes: 7 additions & 2 deletions libcob/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,11 @@ cob_resolve_java (const char *class_name,

void
cob_call_java (const cob_java_handle *method_handle) {
if (method_handle == NULL) {
cob_runtime_error(_("Invalid Java method handle: NULL"));
cob_add_exception(COB_EC_ARGUMENT);
return;
}
#if WITH_JNI
if (java_api == NULL) {
cob_runtime_error (_("Java interoperability module cannot be loaded: %s"),
Expand All @@ -2116,10 +2121,9 @@ cob_call_java (const cob_java_handle *method_handle) {
}
return java_api->cob_call (method_handle);
#else
{
static int first_java = 1;

COB_UNUSED (method_handle);

if (first_java) {
first_java = 0;
cob_runtime_warning (_("runtime is not configured to support %s"),
Expand All @@ -2129,5 +2133,6 @@ cob_call_java (const cob_java_handle *method_handle) {
set_json_exception (JSON_INTERNAL_ERROR);
#endif
cob_add_exception (COB_EC_IMP_FEATURE_DISABLED);
}
#endif
}
22 changes: 22 additions & 0 deletions tests/testsuite.src/run_java.at
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ AT_DATA([prog.cob], [
PROGRAM-ID. prog.
PROCEDURE DIVISION.
CALL "Java.Test.printHelloWorld"
NOT ON EXCEPTION
DISPLAY "Java call worked"
END-CALL
STOP RUN.
])

Expand Down Expand Up @@ -110,3 +113,22 @@ AT_CHECK([$COBCRUN_DIRECT ./prog], [1], [],
[libcob: prog.cob:5: error: Java method 'missingMethod' with signature '()V' not found in class 'Test'
])
AT_CLEANUP

AT_SETUP([CALL Java static void (void) (missing class with ON EXCEPTION)])
AT_KEYWORDS([extensions jni exception])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
PROCEDURE DIVISION.
CALL "Java.Test.isAMissingClass"
ON EXCEPTION
DISPLAY "java call not successful"
END-CALL
STOP RUN.
])

AT_CHECK([$COMPILE prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [java call not successful
])
AT_CLEANUP

0 comments on commit bb76d66

Please sign in to comment.