Author: Armin Rigo <[email protected]>
Branch: py3k-faulthandler
Changeset: r87359:f16ac9a03e25
Date: 2016-09-24 10:56 +0200
http://bitbucket.org/pypy/pypy/changeset/f16ac9a03e25/
Log: Add some more of the test functions
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
@@ -13,10 +13,7 @@
'dump_traceback': 'handler.dump_traceback',
#
'_read_null': 'handler.read_null',
-# '_sigsegv': 'interp_faulthandler.sigsegv',
-# '_sigfpe': 'interp_faulthandler.sigfpe',
-# '_sigabrt': 'interp_faulthandler.sigabrt',
-# #'_sigbus': 'interp_faulthandler.sigbus',
-# #'_sigill': 'interp_faulthandler.sigill',
-# '_fatal_error': 'interp_faulthandler.fatal_error',
+ '_sigsegv': 'handler.sigsegv',
+ '_sigfpe': 'handler.sigfpe',
+ '_sigabrt': 'handler.sigabrt',
}
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
@@ -49,3 +49,16 @@
pypy_faulthandler_read_null_releasegil = direct_llexternal(
'pypy_faulthandler_read_null', [], lltype.Void,
_nowrapper=False, releasegil=True)
+
+pypy_faulthandler_sigsegv = direct_llexternal(
+ 'pypy_faulthandler_sigsegv', [], lltype.Void)
+
+pypy_faulthandler_sigsegv_releasegil = direct_llexternal(
+ 'pypy_faulthandler_sigsegv', [], lltype.Void,
+ _nowrapper=False, releasegil=True)
+
+pypy_faulthandler_sigfpe = direct_llexternal(
+ 'pypy_faulthandler_sigfpe', [], lltype.Void)
+
+pypy_faulthandler_sigabrt = direct_llexternal(
+ 'pypy_faulthandler_sigabrt', [], lltype.Void)
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
@@ -6,6 +6,7 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <sys/resource.h>
typedef struct sigaction _Py_sighandler_t;
@@ -245,19 +246,48 @@
/* for tests... */
+static void
+faulthandler_suppress_crash_report(void)
+{
+#ifdef MS_WINDOWS
+ UINT mode;
+
+ /* Configure Windows to not display the Windows Error Reporting dialog */
+ mode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
+ SetErrorMode(mode | SEM_NOGPFAULTERRORBOX);
+#endif
+
+#ifndef MS_WINDOWS
+ struct rlimit rl;
+
+ /* Disable creation of core dump */
+ if (getrlimit(RLIMIT_CORE, &rl) != 0) {
+ rl.rlim_cur = 0;
+ setrlimit(RLIMIT_CORE, &rl);
+ }
+#endif
+
+#ifdef _MSC_VER
+ /* Visual Studio: configure abort() to not display an error message nor
+ open a popup asking to report the fault. */
+ _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
+#endif
+}
+
RPY_EXTERN
int pypy_faulthandler_read_null(void)
{
int *volatile x;
+ faulthandler_suppress_crash_report();
x = NULL;
return *x;
}
-#if 0
-void
-pypy_faulthandler_sigsegv(void)
+RPY_EXTERN
+void pypy_faulthandler_sigsegv(void)
{
+ faulthandler_suppress_crash_report();
#if defined(MS_WINDOWS)
/* For SIGSEGV, faulthandler_fatal_error() restores the previous signal
handler and then gives back the execution flow to the program (without
@@ -277,12 +307,13 @@
#endif
}
-int
-pypy_faulthandler_sigfpe(void)
+RPY_EXTERN
+int pypy_faulthandler_sigfpe(void)
{
/* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
PowerPC. Use volatile to disable compile-time optimizations. */
volatile int x = 1, y = 0, z;
+ faulthandler_suppress_crash_report();
z = x / y;
/* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
raise it manually. */
@@ -292,30 +323,9 @@
return z;
}
-void
-pypy_faulthandler_sigabrt()
+RPY_EXTERN
+void pypy_faulthandler_sigabrt(void)
{
-#ifdef _MSC_VER
- /* Visual Studio: configure abort() to not display an error message nor
- open a popup asking to report the fault. */
- _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
-#endif
+ faulthandler_suppress_crash_report();
abort();
}
-
-#ifdef SIGBUS
-void
-pypy_faulthandler_sigbus(void)
-{
- raise(SIGBUS);
-}
-#endif
-
-#ifdef SIGILL
-void
-pypy_faulthandler_sigill(void)
-{
- raise(SIGILL);
-}
-#endif
-#endif
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
@@ -3,6 +3,7 @@
#include "src/precommondefs.h"
+
RPY_EXTERN char *pypy_faulthandler_setup(void dump_callback(void));
RPY_EXTERN void pypy_faulthandler_teardown(void);
@@ -17,17 +18,9 @@
RPY_EXTERN int pypy_faulthandler_read_null(void);
-/*
RPY_EXTERN void pypy_faulthandler_sigsegv(void);
RPY_EXTERN int pypy_faulthandler_sigfpe(void);
-RPY_EXTERN void pypy_faulthandler_sigabrt();
-#ifdef SIGBUS
-RPY_EXTERN void pypy_faulthandler_sigbus(void);
-#endif
+RPY_EXTERN void pypy_faulthandler_sigabrt(void);
-#ifdef SIGILL
-RPY_EXTERN void pypy_faulthandler_sigill(void);
-#endif
-*/
#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
@@ -47,12 +47,13 @@
pass # ignore flush() error
return fd, w_file
+ def setup(self):
+ dump_callback = llhelper(cintf.DUMP_CALLBACK, dumper._dump_callback)
+ self.check_err(cintf.pypy_faulthandler_setup(dump_callback))
+
def enable(self, w_file, all_threads):
fileno, w_file = self.get_fileno_and_file(w_file)
- #
- dump_callback = llhelper(cintf.DUMP_CALLBACK, dumper._dump_callback)
- self.check_err(cintf.pypy_faulthandler_setup(dump_callback))
- #
+ self.setup()
self.fatal_error_w_file = w_file
self.check_err(cintf.pypy_faulthandler_enable(
rffi.cast(rffi.INT, fileno),
@@ -67,10 +68,7 @@
def dump_traceback(self, w_file, all_threads):
fileno, w_file = self.get_fileno_and_file(w_file)
- #
- dump_callback = llhelper(cintf.DUMP_CALLBACK, dumper._dump_callback)
- self.check_err(cintf.pypy_faulthandler_setup(dump_callback))
- #
+ self.setup()
cintf.pypy_faulthandler_dump_traceback(
rffi.cast(rffi.INT, fileno),
rffi.cast(rffi.INT, all_threads))
@@ -127,9 +125,22 @@
# for tests...
-@unwrap_spec(release_gil=bool)
-def read_null(space, release_gil):
+@unwrap_spec(release_gil=int)
+def read_null(space, release_gil=0):
if release_gil:
cintf.pypy_faulthandler_read_null_releasegil()
else:
cintf.pypy_faulthandler_read_null()
+
+@unwrap_spec(release_gil=int)
+def sigsegv(space, release_gil=0):
+ if release_gil:
+ cintf.pypy_faulthandler_sigsegv_releasegil()
+ else:
+ cintf.pypy_faulthandler_sigsegv()
+
+def sigfpe(space):
+ cintf.pypy_faulthandler_sigfpe()
+
+def sigabrt(space):
+ cintf.pypy_faulthandler_sigabrt()
diff --git a/pypy/module/faulthandler/interp_faulthandler.py
b/pypy/module/faulthandler/interp_faulthandler.py
deleted file mode 100644
--- a/pypy/module/faulthandler/interp_faulthandler.py
+++ /dev/null
@@ -1,127 +0,0 @@
-import os
-import py
-
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.translator import cdir
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.interpreter.error import OperationError, oefmt
-
-MAX_NTHREADS = 100
-
-cwd = py.path.local(__file__).dirpath()
-eci = ExternalCompilationInfo(
- includes=[cwd.join('faulthandler.h')],
- include_dirs=[str(cwd), cdir],
- separate_module_files=[cwd.join('faulthandler.c')])
-
-def llexternal(*args, **kwargs):
- kwargs.setdefault('releasegil', False)
- kwargs.setdefault('compilation_info', eci)
- return rffi.llexternal(*args, **kwargs)
-
-pypy_faulthandler_read_null = llexternal(
- 'pypy_faulthandler_read_null', [], lltype.Void)
-pypy_faulthandler_read_null_nogil = llexternal(
- 'pypy_faulthandler_read_null', [], lltype.Void,
- releasegil=True)
-pypy_faulthandler_sigsegv = llexternal(
- 'pypy_faulthandler_sigsegv', [], lltype.Void)
-pypy_faulthandler_sigfpe = llexternal(
- 'pypy_faulthandler_sigfpe', [], lltype.Void)
-pypy_faulthandler_sigabrt = llexternal(
- 'pypy_faulthandler_sigabrt', [], lltype.Void)
-pypy_faulthandler_sigbus = llexternal(
- 'pypy_faulthandler_sigbus', [], lltype.Void)
-pypy_faulthandler_sigill = llexternal(
- 'pypy_faulthandler_sigill', [], lltype.Void)
-
-class FatalErrorState(object):
- def __init__(self, space):
- self.enabled = False
- self.all_threads = True
-
-@unwrap_spec(w_file=WrappedDefault(None),
- w_all_threads=WrappedDefault(True))
-def enable(space, w_file, w_all_threads):
- state = space.fromcache(FatalErrorState)
- state.enabled = True
- state.all_threads = bool(space.int_w(w_all_threads))
-
-def disable(space):
- state = space.fromcache(FatalErrorState)
- state.enabled = False
-
-def is_enabled(space):
- return space.wrap(space.fromcache(FatalErrorState).enabled)
-
-def register(space, __args__):
- pass
-
-
-@unwrap_spec(w_file=WrappedDefault(None),
- w_all_threads=WrappedDefault(True))
-def dump_traceback(space, w_file, w_all_threads):
- current_ec = space.getexecutioncontext()
- if space.int_w(w_all_threads):
- ecs = space.threadlocals.getallvalues()
- else:
- ecs = {0: current_ec}
-
- if space.is_none(w_file):
- w_file = space.sys.get('stderr')
- fd = space.c_filedescriptor_w(w_file)
-
- nthreads = 0
- for thread_ident, ec in ecs.items():
- if nthreads:
- os.write(fd, "\n")
- if nthreads >= MAX_NTHREADS:
- os.write(fd, "...\n")
- break
- if ec is current_ec:
- os.write(fd, "Current thread 0x%x:\n" % thread_ident)
- else:
- os.write(fd, "Thread 0x%x:\n" % thread_ident)
-
- frame = ec.gettopframe()
- while frame:
- code = frame.pycode
- lineno = frame.get_last_lineno()
- if code:
- os.write(fd, " File \"%s\", line %s in %s\n" % (
- code.co_filename, lineno, code.co_name))
- else:
- os.write(fd, " File ???, line %s in ???\n" % (
- lineno,))
-
- frame = frame.f_backref()
-
-
-@unwrap_spec(w_release_gil=WrappedDefault(False))
-def read_null(space, w_release_gil):
- if space.is_true(w_release_gil):
- pypy_faulthandler_read_null_nogil()
- else:
- pypy_faulthandler_read_null()
-
-def sigsegv():
- pypy_faulthandler_sigsegv()
-
-def sigfpe():
- pypy_faulthandler_sigfpe()
-
-def sigabrt():
- pypy_faulthandler_sigabrt()
-
-#def sigbus():
-# pypy_faulthandler_sigbus()
-
-#def sigill():
-# pypy_faulthandler_sigill()
-
-@unwrap_spec(msg=str)
-def fatal_error(space, msg):
- os.write(2, "Fatal Python error: %s\n" % msg);
- dump_traceback(space, space.wrap(None), space.wrap(True))
- raise RuntimeError(msg)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit