-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Handling of Non-Void Java Method Calls in GnuCOBOL #174
base: java-interop
Are you sure you want to change the base?
Changes from 1 commit
452d4ec
7b31a0b
332e29c
1f90ff3
da1b85d
0013016
91751c8
8de4183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7098,7 +7098,9 @@ output_java_call (struct cb_call *p) | |
char *last_dot; | ||
char *method_name; | ||
const char *class_name; | ||
char method_signature[256] = "("; | ||
char* mangled; | ||
struct cb_tree *ptr; | ||
|
||
mangled = strdup(class_and_method_name); | ||
for (size_t i = 0; i < strlen(mangled) + 1; i++) { | ||
|
@@ -7115,18 +7117,103 @@ output_java_call (struct cb_call *p) | |
method_name = last_dot + 1; | ||
class_name = class_and_method_name; | ||
|
||
for(ptr = p->args; ptr != NULL; ptr = ptr->next) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: indentation is strange here. I think you need to adjust that in your settings for this project. |
||
switch(CB_TREE_TAG(ptr)) { | ||
case CB_TAG_INTEGER: | ||
strcat(method_signature, "I"); | ||
break; | ||
case CB_TAG_LONG: | ||
strcat(method_signature, "J"); | ||
break; | ||
case CB_TAG_FLOAT: | ||
strcat(method_signature, "F"); | ||
break; | ||
case CB_TAG_DOUBLE: | ||
strcat(method_signature, "D"); | ||
break; | ||
case CB_TAG_BOOLEAN: | ||
strcat(method_signature, "Z"); | ||
break; | ||
case CB_TAG_BYTE: | ||
strcat(method_signature, "B"); | ||
break; | ||
case CB_TAG_SHORT: | ||
strcat(method_signature, "S"); | ||
break; | ||
case CB_TAG_CHAR: | ||
strcat(method_signature, "C"); | ||
break; | ||
case CB_TAG_STRING: | ||
strcat(method_signature, "Ljava/lang/String;"); | ||
break; | ||
case CB_TAG_OBJECT: | ||
strcat(method_signature, "Ljava/lang/Object;"); | ||
break; | ||
case CB_TAG_LITERAL: | ||
if(CB_TREE_CATEGORY(ptr) == CB_CATEGORY_NUMERIC) { | ||
strcat(method_signature, "I"); | ||
} else if(CB_TREE_CATEGORY(ptr) == CB_CATEGORY_ALPHANUMERIC) { | ||
strcat(method_signature, "Ljava/lang/String;"); | ||
} | ||
break; | ||
case CB_TAG_ARRAY: | ||
switch(CB_TREE_TAG(CB_TREE(ptr)->next)) { | ||
case CB_TAG_INTEGER: | ||
strcat(method_signature, "[I"); | ||
break; | ||
case CB_TAG_LONG: | ||
strcat(method_signature, "[J"); | ||
break; | ||
case CB_TAG_FLOAT: | ||
strcat(method_signature, "[F"); | ||
break; | ||
case CB_TAG_DOUBLE: | ||
strcat(method_signature, "[D"); | ||
break; | ||
case CB_TAG_BOOLEAN: | ||
strcat(method_signature, "[Z"); | ||
break; | ||
case CB_TAG_BYTE: | ||
strcat(method_signature, "[B"); | ||
break; | ||
case CB_TAG_SHORT: | ||
strcat(method_signature, "[S"); | ||
break; | ||
case CB_TAG_CHAR: | ||
strcat(method_signature, "[C"); | ||
break; | ||
case CB_TAG_STRING: | ||
strcat(method_signature, "[Ljava/lang/String;"); | ||
break; | ||
case CB_TAG_OBJECT: | ||
strcat(method_signature, "[Ljava/lang/Object;"); | ||
break; | ||
default: | ||
cobc_err_msg(_("Unsupported array type in Java method call")); | ||
COBC_ABORT(); | ||
} | ||
break; | ||
default: | ||
cobc_err_msg(_("Unsupported argument type in Java method call")); | ||
COBC_ABORT(); | ||
} | ||
} | ||
|
||
strcat(method_signature, ")V"); | ||
|
||
lookup_java_call(mangled); | ||
output_line("if (call_java_%s == NULL)", mangled); | ||
output_block_open(); | ||
|
||
output_prefix(); | ||
output_line("call_java_%s = ", mangled); | ||
output("cob_resolve_java(\"%s\", \"%s\", \"()V\");", class_name, method_name); | ||
output("cob_resolve_java(\"%s\", \"%s\", \"()V\");", class_name, method_name, method_signature); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you should probable replace |
||
output_newline (); | ||
output_prefix (); | ||
output_line("cob_call_java(call_java_%s);\n", mangled); | ||
output_newline(); | ||
output_block_close(); | ||
cobc_free(mangled); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will likely cause a use-after-free since |
||
} | ||
|
||
static void | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For internal buffer sizes you have
COB_*_BUFF
definitions inlibcob/common.h
that you can use here as well. Typical signature length could exceed 256 without much effort I think (with long-enough Java package names). I'd go forCOB_NORMAL_BUFF
(2048) for now.