Skip to content

Commit

Permalink
* Provide @Virtual(true) to specify pure virtual functions and pre…
Browse files Browse the repository at this point in the history
…vent `Generator` from making undefined calls

 * Update properties for Android to detect undefined symbols at compile time
  • Loading branch information
saudet committed Sep 25, 2015
1 parent 9ff6d93 commit 5070834
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Provide `@Virtual(true)` to specify pure virtual functions and prevent `Generator` from making undefined calls
* Update properties for Android to detect undefined symbols at compile time
* Log when `Pointer.deallocator` gets registered, garbage collected, or deallocated manually, if `Logger.isDebugEnabled()` (redirectable to SLF4J)
* Make `Pointer implements AutoCloseable` to let us try-with-resources, thus bumping requirements to Java SE 7 and Android 4.0
* Introduce the concept of "owner address" to integrate `Pointer` transparently with `std::shared_ptr`, etc (Thanks to Cyprien Noel for the idea!)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/bytedeco/javacpp/annotation/Virtual.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
*/
@Documented @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Virtual { }
public @interface Virtual {
/** Pure (abstract) or not. */
boolean value() default false;
}
18 changes: 11 additions & 7 deletions src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1818,15 +1818,19 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, boolean
}
member += "virtual " + returnConvention[0] + (returnConvention.length > 1 ? returnConvention[1] : "")
+ methodInfo.memberName[0] + parameterDeclaration + ";\n "
+ returnConvention[0] + "super_" + methodInfo.memberName[0] + nonconstParamDeclaration + " { "
+ (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 += ", ";
+ returnConvention[0] + "super_" + methodInfo.memberName[0] + nonconstParamDeclaration + " { ";
if (methodInfo.method.getAnnotation(Virtual.class).value()) {
member += "throw JavaCPP_exception(\"Cannot call a pure virtual function.\"); }";
} 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 += "); }";
firstLine = returnConvention[0] + (returnConvention.length > 1 ? returnConvention[1] : "")
+ subType + "::" + methodInfo.memberName[0] + parameterDeclaration + " {";
functionList.add(fieldName);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,8 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti

// add @Virtual annotation on user request only, inherited through context
if (type.virtual && context.virtualize) {
modifiers = context.inaccessible ? "@Virtual protected native " : "@Virtual public native ";
modifiers = "@Virtual" + (decl.abstractMember ? "(true) " : " ")
+ (context.inaccessible ? "protected native " : "public native ");
}

// compose the text of the declaration with the info we got up until this point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ platform.path.separator=:
platform.source.suffix=.cpp
platform.root=../android/android-ndk/
platform.sysroot.prefix=--sysroot=
platform.sysroot=platforms/android-9/arch-arm/
platform.sysroot=platforms/android-14/arch-arm/
platform.includepath.prefix=-I
platform.includepath=sources/cxx-stl/gnu-libstdc++/4.9/include/:sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include/
platform.compiler=toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
platform.compiler.cpp11=-std=c++11
platform.compiler.default=-march=armv5te -mtune=xscale -msoft-float
platform.compiler.fastfpu=-march=armv7-a -mfloat-abi=softfp -mfpu=neon -ffast-math -Wl,--fix-cortex-a8
platform.compiler.nodeprecated=-Wno-deprecated-declarations
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined -s -o\u0020
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-undefined -s -o\u0020
platform.linkpath.prefix=-L
platform.linkpath=sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/
platform.link.prefix=-l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ platform.compiler.cpp11=-std=c++11
platform.compiler.default=
platform.compiler.fastfpu=-ffast-math
platform.compiler.nodeprecated=-Wno-deprecated-declarations
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined -s -o\u0020
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-undefined -s -o\u0020
platform.linkpath.prefix=-L
platform.linkpath=sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/
platform.link.prefix=-l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ platform.path.separator=:
platform.source.suffix=.cpp
platform.root=../android/android-ndk/
platform.sysroot.prefix=--sysroot=
platform.sysroot=platforms/android-9/arch-x86/
platform.sysroot=platforms/android-14/arch-x86/
platform.includepath.prefix=-I
platform.includepath=sources/cxx-stl/gnu-libstdc++/4.9/include/:sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include/
platform.compiler=toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-g++
platform.compiler.cpp11=-std=c++11
platform.compiler.default=
platform.compiler.fastfpu=-msse3 -ffast-math -mfpmath=sse
platform.compiler.nodeprecated=-Wno-deprecated-declarations
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined -s -o\u0020
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-undefined -s -o\u0020
platform.linkpath.prefix=-L
platform.linkpath=sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/
platform.link.prefix=-l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ platform.compiler.cpp11=-std=c++11
platform.compiler.default=
platform.compiler.fastfpu=-msse3 -ffast-math
platform.compiler.nodeprecated=-Wno-deprecated-declarations
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined -s -o\u0020
platform.compiler.output=-Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-undefined -s -o\u0020
platform.linkpath.prefix=-L
platform.linkpath=sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/
platform.link.prefix=-l
Expand Down

0 comments on commit 5070834

Please sign in to comment.