From 6e4775610b108c500a4699ed377fdfc6fa1927ef Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Fri, 30 Nov 2018 11:14:25 +0900 Subject: [PATCH 1/4] Update version in the `pom.xml` file to 1.5-SNAPSHOT --- README.md | 20 +++++--------------- pom.xml | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e3bc55e6c..5b21df75d 100644 --- a/README.md +++ b/README.md @@ -154,9 +154,7 @@ public class NativeLibrary { After compiling the Java source code in the usual way, we also need to build using JavaCPP before executing it as follows: ```bash -$ javac -cp javacpp.jar NativeLibrary.java -$ java -jar javacpp.jar NativeLibrary -$ java -cp javacpp.jar NativeLibrary +$ java -jar javacpp.jar NativeLibrary.java -exec Hello World! ``` @@ -213,9 +211,7 @@ public class VectorTest { Executing that program using these commands produces the following output: ```bash -$ javac -cp javacpp.jar VectorTest.java -$ java -jar javacpp.jar VectorTest -$ java -cp javacpp.jar VectorTest +$ java -jar javacpp.jar VectorTest.java -exec 13 42 org.bytedeco.javacpp.Pointer[address=0xdeadbeef,position=0,limit=0,capacity=0,deallocator=null] Exception in thread "main" java.lang.RuntimeException: vector::_M_range_check: __n (which is 42) >= this->size() (which is 13) at VectorTest$PointerVectorVector.at(Native Method) @@ -267,9 +263,7 @@ public class Processor { It would then compile and execute like this: ```bash -$ javac -cp javacpp.jar Processor.java -$ java -jar javacpp.jar Processor -$ java -cp javacpp.jar Processor +$ java -jar javacpp.jar Processor.java -exec Processing in C++... ``` @@ -325,8 +319,7 @@ public class Foo { Since functions also have pointers, we can use `FunctionPointer` instances accordingly, in ways similar to the [`FunPtr` type of Haskell FFI](http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Foreign-Ptr.html#g:2), but where any `java.lang.Throwable` object thrown gets translated to `std::exception`. Building and running this sample code with these commands under Linux x86_64 produces the expected output: ```bash -$ javac -cp javacpp.jar Foo.java -$ java -jar javacpp.jar Foo -header +$ java -jar javacpp.jar Foo.java -header $ g++ -I/usr/lib/jvm/java/include/ -I/usr/lib/jvm/java/include/linux/ foo.cpp linux-x86_64/libjniFoo.so -o foo $ ./foo java.lang.Exception: bar 42 @@ -351,7 +344,6 @@ public: void callback(Foo *foo) { foo->bar(); } - ``` The function `Foo::bar()` can be overridden in Java if we declare the method in the peer class either as `native` or `abstract` and annotate it with `@Virtual`, for example: @@ -391,9 +383,7 @@ public class VirtualFoo { Which outputs what one would naturally assume: ```bash -$ javac -cp javacpp.jar VirtualFoo.java -$ java -jar javacpp.jar VirtualFoo -$ java -cp javacpp.jar VirtualFoo +$ java -jar javacpp.jar VirtualFoo.java -exec Callback in C++ (n == 13) Callback in Java (n == 42) Callback in C++ (n == 13) diff --git a/pom.xml b/pom.xml index 47bf7f06e..05d2b865d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.bytedeco javacpp - 1.4.4-SNAPSHOT + 1.5-SNAPSHOT JavaCPP The missing bridge between Java and native C++ From 30579d49a127ef19af550de52f1078f845acbf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Guillemet?= Date: Mon, 3 Dec 2018 17:15:09 +0100 Subject: [PATCH 2/4] Indexer rows(), col().... returning -1 if not 3D --- .../org/bytedeco/javacpp/indexer/Indexer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java index 2d535481f..4a8bc73dc 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java @@ -73,17 +73,17 @@ protected Indexer(long[] sizes, long[] strides) { /** Returns {@link #strides} */ public long[] strides() { return strides; } - /** Returns {@code sizes[0]} */ - public long rows() { return sizes[0]; } - /** Returns {@code sizes[1]} */ - public long cols() { return sizes[1]; } - - /** Returns {@code sizes[1]} */ - public long width() { return sizes[1]; } - /** Returns {@code sizes[0]} */ - public long height() { return sizes[0]; } - /** Returns {@code sizes[2]} */ - public long channels() { return sizes[2]; } + /** Returns {@code sizes[0]} if the number of dimensions is 3, else returns -1 */ + public long rows() { return sizes.length == 3 ? sizes[0] : -1; } + /** Returns {@code sizes[1]} if the number of dimensions is 3, else returns -1 */ + public long cols() { return sizes.length == 3 ? sizes[1] : -1; } + + /** Returns {@code sizes[1]} if the number of dimensions is 3, else returns -1 */ + public long width() { return sizes.length == 3 ? sizes[1] : -1; } + /** Returns {@code sizes[0]} if the number of dimensions is 3, else returns -1 */ + public long height() { return sizes.length == 3 ? sizes[0] : -1; } + /** Returns {@code sizes[2]} if the number of dimensions is 3, else returns -1 */ + public long channels() { return sizes.length == 3 ? sizes[2] : 1; } protected static final long checkIndex(long i, long size) { if (i < 0 || i >= size) { From bf141ff166faf896fb669edeb5e7fd9b56bb8918 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Fri, 30 Nov 2018 11:14:25 +0900 Subject: [PATCH 3/4] Update version in the `pom.xml` file to 1.5-SNAPSHOT --- README.md | 20 +++++--------------- pom.xml | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e3bc55e6c..5b21df75d 100644 --- a/README.md +++ b/README.md @@ -154,9 +154,7 @@ public class NativeLibrary { After compiling the Java source code in the usual way, we also need to build using JavaCPP before executing it as follows: ```bash -$ javac -cp javacpp.jar NativeLibrary.java -$ java -jar javacpp.jar NativeLibrary -$ java -cp javacpp.jar NativeLibrary +$ java -jar javacpp.jar NativeLibrary.java -exec Hello World! ``` @@ -213,9 +211,7 @@ public class VectorTest { Executing that program using these commands produces the following output: ```bash -$ javac -cp javacpp.jar VectorTest.java -$ java -jar javacpp.jar VectorTest -$ java -cp javacpp.jar VectorTest +$ java -jar javacpp.jar VectorTest.java -exec 13 42 org.bytedeco.javacpp.Pointer[address=0xdeadbeef,position=0,limit=0,capacity=0,deallocator=null] Exception in thread "main" java.lang.RuntimeException: vector::_M_range_check: __n (which is 42) >= this->size() (which is 13) at VectorTest$PointerVectorVector.at(Native Method) @@ -267,9 +263,7 @@ public class Processor { It would then compile and execute like this: ```bash -$ javac -cp javacpp.jar Processor.java -$ java -jar javacpp.jar Processor -$ java -cp javacpp.jar Processor +$ java -jar javacpp.jar Processor.java -exec Processing in C++... ``` @@ -325,8 +319,7 @@ public class Foo { Since functions also have pointers, we can use `FunctionPointer` instances accordingly, in ways similar to the [`FunPtr` type of Haskell FFI](http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Foreign-Ptr.html#g:2), but where any `java.lang.Throwable` object thrown gets translated to `std::exception`. Building and running this sample code with these commands under Linux x86_64 produces the expected output: ```bash -$ javac -cp javacpp.jar Foo.java -$ java -jar javacpp.jar Foo -header +$ java -jar javacpp.jar Foo.java -header $ g++ -I/usr/lib/jvm/java/include/ -I/usr/lib/jvm/java/include/linux/ foo.cpp linux-x86_64/libjniFoo.so -o foo $ ./foo java.lang.Exception: bar 42 @@ -351,7 +344,6 @@ public: void callback(Foo *foo) { foo->bar(); } - ``` The function `Foo::bar()` can be overridden in Java if we declare the method in the peer class either as `native` or `abstract` and annotate it with `@Virtual`, for example: @@ -391,9 +383,7 @@ public class VirtualFoo { Which outputs what one would naturally assume: ```bash -$ javac -cp javacpp.jar VirtualFoo.java -$ java -jar javacpp.jar VirtualFoo -$ java -cp javacpp.jar VirtualFoo +$ java -jar javacpp.jar VirtualFoo.java -exec Callback in C++ (n == 13) Callback in Java (n == 42) Callback in C++ (n == 13) diff --git a/pom.xml b/pom.xml index 47bf7f06e..05d2b865d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.bytedeco javacpp - 1.4.4-SNAPSHOT + 1.5-SNAPSHOT JavaCPP The missing bridge between Java and native C++ From f44145e91973fca9d531bbb4f8cc28c9ca2132b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Guillemet?= Date: Wed, 5 Dec 2018 23:15:32 +0100 Subject: [PATCH 4/4] cls.getResource changed to classLoader.getResource --- src/main/java/org/bytedeco/javacpp/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bytedeco/javacpp/Loader.java b/src/main/java/org/bytedeco/javacpp/Loader.java index f46ec61e8..3173723ad 100644 --- a/src/main/java/org/bytedeco/javacpp/Loader.java +++ b/src/main/java/org/bytedeco/javacpp/Loader.java @@ -1098,7 +1098,7 @@ public static URL[] findLibrary(Class cls, ClassProperties properties, String li } String subdir = (resource == null ? "" : "/" + resource) + platform + (extension == null ? "" : extension) + "/"; - URL u = cls.getResource(subdir + styles[i]); + URL u = cls.getClassLoader().getResource(subdir + styles[i]); if (u != null) { if (reference) { try {