mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-08 06:38:41 -04:00
Fix illustration.
`Book::getIllustration(size)` return a `shared_ptr<Illustration>`. The current `buildWrapper` was creating a wrapper on a `shared_ptr<Illustration>` (so a `shared_ptr<shared_ptr<Illustration>>`) but we was converting to a `shared_ptr<Illustration>` and so we were doing wrong reads. By specializing the buildWrapper for `shared_ptr<T>`, we avoid the "double shared_ptr" and we are good.
This commit is contained in:
parent
4d73e57c69
commit
9312e32435
@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
#include <jni.h>
|
||||
#include "org_kiwix_libkiwix_Book.h"
|
||||
#include "org_kiwix_libkiwix_Illustration.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "book.h"
|
||||
|
@ -141,6 +141,14 @@ inline jobject buildWrapper(JNIEnv* env, const char* class_name, T&& obj, const
|
||||
setPtr(env, wrapper, std::move(ptr));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline jobject buildWrapper(JNIEnv* env, const char* class_name, std::shared_ptr<T>&& ptr, const char* handleName = "nativeHandle") {
|
||||
auto wrapper = newObject(class_name, env);
|
||||
setPtr(env, wrapper, std::move(ptr));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
#define BUILD_WRAPPER(CLASSNAME, OBJ) buildWrapper(env, CLASSNAME, std::move(OBJ))
|
||||
|
||||
template<typename T>
|
||||
|
@ -122,6 +122,7 @@ public class test {
|
||||
Book book = lib.getBookById(bookIds[0]);
|
||||
assertEquals(book.getTitle(), "Test ZIM file");
|
||||
assertEquals(book.getTags(), "unit;test");
|
||||
assertEquals(book.getIllustration(48).width(), 48);
|
||||
assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small");
|
||||
assertEquals(book.getUrl(), "http://localhost/small.zim");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user