Skip to content

Commit

Permalink
* Fix Generator compiler errors for FunctionPointer with `@Uniqu…
Browse files Browse the repository at this point in the history
…ePtr` arguments (issue #613)
  • Loading branch information
saudet committed Oct 12, 2022
1 parent 40e3d38 commit b411ac6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix `Generator` compiler errors for `FunctionPointer` with `@UniquePtr` arguments ([issue #613](https://github.com/bytedeco/javacpp/issues/613))
* Fix `Generator` compiler errors on Mac for Clang without Objective-C support ([pull #610](https://github.com/bytedeco/javacpp/pull/610))
* Prevent `Parser` from outputting cast methods for base classes that are `Info.skip` ([pull #607](https://github.com/bytedeco/javacpp/pull/607))
* Ensure `Generator` and `Parser` process header files from `cinclude` before `include` ([issue #580](https://github.com/bytedeco/javacpp/issues/580))
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver
out.println(" this->ptr = ptr;");
out.println(" this->size = size;");
out.println(" this->owner = owner;");
out.println(" this->uniquePtr = owner != NULL && owner != ptr ? *(U*)owner : U((T*)ptr);");
out.println(" this->uniquePtr = owner != NULL && owner != ptr ? (U&&)*(U*)owner : U((T*)ptr);");
out.println(" }");
out.println(" static void deallocate(void* owner) { delete (U*)owner; }");
out.println(" operator typename UNIQUE_PTR_NAMESPACE::remove_const<T>::type*() {");
Expand Down Expand Up @@ -3079,6 +3079,24 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
String parameterDeclaration = callbackTypeName[1].substring(1);
String fieldName = mangle(callbackMethod.getName()) + "__" + mangle(signature(callbackMethod.getParameterTypes()));

String callbackArguments = "";
for (int j = 0; j < callbackParameterTypes.length; j++) {
String[] typeName = cppTypeName(callbackParameterTypes[j], callbackParameterAnnotations[j]);
String valueTypeName = valueTypeName(typeName);
AdapterInformation adapterInfo = adapterInformation(false, valueTypeName, callbackParameterAnnotations[j]);
if (adapterInfo != null) {
String cast2 = adapterInfo.cast2.trim();
if (cast2.length() > 0 && !cast2.startsWith("(") && !cast2.endsWith(")")) {
cast2 = "(" + cast2 + ")";
}
callbackArguments += cast2;
}
callbackArguments += "arg" + j;
if (j < callbackParameterTypes.length - 1) {
callbackArguments += ", ";
}
}

String firstLine = "";
if (methodInfo != null) {
// stuff from a virtualized class
Expand All @@ -3098,13 +3116,7 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
return;
} else if (methodInfo.allocator) {
member += subType + nonconstParamDeclaration + " : " + valueTypeName + "(";
for (int j = 0; j < callbackParameterTypes.length; j++) {
member += "arg" + j;
if (j < callbackParameterTypes.length - 1) {
member += ", ";
}
}
member += "), obj(NULL) { }";
member += callbackArguments + "), obj(NULL) { }";
} else {
Set<String> functionList = virtualFunctions.get(cls);
if (functionList == null) {
Expand All @@ -3128,13 +3140,7 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
member += "throw JavaCPP_exception(\"Cannot call pure virtual function " + valueTypeName + "::" + methodInfo.memberName[0] + "().\"); }";
} else {
member += (callbackReturnType != void.class ? "return " : "") + valueTypeName + "::" + methodInfo.memberName[0] + "(";
for (int j = 0; j < callbackParameterTypes.length; j++) {
member += "arg" + j;
if (j < callbackParameterTypes.length - 1) {
member += ", ";
}
}
member += "); }";
member += callbackArguments + "); }";
}
firstLine = returnType[0] + (returnConvention.length > 1 ? returnConvention[1] : "")
+ subType + "::" + methodInfo.memberName[0] + parameterDeclaration + returnType[1] + " {";
Expand All @@ -3158,13 +3164,7 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
out.println("JNIEXPORT " + returnType[0] + (returnConvention.length > 1 ?
returnConvention[1] : "") + callbackName + (i > 0 ? i : "") + parameterDeclaration + returnType[1] + " {");
out.print((callbackReturnType != void.class ? " return " : " ") + instanceTypeName + "_instances[" + i + "](");
for (int j = 0; j < callbackParameterTypes.length; j++) {
out.print("arg" + j);
if (j < callbackParameterTypes.length - 1) {
out.print(", ");
}
}
out.println(");");
out.println(callbackArguments + ");");
out.println("}");
}
if (convention != null && !convention.extern().equals("C")) {
Expand Down

0 comments on commit b411ac6

Please sign in to comment.