Skip to content

Commit d65dd5a

Browse files
committed
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.
1 parent 0d73afa commit d65dd5a

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/src/main/cpp/libkiwix/illustration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
#include <jni.h>
22-
#include "org_kiwix_libkiwix_Book.h"
22+
#include "org_kiwix_libkiwix_Illustration.h"
2323

2424
#include "utils.h"
2525
#include "book.h"

lib/src/main/cpp/utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ inline jobject buildWrapper(JNIEnv* env, const char* class_name, T&& obj, const
141141
setPtr(env, wrapper, std::move(ptr));
142142
return wrapper;
143143
}
144+
145+
template<typename T>
146+
inline jobject buildWrapper(JNIEnv* env, const char* class_name, std::shared_ptr<T>&& ptr, const char* handleName = "nativeHandle") {
147+
auto wrapper = newObject(class_name, env);
148+
setPtr(env, wrapper, std::move(ptr));
149+
return wrapper;
150+
}
151+
144152
#define BUILD_WRAPPER(CLASSNAME, OBJ) buildWrapper(env, CLASSNAME, std::move(OBJ))
145153

146154
template<typename T>

lib/src/test/test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void testLibrary()
122122
Book book = lib.getBookById(bookIds[0]);
123123
assertEquals(book.getTitle(), "Test ZIM file");
124124
assertEquals(book.getTags(), "unit;test");
125+
assertEquals(book.getIllustration(48).width(), 48);
125126
assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small");
126127
assertEquals(book.getUrl(), "http://localhost/small.zim");
127128

0 commit comments

Comments
 (0)