Last active
July 14, 2017 09:36
-
-
Save joakim-noah/09a59bdd6e04dd2f3d3ad6e15573ad97 to your computer and use it in GitHub Desktop.
Android/ARM support for phobos, for ldc release-1.3.x branch 2.073
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/std/file.d b/std/file.d | |
index 709461bf..4eadf0c7 100644 | |
--- a/std/file.d | |
+++ b/std/file.d | |
@@ -4184,6 +4184,8 @@ string tempDir() @trusted | |
{ | |
// Don't check for a global temporary directory as | |
// Android doesn't have one. | |
+ version(apk) | |
+ cache = "/data/data/com.example.native_activity/files"; | |
} | |
else version(Posix) | |
{ | |
diff --git a/std/stdio.d b/std/stdio.d | |
index 0c315026..8b1860d0 100644 | |
--- a/std/stdio.d | |
+++ b/std/stdio.d | |
@@ -310,6 +310,45 @@ else version (GENERIC_IO) | |
void funlockfile(FILE*); | |
} | |
+ version(CRuntime_Bionic) | |
+ { | |
+ import core.stdc.wchar_ : mbstate_t; | |
+ import core.sys.posix.sys.types : pthread_mutex_t; | |
+ | |
+ extern(C) struct wchar_io_data | |
+ { | |
+ mbstate_t wcio_mbstate_in; | |
+ mbstate_t wcio_mbstate_out; | |
+ wchar_t[1] wcio_ungetwc_buf; | |
+ size_t wcio_ungetwc_inbuf; | |
+ int wcio_mode; | |
+ } | |
+ | |
+ extern(C) struct __sfileext | |
+ { | |
+ __sbuf _ub; | |
+ wchar_io_data _wcio; | |
+ pthread_mutex_t _lock; | |
+ } | |
+ | |
+ void bionic_lock(FILE* foo) | |
+ { | |
+ if( foo == stdout._p.handle || foo == stdin._p.handle || foo == stderr._p.handle) | |
+ { | |
+ auto ext = cast(__sfileext*) foo._ext._base; | |
+ if (ext._lock.value == 0) | |
+ { | |
+ // A bionic regression in Android 5.0 leaves | |
+ // the mutex for stdout/err/in uninitialized, | |
+ // so check for that and initialize it. | |
+ printf("lock is zero, initializing...\n"); | |
+ ext._lock.value = 0x4000; | |
+ } | |
+ } | |
+ flockfile(foo); | |
+ } | |
+ } | |
+ | |
int fputc_unlocked(int c, _iobuf* fp) { return fputc(c, cast(shared) fp); } | |
int fputwc_unlocked(wchar_t c, _iobuf* fp) | |
{ | |
@@ -328,7 +367,10 @@ else version (GENERIC_IO) | |
alias FGETC = fgetc_unlocked; | |
alias FGETWC = fgetwc_unlocked; | |
- alias FLOCK = flockfile; | |
+ version(CRuntime_Bionic) | |
+ alias FLOCK = bionic_lock; | |
+ else | |
+ alias FLOCK = flockfile; | |
alias FUNLOCK = funlockfile; | |
} | |
else | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment