Skip to content

Commit

Permalink
* Fixed invalid code generated for FunctionPointer parameters anno…
Browse files Browse the repository at this point in the history
…tated with `@Const @ByRef`
  • Loading branch information
saudet committed Nov 3, 2013
1 parent 88d011c commit fad2ca5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ This project was conceived at the Okutomi & Tanaka Laboratory, Tokyo Institute o

==Changes==

* Fixed invalid code generated for `FunctionPointer` parameters annotated with `@Const @ByRef`
* Fixed `NullPointerException` in `Loader.load()` when no `@Platform` annotation is provided (issue #38)
* Parsing for anonymous `struct` or `union` and for `typedef void` (mapped to `@Opaque Pointer`) now outputs something
* The `Parser` now expands preprocessor macros and outputs all unprocessed directives as comments
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/googlecode/javacpp/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ private boolean doMethods(Class<?> cls) {
if (functionMethod != null) {
String[] typeName = getCPPTypeName(cls);
String[] returnConvention = typeName[0].split("\\(");
returnConvention[1] = getValueTypeName(returnConvention[1]);
returnConvention[1] = getConstValueTypeName(returnConvention[1]);
String parameterDeclaration = typeName[1].substring(1);
String instanceTypeName = getFunctionClassName(cls);
functionDefinitions.register("struct JavaCPP_hidden " + instanceTypeName + " {\n" +
Expand Down Expand Up @@ -1465,7 +1465,7 @@ private void doCallback(Class<?> cls, Method callbackMethod, String callbackName
String instanceTypeName = getFunctionClassName(cls);
String[] callbackTypeName = getCPPTypeName(cls);
String[] returnConvention = callbackTypeName[0].split("\\(");
returnConvention[1] = getValueTypeName(returnConvention[1]);
returnConvention[1] = getConstValueTypeName(returnConvention[1]);
String parameterDeclaration = callbackTypeName[1].substring(1);
functionPointers.register("static " + instanceTypeName + " " + callbackName + "_instance;");
jclassesInit.register(cls); // for custom class loaders
Expand Down Expand Up @@ -2256,11 +2256,19 @@ public static Annotation getBehavior(Annotation ... annotations) {
return behaviorAnnotation;
}

public static String getConstValueTypeName(String ... typeName) {
String type = typeName[0];
if (type.endsWith("*") || type.endsWith("&")) {
type = type.substring(0, type.length()-1);
}
return type;
}

public static String getValueTypeName(String ... typeName) {
String type = typeName[0];
if (type.startsWith("const ")) {
type = type.substring(6, type.length()-1);
} else if (type.length() != 0) {
} else if (type.endsWith("*") || type.endsWith("&")) {
type = type.substring(0, type.length()-1);
}
return type;
Expand All @@ -2281,9 +2289,9 @@ public static String[] getAnnotatedCPPTypeName(Annotation[] annotations, Class<?

Annotation by = getBy(annotations);
if (by instanceof ByVal) {
prefix = getValueTypeName(typeName);
prefix = getConstValueTypeName(typeName);
} else if (by instanceof ByRef) {
prefix = getValueTypeName(typeName) + "&";
prefix = getConstValueTypeName(typeName) + "&";
} else if (by instanceof ByPtrPtr && !casted) {
prefix = prefix + "*";
} else if (by instanceof ByPtrRef) {
Expand Down

0 comments on commit fad2ca5

Please sign in to comment.