lbry-android/p4a/pythonforandroid/recipes/python3/log_failures.patch
Akinwale Ariwodola 744cfaebc2 Initial commit
2017-08-13 02:24:00 +01:00

385 lines
13 KiB
Diff

diff --git a/Include/Python.h b/Include/Python.h
index 2dd8290..aab5810 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -41,6 +41,12 @@
#include <stddef.h>
#endif
+/* p4a log redirect */
+#include <jni.h>
+#include "android/log.h"
+#define LOG(x) __android_log_write(ANDROID_LOG_INFO, "python", (x))
+
+
/* CAUTION: Build setups should ensure that NDEBUG is defined on the
* compiler command line when building Python in release mode; else
* assert() calls won't be removed.
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 9bb3666..4fb89c5 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1758,13 +1758,14 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
PyVarObject *op;
if (nitems < 0) {
+ LOG("PyErr_BadInternalCall in gc");
PyErr_BadInternalCall();
return NULL;
}
size = _PyObject_VAR_SIZE(tp, nitems);
op = (PyVarObject *) _PyObject_GC_Malloc(size);
if (op != NULL)
- op = PyObject_INIT_VAR(op, tp, nitems);
+ op = PyObject_INIT_VAR(op, tp, nitems);
return op;
}
diff --git a/Modules/getpath.c b/Modules/getpath.c
index c057737..5d02f08 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -866,6 +866,7 @@ wchar_t *
Py_GetProgramFullPath(void)
{
if (!module_search_path)
+ LOG("Py_GetProgramFullPath: calculating path");
calculate_path();
return progpath;
}
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 05b7679..be38e75 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -77,6 +77,7 @@ PyFloat_GetInfo(void)
floatinfo = PyStructSequence_New(&FloatInfoType);
if (floatinfo == NULL) {
+ LOG("PyFloat_GetInfo got NULL");
return NULL;
}
@@ -84,22 +85,63 @@ PyFloat_GetInfo(void)
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
#define SetDblFlag(flag) \
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
+
+ LOG("About to start typing to set int and dbl flags");
+ if (PyErr_Occurred()) {
+ LOG("err even before 1!");
+ } else {
+ LOG("no err before this");
+ }
SetDblFlag(DBL_MAX);
+ if (PyErr_Occurred()) {
+ LOG("err 1");
+ }
SetIntFlag(DBL_MAX_EXP);
+ if (PyErr_Occurred()) {
+ LOG("err 2");
+ }
SetIntFlag(DBL_MAX_10_EXP);
+ if (PyErr_Occurred()) {
+ LOG("err 3");
+ }
SetDblFlag(DBL_MIN);
+ if (PyErr_Occurred()) {
+ LOG("err 4");
+ }
SetIntFlag(DBL_MIN_EXP);
+ if (PyErr_Occurred()) {
+ LOG("err 5");
+ }
SetIntFlag(DBL_MIN_10_EXP);
+ if (PyErr_Occurred()) {
+ LOG("err 6");
+ }
SetIntFlag(DBL_DIG);
+ if (PyErr_Occurred()) {
+ LOG("err 7");
+ }
SetIntFlag(DBL_MANT_DIG);
+ if (PyErr_Occurred()) {
+ LOG("err 8");
+ }
SetDblFlag(DBL_EPSILON);
+ if (PyErr_Occurred()) {
+ LOG("err 9");
+ }
SetIntFlag(FLT_RADIX);
+ if (PyErr_Occurred()) {
+ LOG("err 10");
+ }
SetIntFlag(FLT_ROUNDS);
+ if (PyErr_Occurred()) {
+ LOG("err 11");
+ }
#undef SetIntFlag
#undef SetDblFlag
if (PyErr_Occurred()) {
+ LOG("PyErr_Occurred in floatinfo stuff");
Py_CLEAR(floatinfo);
return NULL;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d9c131c..0840930 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2297,6 +2297,12 @@ PyUnicode_AsUCS4Copy(PyObject *string)
PyObject *
PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
{
+ if (PyErr_Occurred()) {
+ LOG("PyErr already occurred before PyUnicode_FromWideChar does anything");
+ } else {
+ LOG("start of PyUnicode_FromWideChar; everything seems fine");
+ }
+
if (w == NULL) {
if (size == 0)
_Py_RETURN_UNICODE_EMPTY();
diff --git a/Python/errors.c b/Python/errors.c
index 996292a..20bc3f1 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -755,6 +755,9 @@ PyErr_Format(PyObject *exception, const char *format, ...)
{
va_list vargs;
PyObject* string;
+
+ LOG("PyErr Format with:");
+ LOG(format);
#ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, format);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0327830..e4428d0 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -415,6 +415,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
/* initialize builtin exceptions */
_PyExc_Init(bimod);
+ LOG("Got to _PySys_Init");
sysmod = _PySys_Init();
if (sysmod == NULL)
Py_FatalError("Py_Initialize: can't initialize sys");
@@ -2594,6 +2595,8 @@ Py_FatalError(const char *msg)
{
const int fd = fileno(stderr);
PyThreadState *tstate;
+
+ LOG(msg);
fprintf(stderr, "Fatal Python error: %s\n", msg);
fflush(stderr); /* it helps in Windows debug build */
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 39fe53f..d76c793 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1633,27 +1633,36 @@ _PySys_Init(void)
int res;
m = PyModule_Create(&sysmodule);
- if (m == NULL)
+ if (m == NULL) {
+ LOG("module create is NULL");
return NULL;
+ }
sysdict = PyModule_GetDict(m);
#define SET_SYS_FROM_STRING_BORROW(key, value) \
do { \
PyObject *v = (value); \
- if (v == NULL) \
+ if (v == NULL) { \
+ LOG("set from string 1 is NULL"); \
return NULL; \
+ } \
res = PyDict_SetItemString(sysdict, key, v); \
if (res < 0) { \
+ LOG("_SetItemString thing was NULL"); \
return NULL; \
} \
} while (0)
#define SET_SYS_FROM_STRING(key, value) \
do { \
PyObject *v = (value); \
- if (v == NULL) \
+ if (v == NULL) { \
+ LOG("set from string 2 is NULL"); \
+ LOG(key); \
return NULL; \
+ } \
res = PyDict_SetItemString(sysdict, key, v); \
Py_DECREF(v); \
if (res < 0) { \
+ LOG("_SetItemString 2 thing was NULL"); \
return NULL; \
} \
} while (0)
@@ -1677,47 +1686,102 @@ _PySys_Init(void)
#endif
/* stdin/stdout/stderr are now set by pythonrun.c */
+
+ if (PyErr_Occurred()) {
+ LOG("PyErr_Occurred before set_sys_from_string stuff");
+ } else {
+ LOG("PyErr has *NOT* yet occurred before set_sys_from_string stuff");
+ }
SET_SYS_FROM_STRING_BORROW("__displayhook__",
PyDict_GetItemString(sysdict, "displayhook"));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after __displayhook__");
+ }
SET_SYS_FROM_STRING_BORROW("__excepthook__",
PyDict_GetItemString(sysdict, "excepthook"));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after __excepthook__");
+ }
SET_SYS_FROM_STRING("version",
PyUnicode_FromString(Py_GetVersion()));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after __excepthook__");
+ }
SET_SYS_FROM_STRING("hexversion",
PyLong_FromLong(PY_VERSION_HEX));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after hexversion");
+ }
SET_SYS_FROM_STRING("_mercurial",
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
_Py_hgversion()));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after _mercurial");
+ }
SET_SYS_FROM_STRING("dont_write_bytecode",
PyBool_FromLong(Py_DontWriteBytecodeFlag));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after dont_write_bytecode");
+ }
SET_SYS_FROM_STRING("api_version",
PyLong_FromLong(PYTHON_API_VERSION));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after api_version");
+ }
SET_SYS_FROM_STRING("copyright",
PyUnicode_FromString(Py_GetCopyright()));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after copyright");
+ }
SET_SYS_FROM_STRING("platform",
PyUnicode_FromString(Py_GetPlatform()));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after platform");
+ } else {
+ LOG("No PyErr yet, about to do executable");
+ }
SET_SYS_FROM_STRING("executable",
PyUnicode_FromWideChar(
Py_GetProgramFullPath(), -1));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after executable");
+ }
SET_SYS_FROM_STRING("prefix",
PyUnicode_FromWideChar(Py_GetPrefix(), -1));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after prefix");
+ }
SET_SYS_FROM_STRING("exec_prefix",
PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after exec_prefix");
+ }
SET_SYS_FROM_STRING("base_prefix",
PyUnicode_FromWideChar(Py_GetPrefix(), -1));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after base_prefix");
+ }
SET_SYS_FROM_STRING("base_exec_prefix",
PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
+ if (PyErr_Occurred()) {
+ LOG("PyErr after base_exec_prefix");
+ }
SET_SYS_FROM_STRING("maxsize",
PyLong_FromSsize_t(PY_SSIZE_T_MAX));
+ if (PyErr_Occurred()) {
+ LOG("PyErr_Occurred before float_info stuff");
+ }
SET_SYS_FROM_STRING("float_info",
PyFloat_GetInfo());
SET_SYS_FROM_STRING("int_info",
PyLong_GetInfo());
/* initialize hash_info */
if (Hash_InfoType.tp_name == NULL) {
- if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0)
+ if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) {
+ LOG("InitType2 thing was NULL");
return NULL;
+ }
}
SET_SYS_FROM_STRING("hash_info",
get_hash_info());
@@ -1745,8 +1809,10 @@ _PySys_Init(void)
#endif
if (warnoptions == NULL) {
warnoptions = PyList_New(0);
- if (warnoptions == NULL)
+ if (warnoptions == NULL) {
+ LOG("warnoptions is NULL");
return NULL;
+ }
}
else {
Py_INCREF(warnoptions);
@@ -1758,8 +1824,10 @@ _PySys_Init(void)
/* version_info */
if (VersionInfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&VersionInfoType,
- &version_info_desc) < 0)
+ &version_info_desc) < 0) {
+ LOG("versioninfo stuff is NULL");
return NULL;
+ }
}
version_info = make_version_info();
SET_SYS_FROM_STRING("version_info", version_info);
@@ -1775,8 +1843,10 @@ _PySys_Init(void)
/* flags */
if (FlagsType.tp_name == 0) {
- if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0)
+ if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0) {
+ LOG("flags stuff is NULL");
return NULL;
+ }
}
SET_SYS_FROM_STRING("flags", make_flags());
/* prevent user from creating new instances */
@@ -1790,8 +1860,10 @@ _PySys_Init(void)
/* getwindowsversion */
if (WindowsVersionType.tp_name == 0)
if (PyStructSequence_InitType2(&WindowsVersionType,
- &windows_version_desc) < 0)
+ &windows_version_desc) < 0) {
+ LOG("Windows version is NULL");
return NULL;
+ }
/* prevent user from creating new instances */
WindowsVersionType.tp_init = NULL;
WindowsVersionType.tp_new = NULL;
@@ -1815,8 +1887,10 @@ _PySys_Init(void)
#undef SET_SYS_FROM_STRING
#undef SET_SYS_FROM_STRING_BORROW
- if (PyErr_Occurred())
+if (PyErr_Occurred()) {
+ LOG("PyErr_Occurred to NULL");
return NULL;
+ }
return m;
}