Skip to content

Commit 45003e0

Browse files
committed
Added more python3 failure logging
1 parent 63bcbd0 commit 45003e0

File tree

1 file changed

+370
-11
lines changed

1 file changed

+370
-11
lines changed
Lines changed: 370 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,385 @@
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
1+
diff --git a/Include/Python.h b/Include/Python.h
2+
index 2dd8290..aab5810 100644
3+
--- a/Include/Python.h
4+
+++ b/Include/Python.h
5+
@@ -41,6 +41,12 @@
6+
#include <stddef.h>
77
#endif
88

99
+/* p4a log redirect */
1010
+#include <jni.h>
1111
+#include "android/log.h"
1212
+#define LOG(x) __android_log_write(ANDROID_LOG_INFO, "python", (x))
1313
+
14-
_Py_IDENTIFIER(builtins);
15-
_Py_IDENTIFIER(excepthook);
16-
_Py_IDENTIFIER(flush);
17-
@@ -2594,6 +2599,9 @@ Py_FatalError(const char *msg)
14+
+
15+
/* CAUTION: Build setups should ensure that NDEBUG is defined on the
16+
* compiler command line when building Python in release mode; else
17+
* assert() calls won't be removed.
18+
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
19+
index 9bb3666..4fb89c5 100644
20+
--- a/Modules/gcmodule.c
21+
+++ b/Modules/gcmodule.c
22+
@@ -1758,13 +1758,14 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
23+
PyVarObject *op;
24+
25+
if (nitems < 0) {
26+
+ LOG("PyErr_BadInternalCall in gc");
27+
PyErr_BadInternalCall();
28+
return NULL;
29+
}
30+
size = _PyObject_VAR_SIZE(tp, nitems);
31+
op = (PyVarObject *) _PyObject_GC_Malloc(size);
32+
if (op != NULL)
33+
- op = PyObject_INIT_VAR(op, tp, nitems);
34+
+ op = PyObject_INIT_VAR(op, tp, nitems);
35+
return op;
36+
}
37+
38+
diff --git a/Modules/getpath.c b/Modules/getpath.c
39+
index c057737..5d02f08 100644
40+
--- a/Modules/getpath.c
41+
+++ b/Modules/getpath.c
42+
@@ -866,6 +866,7 @@ wchar_t *
43+
Py_GetProgramFullPath(void)
44+
{
45+
if (!module_search_path)
46+
+ LOG("Py_GetProgramFullPath: calculating path");
47+
calculate_path();
48+
return progpath;
49+
}
50+
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
51+
index 05b7679..be38e75 100644
52+
--- a/Objects/floatobject.c
53+
+++ b/Objects/floatobject.c
54+
@@ -77,6 +77,7 @@ PyFloat_GetInfo(void)
55+
56+
floatinfo = PyStructSequence_New(&FloatInfoType);
57+
if (floatinfo == NULL) {
58+
+ LOG("PyFloat_GetInfo got NULL");
59+
return NULL;
60+
}
61+
62+
@@ -84,22 +85,63 @@ PyFloat_GetInfo(void)
63+
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
64+
#define SetDblFlag(flag) \
65+
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
66+
+
67+
+ LOG("About to start typing to set int and dbl flags");
68+
+ if (PyErr_Occurred()) {
69+
+ LOG("err even before 1!");
70+
+ } else {
71+
+ LOG("no err before this");
72+
+ }
73+
74+
SetDblFlag(DBL_MAX);
75+
+ if (PyErr_Occurred()) {
76+
+ LOG("err 1");
77+
+ }
78+
SetIntFlag(DBL_MAX_EXP);
79+
+ if (PyErr_Occurred()) {
80+
+ LOG("err 2");
81+
+ }
82+
SetIntFlag(DBL_MAX_10_EXP);
83+
+ if (PyErr_Occurred()) {
84+
+ LOG("err 3");
85+
+ }
86+
SetDblFlag(DBL_MIN);
87+
+ if (PyErr_Occurred()) {
88+
+ LOG("err 4");
89+
+ }
90+
SetIntFlag(DBL_MIN_EXP);
91+
+ if (PyErr_Occurred()) {
92+
+ LOG("err 5");
93+
+ }
94+
SetIntFlag(DBL_MIN_10_EXP);
95+
+ if (PyErr_Occurred()) {
96+
+ LOG("err 6");
97+
+ }
98+
SetIntFlag(DBL_DIG);
99+
+ if (PyErr_Occurred()) {
100+
+ LOG("err 7");
101+
+ }
102+
SetIntFlag(DBL_MANT_DIG);
103+
+ if (PyErr_Occurred()) {
104+
+ LOG("err 8");
105+
+ }
106+
SetDblFlag(DBL_EPSILON);
107+
+ if (PyErr_Occurred()) {
108+
+ LOG("err 9");
109+
+ }
110+
SetIntFlag(FLT_RADIX);
111+
+ if (PyErr_Occurred()) {
112+
+ LOG("err 10");
113+
+ }
114+
SetIntFlag(FLT_ROUNDS);
115+
+ if (PyErr_Occurred()) {
116+
+ LOG("err 11");
117+
+ }
118+
#undef SetIntFlag
119+
#undef SetDblFlag
120+
121+
if (PyErr_Occurred()) {
122+
+ LOG("PyErr_Occurred in floatinfo stuff");
123+
Py_CLEAR(floatinfo);
124+
return NULL;
125+
}
126+
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
127+
index d9c131c..0840930 100644
128+
--- a/Objects/unicodeobject.c
129+
+++ b/Objects/unicodeobject.c
130+
@@ -2297,6 +2297,12 @@ PyUnicode_AsUCS4Copy(PyObject *string)
131+
PyObject *
132+
PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
133+
{
134+
+ if (PyErr_Occurred()) {
135+
+ LOG("PyErr already occurred before PyUnicode_FromWideChar does anything");
136+
+ } else {
137+
+ LOG("start of PyUnicode_FromWideChar; everything seems fine");
138+
+ }
139+
+
140+
if (w == NULL) {
141+
if (size == 0)
142+
_Py_RETURN_UNICODE_EMPTY();
143+
diff --git a/Python/errors.c b/Python/errors.c
144+
index 996292a..20bc3f1 100644
145+
--- a/Python/errors.c
146+
+++ b/Python/errors.c
147+
@@ -755,6 +755,9 @@ PyErr_Format(PyObject *exception, const char *format, ...)
148+
{
149+
va_list vargs;
150+
PyObject* string;
151+
+
152+
+ LOG("PyErr Format with:");
153+
+ LOG(format);
154+
155+
#ifdef HAVE_STDARG_PROTOTYPES
156+
va_start(vargs, format);
157+
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
158+
index 0327830..e4428d0 100644
159+
--- a/Python/pythonrun.c
160+
+++ b/Python/pythonrun.c
161+
@@ -415,6 +415,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
162+
/* initialize builtin exceptions */
163+
_PyExc_Init(bimod);
164+
165+
+ LOG("Got to _PySys_Init");
166+
sysmod = _PySys_Init();
167+
if (sysmod == NULL)
168+
Py_FatalError("Py_Initialize: can't initialize sys");
169+
@@ -2594,6 +2595,8 @@ Py_FatalError(const char *msg)
18170
{
19171
const int fd = fileno(stderr);
20172
PyThreadState *tstate;
21173
+
22-
+ LOG("Py_FatalError called!");
23174
+ LOG(msg);
24175

25176
fprintf(stderr, "Fatal Python error: %s\n", msg);
26177
fflush(stderr); /* it helps in Windows debug build */
178+
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
179+
index 39fe53f..d76c793 100644
180+
--- a/Python/sysmodule.c
181+
+++ b/Python/sysmodule.c
182+
@@ -1633,27 +1633,36 @@ _PySys_Init(void)
183+
int res;
184+
185+
m = PyModule_Create(&sysmodule);
186+
- if (m == NULL)
187+
+ if (m == NULL) {
188+
+ LOG("module create is NULL");
189+
return NULL;
190+
+ }
191+
sysdict = PyModule_GetDict(m);
192+
#define SET_SYS_FROM_STRING_BORROW(key, value) \
193+
do { \
194+
PyObject *v = (value); \
195+
- if (v == NULL) \
196+
+ if (v == NULL) { \
197+
+ LOG("set from string 1 is NULL"); \
198+
return NULL; \
199+
+ } \
200+
res = PyDict_SetItemString(sysdict, key, v); \
201+
if (res < 0) { \
202+
+ LOG("_SetItemString thing was NULL"); \
203+
return NULL; \
204+
} \
205+
} while (0)
206+
#define SET_SYS_FROM_STRING(key, value) \
207+
do { \
208+
PyObject *v = (value); \
209+
- if (v == NULL) \
210+
+ if (v == NULL) { \
211+
+ LOG("set from string 2 is NULL"); \
212+
+ LOG(key); \
213+
return NULL; \
214+
+ } \
215+
res = PyDict_SetItemString(sysdict, key, v); \
216+
Py_DECREF(v); \
217+
if (res < 0) { \
218+
+ LOG("_SetItemString 2 thing was NULL"); \
219+
return NULL; \
220+
} \
221+
} while (0)
222+
@@ -1677,47 +1686,102 @@ _PySys_Init(void)
223+
#endif
224+
225+
/* stdin/stdout/stderr are now set by pythonrun.c */
226+
+
227+
+ if (PyErr_Occurred()) {
228+
+ LOG("PyErr_Occurred before set_sys_from_string stuff");
229+
+ } else {
230+
+ LOG("PyErr has *NOT* yet occurred before set_sys_from_string stuff");
231+
+ }
232+
233+
SET_SYS_FROM_STRING_BORROW("__displayhook__",
234+
PyDict_GetItemString(sysdict, "displayhook"));
235+
+ if (PyErr_Occurred()) {
236+
+ LOG("PyErr after __displayhook__");
237+
+ }
238+
SET_SYS_FROM_STRING_BORROW("__excepthook__",
239+
PyDict_GetItemString(sysdict, "excepthook"));
240+
+ if (PyErr_Occurred()) {
241+
+ LOG("PyErr after __excepthook__");
242+
+ }
243+
SET_SYS_FROM_STRING("version",
244+
PyUnicode_FromString(Py_GetVersion()));
245+
+ if (PyErr_Occurred()) {
246+
+ LOG("PyErr after __excepthook__");
247+
+ }
248+
SET_SYS_FROM_STRING("hexversion",
249+
PyLong_FromLong(PY_VERSION_HEX));
250+
+ if (PyErr_Occurred()) {
251+
+ LOG("PyErr after hexversion");
252+
+ }
253+
SET_SYS_FROM_STRING("_mercurial",
254+
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
255+
_Py_hgversion()));
256+
+ if (PyErr_Occurred()) {
257+
+ LOG("PyErr after _mercurial");
258+
+ }
259+
SET_SYS_FROM_STRING("dont_write_bytecode",
260+
PyBool_FromLong(Py_DontWriteBytecodeFlag));
261+
+ if (PyErr_Occurred()) {
262+
+ LOG("PyErr after dont_write_bytecode");
263+
+ }
264+
SET_SYS_FROM_STRING("api_version",
265+
PyLong_FromLong(PYTHON_API_VERSION));
266+
+ if (PyErr_Occurred()) {
267+
+ LOG("PyErr after api_version");
268+
+ }
269+
SET_SYS_FROM_STRING("copyright",
270+
PyUnicode_FromString(Py_GetCopyright()));
271+
+ if (PyErr_Occurred()) {
272+
+ LOG("PyErr after copyright");
273+
+ }
274+
SET_SYS_FROM_STRING("platform",
275+
PyUnicode_FromString(Py_GetPlatform()));
276+
+ if (PyErr_Occurred()) {
277+
+ LOG("PyErr after platform");
278+
+ } else {
279+
+ LOG("No PyErr yet, about to do executable");
280+
+ }
281+
SET_SYS_FROM_STRING("executable",
282+
PyUnicode_FromWideChar(
283+
Py_GetProgramFullPath(), -1));
284+
+ if (PyErr_Occurred()) {
285+
+ LOG("PyErr after executable");
286+
+ }
287+
SET_SYS_FROM_STRING("prefix",
288+
PyUnicode_FromWideChar(Py_GetPrefix(), -1));
289+
+ if (PyErr_Occurred()) {
290+
+ LOG("PyErr after prefix");
291+
+ }
292+
SET_SYS_FROM_STRING("exec_prefix",
293+
PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
294+
+ if (PyErr_Occurred()) {
295+
+ LOG("PyErr after exec_prefix");
296+
+ }
297+
SET_SYS_FROM_STRING("base_prefix",
298+
PyUnicode_FromWideChar(Py_GetPrefix(), -1));
299+
+ if (PyErr_Occurred()) {
300+
+ LOG("PyErr after base_prefix");
301+
+ }
302+
SET_SYS_FROM_STRING("base_exec_prefix",
303+
PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
304+
+ if (PyErr_Occurred()) {
305+
+ LOG("PyErr after base_exec_prefix");
306+
+ }
307+
SET_SYS_FROM_STRING("maxsize",
308+
PyLong_FromSsize_t(PY_SSIZE_T_MAX));
309+
+ if (PyErr_Occurred()) {
310+
+ LOG("PyErr_Occurred before float_info stuff");
311+
+ }
312+
SET_SYS_FROM_STRING("float_info",
313+
PyFloat_GetInfo());
314+
SET_SYS_FROM_STRING("int_info",
315+
PyLong_GetInfo());
316+
/* initialize hash_info */
317+
if (Hash_InfoType.tp_name == NULL) {
318+
- if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0)
319+
+ if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) {
320+
+ LOG("InitType2 thing was NULL");
321+
return NULL;
322+
+ }
323+
}
324+
SET_SYS_FROM_STRING("hash_info",
325+
get_hash_info());
326+
@@ -1745,8 +1809,10 @@ _PySys_Init(void)
327+
#endif
328+
if (warnoptions == NULL) {
329+
warnoptions = PyList_New(0);
330+
- if (warnoptions == NULL)
331+
+ if (warnoptions == NULL) {
332+
+ LOG("warnoptions is NULL");
333+
return NULL;
334+
+ }
335+
}
336+
else {
337+
Py_INCREF(warnoptions);
338+
@@ -1758,8 +1824,10 @@ _PySys_Init(void)
339+
/* version_info */
340+
if (VersionInfoType.tp_name == NULL) {
341+
if (PyStructSequence_InitType2(&VersionInfoType,
342+
- &version_info_desc) < 0)
343+
+ &version_info_desc) < 0) {
344+
+ LOG("versioninfo stuff is NULL");
345+
return NULL;
346+
+ }
347+
}
348+
version_info = make_version_info();
349+
SET_SYS_FROM_STRING("version_info", version_info);
350+
@@ -1775,8 +1843,10 @@ _PySys_Init(void)
351+
352+
/* flags */
353+
if (FlagsType.tp_name == 0) {
354+
- if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0)
355+
+ if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0) {
356+
+ LOG("flags stuff is NULL");
357+
return NULL;
358+
+ }
359+
}
360+
SET_SYS_FROM_STRING("flags", make_flags());
361+
/* prevent user from creating new instances */
362+
@@ -1790,8 +1860,10 @@ _PySys_Init(void)
363+
/* getwindowsversion */
364+
if (WindowsVersionType.tp_name == 0)
365+
if (PyStructSequence_InitType2(&WindowsVersionType,
366+
- &windows_version_desc) < 0)
367+
+ &windows_version_desc) < 0) {
368+
+ LOG("Windows version is NULL");
369+
return NULL;
370+
+ }
371+
/* prevent user from creating new instances */
372+
WindowsVersionType.tp_init = NULL;
373+
WindowsVersionType.tp_new = NULL;
374+
@@ -1815,8 +1887,10 @@ _PySys_Init(void)
375+
376+
#undef SET_SYS_FROM_STRING
377+
#undef SET_SYS_FROM_STRING_BORROW
378+
- if (PyErr_Occurred())
379+
+if (PyErr_Occurred()) {
380+
+ LOG("PyErr_Occurred to NULL");
381+
return NULL;
382+
+ }
383+
return m;
384+
}
385+

0 commit comments

Comments
 (0)