Skip to content

Commit 63bcbd0

Browse files
committed
Added python internal log -> logcat redirection
1 parent 358c91f commit 63bcbd0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pythonforandroid/recipes/python3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def prebuild_armeabi(self):
3838
self.apply_patch(join('patches', 'python-{version}-python-misc.patch'.format(version=self.version)))
3939

4040
self.apply_patch(join('patches', 'python-{version}-libpymodules_loader.patch'.format(version=self.version)))
41+
self.apply_patch('log_failures.patch')
4142

4243

4344
shprint(sh.touch, join(build_dir, '.patched'))
@@ -67,6 +68,7 @@ def build_armeabi(self):
6768
# shprint(sh.cp, join(hostpython_recipe.get_recipe_dir(), 'Setup'), 'Modules')
6869

6970
env = ArchAndroid(self.ctx).get_env()
71+
env["LDFLAGS"] = env["LDFLAGS"] + ' -llog'
7072

7173
# AND: Should probably move these to get_recipe_env for
7274
# neatness, but the whole recipe needs tidying along these
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
2+
index 0327830..903cc02 100644
3+
--- a/Python/pythonrun.c
4+
+++ b/Python/pythonrun.c
5+
@@ -39,6 +39,11 @@
6+
#define PATH_MAX MAXPATHLEN
7+
#endif
8+
9+
+/* p4a log redirect */
10+
+#include <jni.h>
11+
+#include "android/log.h"
12+
+#define LOG(x) __android_log_write(ANDROID_LOG_INFO, "python", (x))
13+
+
14+
_Py_IDENTIFIER(builtins);
15+
_Py_IDENTIFIER(excepthook);
16+
_Py_IDENTIFIER(flush);
17+
@@ -2594,6 +2599,9 @@ Py_FatalError(const char *msg)
18+
{
19+
const int fd = fileno(stderr);
20+
PyThreadState *tstate;
21+
+
22+
+ LOG("Py_FatalError called!");
23+
+ LOG(msg);
24+
25+
fprintf(stderr, "Fatal Python error: %s\n", msg);
26+
fflush(stderr); /* it helps in Windows debug build */

0 commit comments

Comments
 (0)