[Python-modules-commits] [cysignals] 02/05: Import cysignals_1.2.0+ds.orig.tar.xz
Jerome Benoit
calculus-guest at moszumanska.debian.org
Thu Oct 13 01:07:34 UTC 2016
This is an automated email from the git hooks/post-receive script.
calculus-guest pushed a commit to branch master
in repository cysignals.
commit 5e36981701849c5a6e552ff50e9163af52330d3a
Author: Jerome Benoit <calculus at rezozer.net>
Date: Thu Oct 13 00:53:21 2016 +0100
Import cysignals_1.2.0+ds.orig.tar.xz
---
PKG-INFO | 2 +-
VERSION | 2 +-
configure.ac | 11 ++-
example/cysignals_example.pyx | 1 +
setup.py | 3 +-
src/cysignals/{debug.h => debug.h.in} | 4 +-
src/cysignals/implementation.c | 26 ++++---
src/cysignals/macros.h | 10 ++-
src/cysignals/signals.pyx | 27 +++++++
src/cysignals/tests.pyx | 10 ++-
src/cysignals/tests_helper.c | 8 +--
src/scripts/cysignals-CSI | 130 +++++++++++++++++++---------------
src/scripts/cysignals-CSI-helper.py | 11 +--
13 files changed, 158 insertions(+), 87 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 946e50e..652d61c 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: cysignals
-Version: 1.1.1
+Version: 1.2.0
Summary: Interrupt and signal handling for Cython
Home-page: https://github.com/sagemath/cysignals
Author: Martin R. Albrecht, François Bissey, Volker Braun, Jeroen Demeyer
diff --git a/VERSION b/VERSION
index 524cb55..26aaba0 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.1
+1.2.0
diff --git a/configure.ac b/configure.ac
index 6cfaa0f..20cd006 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,9 +5,16 @@ AC_PREREQ([2.69])
AC_DEFUN([VERSION], m4_esyscmd_s(cat VERSION))
AC_INIT([cysignals], VERSION, [https://github.com/sagemath/cysignals/issues])
-AC_COPYRIGHT([GPL version 2 or later])
+AC_COPYRIGHT([GNU Lesser General Public License version 3 or later])
AC_CONFIG_SRCDIR([configure.ac])
-AC_CONFIG_HEADERS([build/src/config.h:src/config.h.in])
+AC_CONFIG_HEADERS([build/src/config.h:src/config.h.in build/src/cysignals/debug.h:src/cysignals/debug.h.in])
+
+AC_ARG_ENABLE(debug,
+ AS_HELP_STRING([--enable-debug], [enable debug output]))
+
+if test "$enable_debug" = yes; then
+ AC_DEFINE([ENABLE_DEBUG_CYSIGNALS], 1, [Enable debug output])
+fi
AC_LANG(C)
diff --git a/example/cysignals_example.pyx b/example/cysignals_example.pyx
index ed7b0f6..80a4350 100644
--- a/example/cysignals_example.pyx
+++ b/example/cysignals_example.pyx
@@ -5,6 +5,7 @@ from libc.math cimport sin
def sine_sum(double x, long count):
cdef double s = 0
+ cdef long i
for i in range(count):
sig_check()
s += sin(i*x)
diff --git a/setup.py b/setup.py
index 135bda0..3c66e62 100755
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,8 @@ extensions = [
config_pxd_file = opj(cythonize_dir, "src", "config.pxd")
if not os.path.isfile(config_pxd_file):
import subprocess
- subprocess.check_call("make configure && ./configure", shell=True)
+ subprocess.check_call(["make", "configure"])
+ subprocess.check_call(["sh", "configure"])
# Determine installation directory from distutils
diff --git a/src/cysignals/debug.h b/src/cysignals/debug.h.in
similarity index 75%
rename from src/cysignals/debug.h
rename to src/cysignals/debug.h.in
index 23e7af5..4c67836 100644
--- a/src/cysignals/debug.h
+++ b/src/cysignals/debug.h.in
@@ -3,4 +3,6 @@
* code (0: disable, 1: enable). Enabling will make the code slower.
* The debug level itself needs to be set in implementation.c
*/
-#define ENABLE_DEBUG_CYSIGNALS 0
+#ifndef ENABLE_DEBUG_CYSIGNALS
+#undef ENABLE_DEBUG_CYSIGNALS
+#endif
diff --git a/src/cysignals/implementation.c b/src/cysignals/implementation.c
index 47995e5..47d8249 100644
--- a/src/cysignals/implementation.c
+++ b/src/cysignals/implementation.c
@@ -25,19 +25,21 @@ Interrupt and signal handling for Cython
#include "config.h"
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <Python.h>
-#include <stdlib.h>
+#if HAVE_UNISTD_H
#include <unistd.h>
+#endif
#if HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#if HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
+#include <Python.h>
#if HAVE_PARI
#include <pari/pari.h>
#else
@@ -49,10 +51,7 @@ static int PARI_SIGINT_pending = 0;
#include "signals.h"
-/* Interrupt debug level. This only works if ENABLE_DEBUG_CYSIGNALS
- * has been set to "1" in debug.h */
#if ENABLE_DEBUG_CYSIGNALS
-static int default_debug_level = 2;
static struct timeval sigtime; /* Time of signal */
#endif
@@ -189,7 +188,7 @@ static void cysigs_signal_handler(int sig)
signal(SIGTERM, SIG_DFL);
sigprocmask(SIG_SETMASK, &default_sigmask, NULL);
- if (inside) sigdie(sig, "An error occured during signal handling.");
+ if (inside) sigdie(sig, "An error occurred during signal handling.");
/* Quit Python with an appropriate message. */
switch(sig)
@@ -324,11 +323,20 @@ static void setup_cysignals_handlers(void)
if (sigaction(SIGFPE, &sa, NULL)) {perror("sigaction"); exit(1);}
if (sigaction(SIGBUS, &sa, NULL)) {perror("sigaction"); exit(1);}
if (sigaction(SIGSEGV, &sa, NULL)) {perror("sigaction"); exit(1);}
+}
+
+static inline int _set_debug_level(int level)
+{
#if ENABLE_DEBUG_CYSIGNALS
- cysigs.debug_level = default_debug_level;
- if (cysigs.debug_level >= 1)
- fprintf(stderr, "Finished setting up interrupts\n");
+ int old = cysigs.debug_level;
+ cysigs.debug_level = level;
+ return old;
+#else
+ if (level == 0)
+ return 0; /* 0 is the only valid debug level */
+ else
+ return -1; /* Error */
#endif
}
diff --git a/src/cysignals/macros.h b/src/cysignals/macros.h
index a3155f3..f68786d 100644
--- a/src/cysignals/macros.h
+++ b/src/cysignals/macros.h
@@ -1,8 +1,6 @@
/*
Interrupt and signal handling for Cython.
-For documentation about how to use these, see the Developer's Guide.
-
This code distinguishes between two kinds of signals:
(1) interrupt-like signals: SIGINT, SIGALRM, SIGHUP. The word
@@ -66,14 +64,14 @@ extern "C" {
*
* _sig_on_(message) is a macro which pretends to be a function.
* Since this is declared as "cdef except 0", Cython will know that an
- * exception occured if the value of _sig_on_() is 0 (false).
+ * exception occurred if the value of _sig_on_() is 0 (false).
*
* INPUT:
*
* - message -- a string to be displayed as error message when the code
* between sig_on() and sig_off() fails and raises an exception.
*
- * OUTPUT: zero if an exception occured, non-zero otherwise.
+ * OUTPUT: zero if an exception occurred, non-zero otherwise.
*
* The function sigsetjmp() in the _sig_on_() macro can return:
* - zero: this happens in the actual sig_on() call. sigsetjmp() sets
@@ -127,7 +125,7 @@ static inline int _sig_on_postjmp(int jmpret)
{
if (unlikely(jmpret > 0))
{
- /* An exception occured */
+ /* An exception occurred */
_sig_on_recover();
return 0;
}
@@ -189,7 +187,7 @@ static inline void _sig_off_(const char* file, int line)
* but much faster. Essentially, it checks whether we missed any
* interrupts.
*
- * OUTPUT: zero if an interrupt occured, non-zero otherwise.
+ * OUTPUT: zero if an interrupt occurred, non-zero otherwise.
*/
static inline int sig_check(void)
{
diff --git a/src/cysignals/signals.pyx b/src/cysignals/signals.pyx
index efb7725..c3e2fbe 100644
--- a/src/cysignals/signals.pyx
+++ b/src/cysignals/signals.pyx
@@ -29,6 +29,7 @@ from cpython.exc cimport PyErr_Occurred
cdef extern from "implementation.c":
cysigs_t cysigs "cysigs"
+ int _set_debug_level(int) nogil
void setup_cysignals_handlers() nogil
void print_backtrace() nogil
void _sig_on_interrupt_received() nogil
@@ -193,9 +194,35 @@ def init_cysignals():
setup_cysignals_handlers()
+ # Set debug level to 2 by default (if debugging was enabled)
+ _set_debug_level(2)
+
return old
+def set_debug_level(int level):
+ """
+ Set the cysignals debug level and return the old debug level.
+
+ Setting this to a positive value is only allowed if cysignals was
+ compiled with ``--enable-debug``.
+
+ EXAMPLES::
+
+ >>> from cysignals.signals import set_debug_level
+ >>> old = set_debug_level(0)
+ >>> set_debug_level(old)
+ 0
+
+ """
+ if level < 0:
+ raise ValueError("cysignals debug level must be >= 0")
+ cdef int r = _set_debug_level(level)
+ if r == -1:
+ raise RuntimeError("cysignals is compiled without debugging, recompile with --enable-debug")
+ return r
+
+
def sig_on_reset():
"""
Return the current value of ``cysigs.sig_on_count`` and set its
diff --git a/src/cysignals/tests.pyx b/src/cysignals/tests.pyx
index b0b52dc..66ce311 100644
--- a/src/cysignals/tests.pyx
+++ b/src/cysignals/tests.pyx
@@ -51,6 +51,14 @@ cdef long DEFAULT_DELAY = 200
########################################################################
+# Disable debugging while testing #
+########################################################################
+
+from .signals import set_debug_level
+set_debug_level(0)
+
+
+########################################################################
# C helper functions #
########################################################################
cdef void infinite_loop() nogil:
@@ -598,7 +606,7 @@ def test_bad_str(long delay=DEFAULT_DELAY):
------------------------------------------------------------------------
...
------------------------------------------------------------------------
- An error occured during signal handling.
+ An error occurred during signal handling.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
diff --git a/src/cysignals/tests_helper.c b/src/cysignals/tests_helper.c
index a8018ed..8a76a89 100644
--- a/src/cysignals/tests_helper.c
+++ b/src/cysignals/tests_helper.c
@@ -24,7 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
-#include <time.h>
+#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#include <sys/select.h>
@@ -36,10 +36,10 @@
/* Wait ``ms`` milliseconds */
void ms_sleep(long ms)
{
- struct timespec t;
+ struct timeval t;
t.tv_sec = (ms / 1000);
- t.tv_nsec = (ms % 1000) * 1000000;
- pselect(0, NULL, NULL, NULL, &t, NULL);
+ t.tv_usec = (ms % 1000) * 1000;
+ select(0, NULL, NULL, NULL, &t);
}
diff --git a/src/scripts/cysignals-CSI b/src/scripts/cysignals-CSI
index 92585fc..28187b6 100755
--- a/src/scripts/cysignals-CSI
+++ b/src/scripts/cysignals-CSI
@@ -42,6 +42,16 @@ from argparse import ArgumentParser
from datetime import datetime
+def b(x):
+ """
+ Convert `x` (either a ``str`` or ``bytes``) to ``bytes``, assuming
+ ASCII encoding.
+ """
+ if isinstance(x, bytes):
+ return x
+ return bytes(x, "ascii")
+
+
def pid_exists(pid):
"""
Return True if and only if there is a process with id pid running.
@@ -54,30 +64,31 @@ def pid_exists(pid):
def gdb_commands(pid, color):
- cmds = ''
- cmds += 'set prompt (cysignals-gdb-prompt)\n'
- cmds += 'set verbose off\n'
- cmds += 'attach {0}\n'.format(pid)
- cmds += 'python\n'
- cmds += 'print("\\n")\n'
- cmds += 'print("Stack backtrace")\n'
- cmds += 'print("---------------")\n'
- cmds += 'import sys; sys.stdout.flush()\n'
- cmds += 'end\n'
- cmds += 'bt full\n'
+ cmds = b('')
+ cmds += b('set prompt (cysignals-gdb-prompt)\n')
+ cmds += b('set verbose off\n')
+ cmds += b('attach {0}\n'.format(pid))
+ cmds += b('python\n')
+ cmds += b('print("\\n")\n')
+ cmds += b('print("Stack backtrace")\n')
+ cmds += b('print("---------------")\n')
+ cmds += b('import sys; sys.stdout.flush()\n')
+ cmds += b('end\n')
+ cmds += b('bt full\n')
script = os.path.join(os.path.dirname(sys.argv[0]), 'cysignals-CSI-helper.py')
with open(script, 'r') as f:
- cmds += 'python\n'
- cmds += 'color = {0}\n'.format(color)
- cmds += f.read()
- cmds += 'end\n'
- cmds += 'detach inferior 1\n'
- cmds += 'python print("Stack backtrace (newest frame = first)\\n")\n'
- cmds += 'python print("--------------------------------------\\n")\n'
- cmds += 'python import sys; sys.stdout.flush()\n'
- cmds += 'quit\n'
+ cmds += b('python\n')
+ cmds += b('color = {0}\n'.format(color))
+ cmds += b(f.read())
+ cmds += b('end\n')
+ cmds += b('detach inferior 1\n')
+ cmds += b('python print("Stack backtrace (newest frame = first)\\n")\n')
+ cmds += b('python print("--------------------------------------\\n")\n')
+ cmds += b('python import sys; sys.stdout.flush()\n')
+ cmds += b('quit\n')
return cmds
+
def run_gdb(pid, color):
"""
Execute gdb.
@@ -97,7 +108,12 @@ def run_gdb(pid, color):
stderr=PIPE, env=env)
except OSError:
return "Unable to start gdb (not installed?)"
- stdout, stderr = cmd.communicate(gdb_commands(pid, color))
+ try:
+ stdout, stderr = cmd.communicate(gdb_commands(pid, color))
+ except BaseException:
+ # Something went wrong => kill gdb
+ cmd.kill()
+ raise
result = []
for line in stdout.splitlines():
if line.find('(cysignals-gdb-prompt)') >= 0:
@@ -107,19 +123,19 @@ def run_gdb(pid, color):
if line.startswith('Loaded symbols for '):
continue
result.append(line)
- if stderr != "":
+ if stderr:
result.append(stderr)
return '\n'.join(result)
+
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as e:
- if os.path.isdir(path):
- pass
- else:
+ if not os.path.isdir(path):
raise
+
def prune_old_logs(directory, days):
"""
Delete all files in ``directory`` that are older than a given
@@ -162,27 +178,7 @@ def save_backtrace(output):
return filename
-if __name__ == '__main__':
- parser = ArgumentParser(description=description)
- parser.add_argument('-p', '--pid', dest='pid', action='store',
- default=None, type=int,
- help='the pid to attach to.')
- parser.add_argument('-nc', '--no-color', dest='nocolor', action='store_true',
- default=False,
- help='turn off syntax-highlighting.')
- parser.add_argument('-k', '--kill', dest='kill', action='store_true',
- default=False,
- help='kill after inspection is finished.')
- args = parser.parse_args()
-
- if args.pid is None:
- parser.print_help()
- sys.exit(0)
-
- if not pid_exists(args.pid):
- print('There is no process with pid {0}.'.format(args.pid))
- sys.exit(1)
-
+def main(args):
print('Attaching gdb to process id {0}.'.format(args.pid))
trace = run_gdb(args.pid, not args.nocolor)
print(trace)
@@ -197,21 +193,41 @@ if __name__ == '__main__':
( 'ImportError: No module named',
'Your system GDB uses an incompatible version of Python') ]
- fail = False
for key, msg in fatalities:
if key in trace:
print()
print(msg)
- fail = True
- break
+ print('Install gdb for enhanced tracebacks.')
+ return
- if fail:
- print('Install gdb for enhanced tracebacks.')
- else:
- filename = save_backtrace(trace)
- if filename is not None:
- print('Saved trace to {0}'.format(filename))
+ filename = save_backtrace(trace)
+ if filename is not None:
+ print('Saved trace to {0}'.format(filename))
+
+
+if __name__ == '__main__':
+ parser = ArgumentParser(description=description)
+ parser.add_argument('-p', '--pid', dest='pid', action='store',
+ default=None, type=int,
+ help='the pid to attach to.')
+ parser.add_argument('-nc', '--no-color', dest='nocolor', action='store_true',
+ default=False,
+ help='turn off syntax-highlighting.')
+ parser.add_argument('-k', '--kill', dest='kill', action='store_true',
+ default=False,
+ help='kill after inspection is finished.')
+ args = parser.parse_args()
- if args.kill:
- os.kill(args.pid, signal.SIGKILL)
+ if args.pid is None:
+ parser.print_help()
+ sys.exit(0)
+
+ if not pid_exists(args.pid):
+ print('There is no process with pid {0}.'.format(args.pid))
+ sys.exit(1)
+ try:
+ main(args)
+ finally:
+ if args.kill:
+ os.kill(args.pid, signal.SIGKILL)
diff --git a/src/scripts/cysignals-CSI-helper.py b/src/scripts/cysignals-CSI-helper.py
index 4954f6d..e5cfed8 100644
--- a/src/scripts/cysignals-CSI-helper.py
+++ b/src/scripts/cysignals-CSI-helper.py
@@ -36,7 +36,11 @@ def cython_debug_files():
"""
Cython extra debug information files
"""
- pattern = os.path.join(os.environ['SAGE_SRC'], 'cython_debug',
+ try:
+ SAGE_SRC = os.environ['SAGE_SRC']
+ except KeyError:
+ return []
+ pattern = os.path.join(SAGE_SRC, 'build', 'cython_debug',
'cython_debug_info_*')
return glob.glob(pattern)
@@ -46,11 +50,10 @@ print('----------------')
# The Python interpreter in GDB does not do automatic backtraces for you
try:
-
for f in cython_debug_files():
cy.import_.invoke(f, None)
- class SageBacktrace(CythonCommand):
+ class Backtrace(CythonCommand):
name = 'cy fullbt'
alias = 'cy full_backtrace'
command_class = gdb.COMMAND_STACK
@@ -123,7 +126,7 @@ try:
index += 1
frame = frame.newer()
- trace = SageBacktrace.register()
+ trace = Backtrace.register()
trace.invoke(None, None)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/cysignals.git
More information about the Python-modules-commits
mailing list