Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getResource changed in Loader.findLibrary #276

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
```

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++...
```

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.4-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>

<name>JavaCPP</name>
<description>The missing bridge between Java and native C++</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacpp/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/bytedeco/javacpp/indexer/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected Indexer(long[] sizes, long[] strides) {
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 */
Expand Down