Author: Armin Rigo <[email protected]>
Branch: py3k-faulthandler
Changeset: r87360:48111b3e0633
Date: 2016-09-24 15:06 +0200
http://bitbucket.org/pypy/pypy/changeset/48111b3e0633/
Log: tweaks, in-progress
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -518,6 +518,11 @@
sys._xoptions = dict(x.split('=', 1) if '=' in x else (x, True)
for x in options['_xoptions'])
+ if 'faulthandler' in sys.builtin_module_names:
+ if 'faulthandler' in sys._xoptions or os.getenv('PYTHONFAULTHANDLER'):
+ import faulthandler
+ faulthandler.enable(2) # manually set to stderr
+
## if not we_are_translated():
## for key in sorted(options):
## print '%40s: %s' % (key, options[key])
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -422,11 +422,6 @@
# To be called before using the space
self.threadlocals.enter_thread(self)
- # Set up faulthandler even if not imported explicitly
- if self.config.objspace.usemodules.faulthandler:
- from pypy.module.faulthandler import handler
- handler.startup(self)
-
# Initialize already imported builtin modules
from pypy.interpreter.module import Module
w_modules = self.sys.get('modules')
@@ -450,11 +445,6 @@
for w_mod in self.builtin_modules.values():
if isinstance(w_mod, Module) and w_mod.startup_called:
w_mod.shutdown(self)
- #
- # Shut down faulthandler
- if self.config.objspace.usemodules.faulthandler:
- from pypy.module.faulthandler import handler
- handler.finish(self)
def wait_for_thread_shutdown(self):
"""Wait until threading._shutdown() completes, provided the threading
diff --git a/pypy/module/faulthandler/__init__.py
b/pypy/module/faulthandler/__init__.py
--- a/pypy/module/faulthandler/__init__.py
+++ b/pypy/module/faulthandler/__init__.py
@@ -16,4 +16,10 @@
'_sigsegv': 'handler.sigsegv',
'_sigfpe': 'handler.sigfpe',
'_sigabrt': 'handler.sigabrt',
+ '_stack_overflow': 'handler.stack_overflow',
}
+
+ def shutdown(self, space):
+ from pypy.module.faulthandler import handler
+ handler.finish(space)
+ MixedModule.shutdown(self, space)
diff --git a/pypy/module/faulthandler/cintf.py
b/pypy/module/faulthandler/cintf.py
--- a/pypy/module/faulthandler/cintf.py
+++ b/pypy/module/faulthandler/cintf.py
@@ -62,3 +62,6 @@
pypy_faulthandler_sigabrt = direct_llexternal(
'pypy_faulthandler_sigabrt', [], lltype.Void)
+
+pypy_faulthandler_stackoverflow = direct_llexternal(
+ 'pypy_faulthandler_stackoverflow', [lltype.Float], lltype.Float)
diff --git a/pypy/module/faulthandler/faulthandler.c
b/pypy/module/faulthandler/faulthandler.c
--- a/pypy/module/faulthandler/faulthandler.c
+++ b/pypy/module/faulthandler/faulthandler.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/resource.h>
+#include <math.h>
typedef struct sigaction _Py_sighandler_t;
@@ -329,3 +330,19 @@
faulthandler_suppress_crash_report();
abort();
}
+
+static double fh_stack_overflow(double levels)
+{
+ if (levels > 2.5) {
+ return (sqrt(fh_stack_overflow(levels - 1.0))
+ + fh_stack_overflow(levels * 1e-10));
+ }
+ return 1e100 + levels;
+}
+
+RPY_EXTERN
+double pypy_faulthandler_stackoverflow(double levels)
+{
+ faulthandler_suppress_crash_report();
+ return fh_stack_overflow(levels);
+}
diff --git a/pypy/module/faulthandler/faulthandler.h
b/pypy/module/faulthandler/faulthandler.h
--- a/pypy/module/faulthandler/faulthandler.h
+++ b/pypy/module/faulthandler/faulthandler.h
@@ -21,6 +21,7 @@
RPY_EXTERN void pypy_faulthandler_sigsegv(void);
RPY_EXTERN int pypy_faulthandler_sigfpe(void);
RPY_EXTERN void pypy_faulthandler_sigabrt(void);
+RPY_EXTERN double pypy_faulthandler_stackoverflow(double);
#endif /* PYPY_FAULTHANDLER_H */
diff --git a/pypy/module/faulthandler/handler.py
b/pypy/module/faulthandler/handler.py
--- a/pypy/module/faulthandler/handler.py
+++ b/pypy/module/faulthandler/handler.py
@@ -79,28 +79,8 @@
self._cleanup_()
-def startup(space):
- """Initialize the faulthandler logic when the space is starting
- (this is called from baseobjspace.py)"""
- #
- # Call faulthandler.enable() if the PYTHONFAULTHANDLER environment variable
- # is defined, or if sys._xoptions has a 'faulthandler' key.
- if not os.environ.get('PYTHONFAULTHANDLER'):
- w_options = space.sys.get('_xoptions')
- if not space.is_true(space.contains(w_options,
- space.wrap('faulthandler'))):
- return
- #
- # Like CPython. Why not just call enable(space)? Maybe someone
- # mis-uses ``"faulthandler" in sys.modules'' as a way to check if it
- # was started by checking if it was imported at all.
- space.appexec([], """():
- import faulthandler
- faulthandler.enable()
- """)
-
def finish(space):
- """Finalize the faulthandler logic (called from baseobjspace.py)"""
+ "Finalize the faulthandler logic (called from shutdown())"
space.fromcache(Handler).finish()
@@ -144,3 +124,8 @@
def sigabrt(space):
cintf.pypy_faulthandler_sigabrt()
+
+@unwrap_spec(levels=int)
+def stack_overflow(space, levels=100000000):
+ levels = float(levels)
+ return space.wrap(cintf.pypy_faulthandler_stackoverflow(levels))
diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -159,4 +159,4 @@
# faulthandler support
def get_rvmprof_stack():
- return vmprof_tl_stack.getraw()
+ return vmprof_tl_stack.get_or_make_raw()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit