Skip to content

Commit

Permalink
jnaerator with bridj: fixing problem with varargs and variable named …
Browse files Browse the repository at this point in the history
…with reserved java keywords

Fixing incorrect generation for bridj backend mainly for varargs
* added tests for the problem of varargs (also for reserved name)
* fixing problem by taking inspiration from the jna backed version

=== Copyright Transfert Declaration ===

I, Rémi Emonet, declare being the only author of the current commit.

I fully transfer the copyright for this patch to Olivier Chafik for an
integration as part of the nativelibs4java project provided it uses
opensource licenses such as BSD license, Apache license, MIT license
or any equivalent licensing scheme.
  • Loading branch information
Rémi Émonet committed Aug 9, 2011
1 parent 1a0c9c7 commit 74b59d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,29 @@ private void convertBridJFunction(Function function, Signatures signatures, bool
nativeMethod.setValueType(retType.typeRef);

Map<String, NL4JConversion> argTypes = new LinkedHashMap<String, NL4JConversion>();

boolean isObjectiveC = function.getType() == Type.ObjCMethod;
int iArg = 1;
Set<String> argNames = new TreeSet<String>();

for (Arg arg : function.getArgs()) {
String argName = arg.getName();

NL4JConversion argType = result.typeConverter.convertTypeToNL4J(arg.getValueType(), libraryClassName, null, null, -1, -1);
argTypes.put(argName, argType);
// typedMethod.addArg(new Arg(argName, argType.getTypedTypeRef()));
nativeMethod.addArg(argType.annotateTypedType(new Arg(argName, argType.typeRef)));//.getTypedTypeRef())));
// nativeMethod.addArg(argType.annotateRawType(new Arg(argName, argType.getRawType())));
if (arg.isVarArg() && arg.getValueType() == null) {
// TODO choose vaname dynamically ! (<- this todo is copied from the one for JNI (same file)) [remi]
Identifier vaType = ident(isObjectiveC ? NSObject.class : Object.class);
String argName = chooseJavaArgName("varargs", iArg, argNames);
nativeMethod.addArg(new Arg(argName, typeRef(vaType.clone()))).setVarArg(true);
// TODO is there an equivalent of "alternativeOutputs" with BridJ? if (alternativeOutputs) { [remi]
} else {
// TODO should we use also chooseJavaArgName in this case? I guess so, so I put it [remi]
String argName = chooseJavaArgName(arg.getName(), iArg, argNames);
NL4JConversion argType = result.typeConverter.convertTypeToNL4J(arg.getValueType(), libraryClassName, null, null, -1, -1);
argTypes.put(argName, argType);
// typedMethod.addArg(new Arg(argName, argType.getTypedTypeRef()));
nativeMethod.addArg(argType.annotateTypedType(new Arg(argName, argType.typeRef)));//.getTypedTypeRef())));
// nativeMethod.addArg(argType.annotateRawType(new Arg(argName, argType.getRawType())));
}
iArg++;
}
//
String //natFullSig = nativeMethod.computeSignature(true),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
void varargAndReserved(int transient, ...);
--
#runtime(JNAerator)
import test.*;
import static test.TestLibrary.*;

INSTANCE.varargAndReserved(1);
INSTANCE.varargAndReserved(1,(Pointer)null);
--
#runtime(BridJ)
import test.*;
import static test.TestLibrary.*;

varargAndReserved(1);
varargAndReserved(1,(Pointer)null);

0 comments on commit 74b59d5

Please sign in to comment.