barak / djvulibre

djvulibre sourceforge repo clone, plus Debian packaging info
http://djvu.sourceforge.net
GNU General Public License v2.0
69 stars 19 forks source link

building on Android 10 in termux: pthread_cancel -> pthread_kill #2

Closed stuart-little closed 4 years ago

stuart-little commented 4 years ago

I'm on an aarch64 phone running Android 10 and the Termux terminal emulator / Linux environment.

I was trying to build a clone of this repo and ran into the issue that pthread_cancel() is absent on this machine.

It built in the end, but I implemented the change suggested in that thread I linked. The git diff is as follows:

Date:   Sun Feb 23 07:44:45 2020 -0500

    added Android compatibility: pthread_cancel(*) -> pthread_kill(*,0)

diff --git a/libdjvu/GThreads.cpp b/libdjvu/GThreads.cpp
index 0b0fe0a..d9e9d53 100644
--- a/libdjvu/GThreads.cpp
+++ b/libdjvu/GThreads.cpp
@@ -72,6 +72,10 @@
 #include "GException.h"
 #include "DjVuMessageLite.h"

+// Android
+// source: https://github.com/axel-download-accelerator/axel/issues/150
+#include "android-compat.h"
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/libdjvu/android-compat.h b/libdjvu/android-compat.h
new file mode 100644
index 0000000..e34d9bca
--- /dev/null
+++ b/libdjvu/android-compat.h
@@ -0,0 +1,5 @@
+#ifdef __ANDROID__
+int pthread_cancel(pthread_t h) {
+        return pthread_kill(h, 0);
+}
+#endif /* __ANDROID__ */

So I added a header file libdjvu/android-compat.h that changes pthread_cancel(*) to pthread_kill(*,0) conditional on ifdef __ANDROID__ and then included that header file in libdjvu/GThreads.cpp.

This seems to have worked; I've used the ddjvu utility to convert a .djvu to a .pdf in my phone's terminal just now for instance.

barak commented 4 years ago

This is really an upstream issue, so you might want to report it at http://djvu.sourceforge.net/

stuart-little commented 4 years ago

Will do, thank you!

This is embarrassing: that's precisely what I intended, but found my way to the cloned repo instead.. My apologies for the misunderstanding.

The report will at least be easy to copy-paste now that I have it here though.

barak commented 4 years ago

It's silly that these systems aren't all "federated" so issues etc could cross git hosting domains. I don't really care if upstream is on github or gitlab or sourceforge, right?

stuart-little commented 4 years ago

Absolutely!

Anyway, the "bug" (which isn't really what this is) is being discussed upstream.

stuart-little commented 4 years ago

An update: they were very responsive over there, and this seems to have been fixed:

https://sourceforge.net/p/djvu/djvulibre-git/ci/8e79901a927d7b20b629f5240e64f617d67f3dff/tree/libdjvu/GThreads.cpp?diff=3966e177ce1419e4622b9fd384fff8fed527f421

I cloned that repo (just djvulibre) and it built fine on my phone just now.

barak commented 4 years ago

Yes, djvulibre upstream is super-nice!