Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java')
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java37
1 files changed, 33 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
index 5816ce8fdb..c05290e1ee 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java
@@ -11,7 +11,8 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Red Hat Inc. - stop generating pre 1.2 JNI code
- * Martin Oberhuber (WindRiver) - [515610] Fix incorrect code for memmove()
+ * Martin Oberhuber (WindRiver) - [515610] Fix incorrect code for memmove()
+ * Thomas Wolf <thomas.wolf@paranor.ch> [534923] Fix incorrect casts
*******************************************************************************/
package org.eclipse.swt.tools.internal;
@@ -793,12 +794,14 @@ void generateFunctionCall(JNIMethod method, JNIParameter[] params, JNIType retur
if (method.getFlag(Flags.FLAG_CAST)) {
output("((");
String returnCast = returnType.getTypeSignature2(!returnType.equals(returnType64));
- if (name.equals("objc_msgSend_bool") && returnCast.equals("jboolean")) {
+ if ((name.equals("objc_msgSend_bool") || name.equals("objc_msgSendSuper_bool")) && returnCast.equals("jboolean")) {
returnCast = "BOOL";
}
output(returnCast);
output(" (*)(");
- for (int i = 0; i < params.length; i++) {
+ int fixedargs = getNumberOfFixedArguments(method);
+ int n = fixedargs > 0 ? fixedargs : params.length;
+ for (int i = 0; i < n; i++) {
if (i != 0) output(", ");
JNIParameter param = params[i];
String cast = param.getCast();
@@ -816,6 +819,9 @@ void generateFunctionCall(JNIMethod method, JNIParameter[] params, JNIType retur
output(paramType.getTypeSignature4(!paramType.equals(paramType64), param.getFlag(FLAG_STRUCT)));
}
}
+ if (fixedargs > 0) {
+ output(", ...");
+ }
output("))");
}
String accessor = method.getAccessor();
@@ -875,7 +881,8 @@ void generate_objc_msgSend_stret (JNIParameter[] params, String func) {
JNIType paramType = params[0].getType(), paramType64 = params[0].getType64();
output(paramType.getTypeSignature4(!paramType.equals(paramType64), true));
output(" (*)(");
- for (int i = 1; i < params.length; i++) {
+ // Only the fixed arguments
+ for (int i = 1; i <= 2; i++) {
if (i != 1) output(", ");
JNIParameter param = params[i];
String cast = param.getCast();
@@ -893,11 +900,33 @@ void generate_objc_msgSend_stret (JNIParameter[] params, String func) {
output(paramType.getTypeSignature4(!paramType.equals(paramType64), param.getFlag(FLAG_STRUCT)));
}
}
+ output(", ...");
output("))");
output(func);
output(")");
}
+/**
+ * Determines whether the {@code method} has variadic arguments. If so, returns
+ * the number of fixed parameters (always {@code > 0}). Otherwise returns zero,
+ * which indicates that all parameters are fixed.
+ *
+ * @param method to examine
+ * @return the number of fixed parameters, or zero if all parameters are fixed
+ * (the method has no varargs)
+ */
+int getNumberOfFixedArguments(JNIMethod method) {
+ Object param = method.getParam("fixedargs");
+ if (param == null) {
+ return 0;
+ }
+ String number = param.toString();
+ if (number.isEmpty()) {
+ return 0;
+ }
+ return Integer.parseInt(number);
+}
+
void generateReturn(JNIType returnType, boolean needsReturn) {
if (needsReturn && !returnType.isType("void")) {
outputln("\treturn rc;");

Back to the top