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:
Matthieu Gautier 2023-05-17 14:33:43 +02:00
parent 4d73e57c69
commit 9312e32435
3 changed files with 10 additions and 1 deletions

View File

@ -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"

View File

@ -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>

View File

@ -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");