[Python-modules-commits] [cysignals] 02/04: Import cysignals_1.6.6+ds.orig.tar.xz
Jerome Benoit
calculus-guest at moszumanska.debian.org
Fri Jan 19 13:05:36 UTC 2018
This is an automated email from the git hooks/post-receive script.
calculus-guest pushed a commit to branch master
in repository cysignals.
commit 111af3d3682afd441dcf30d7197d3df235e1845b
Author: Jerome Benoit <calculus at rezozer.net>
Date: Fri Jan 19 09:35:46 2018 +0400
Import cysignals_1.6.6+ds.orig.tar.xz
---
MANIFEST.in | 2 +-
Makefile | 6 ++---
PKG-INFO | 22 +++++++++++++++---
VERSION | 2 +-
docs/source/crash.rst | 49 ++++++++++++++++++++++++++++++++++++++++
docs/source/index.rst | 1 +
docs/source/interrupt.rst | 2 +-
docs/source/sigadvanced.rst | 7 +++---
docs/source/sigerror.rst | 11 +++++----
setup.py | 35 +++++++++++++++++++++++++----
src/cysignals/alarm.pyx | 2 ++
src/cysignals/implementation.c | 8 +++++--
src/cysignals/pselect.pyx | 2 ++
src/cysignals/pysignals.pyx | 4 +++-
src/cysignals/signals.pxd | 4 ++--
src/cysignals/signals.pyx | 1 +
src/cysignals/struct_signals.h | 8 +++----
src/cysignals/tests.pyx | 19 +++++++++++++---
src/scripts/cysignals-CSI | 4 ++--
testgdb.py | 51 ++++++++++++++++++++++++++++++++++++++++++
20 files changed, 206 insertions(+), 34 deletions(-)
diff --git a/MANIFEST.in b/MANIFEST.in
index 84eff69..d9d71ec 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,6 +1,6 @@
global-include README README.rst VERSION LICENSE
global-include Makefile configure configure.ac
-global-include setup.py rundoctests.py *.pyx
+global-include setup.py rundoctests.py testgdb.py *.pyx
graft src
graft docs/source
prune build
diff --git a/Makefile b/Makefile
index f1c908e..77468a1 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ install: configure
dist: configure
chmod go+rX-w -R .
- umask 0022 && $(PYTHON) setup.py sdist --formats=bztar
+ umask 0022 && $(PYTHON) setup.py sdist --formats=gztar
doc:
cd docs && $(MAKE) html
@@ -112,7 +112,7 @@ check-user-example: user-install
distcheck: dist
rm -rf dist/check
mkdir -p dist/check
- cd dist/check && tar xjf ../cysignals-$(VERSION).tar.bz2
+ cd dist/check && tar xzf ../cysignals-$(VERSION).tar.gz
cd dist/check/cysignals-$(VERSION) && $(LS_R) >../dist0.ls
cd dist/check/cysignals-$(VERSION) && $(MAKE) all
cd dist/check/cysignals-$(VERSION) && $(MAKE) distclean
@@ -125,7 +125,7 @@ distcheck: dist
cd dist/check/cysignals-$(VERSION) && $(LS_R) >../dist2.ls
cd dist/check; diff -u dist0.ls dist2.ls || { echo >&2 "Error: distclean after check-tmp leaves garbage"; exit 1; }
cd dist/check/cysignals-$(VERSION) && $(MAKE) dist
- cd dist/check/cysignals-$(VERSION) && tar xjf dist/cysignals-$(VERSION).tar.bz2
+ cd dist/check/cysignals-$(VERSION) && tar xzf dist/cysignals-$(VERSION).tar.gz
cd dist/check/cysignals-$(VERSION)/cysignals-$(VERSION) && $(LS_R) >../../dist3.ls
cd dist/check; diff -u dist0.ls dist3.ls || { echo >&2 "Error: sdist is not reproducible"; exit 1; }
rm -rf dist/check
diff --git a/PKG-INFO b/PKG-INFO
index f7842f6..73dff4f 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,11 +1,12 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
Name: cysignals
-Version: 1.6.5
+Version: 1.6.6
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
Author-email: sage-devel at googlegroups.com
License: GNU Lesser General Public License, version 3 or later
+Description-Content-Type: UNKNOWN
Description: cysignals: interrupt and signal handling for Cython
===================================================
@@ -29,4 +30,19 @@ Description: cysignals: interrupt and signal handling for Cython
See http://cysignals.readthedocs.org/ for the full documentation.
-Platform: POSIX
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
+Classifier: Operating System :: POSIX
+Classifier: Programming Language :: C
+Classifier: Programming Language :: Cython
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Topic :: System
+Classifier: Topic :: Software Development :: Debuggers
diff --git a/VERSION b/VERSION
index 9f05f9f..ec70f75 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.6.5
+1.6.6
diff --git a/docs/source/crash.rst b/docs/source/crash.rst
new file mode 100644
index 0000000..d909b97
--- /dev/null
+++ b/docs/source/crash.rst
@@ -0,0 +1,49 @@
+.. _section_debug:
+
+Debugging Python crashes
+========================
+
+If ``cysignals`` is imported, it sets up a hook which triggers when
+Python crashes. For example, it would be triggered on a segmentation
+fault outside a ``sig_on()`` block.
+
+When a crash happens, first a simple C backtrace is printed if supported
+by the C library on the system.
+Then GDB is run to print a much more complete backtrace
+(except on OS X, where running a debugger requires special privileges).
+For your convenience, these GDB backtraces are also saved to a logfile.
+
+Finally, this familiar message is shown::
+
+ 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.
+
+Environment variables
+---------------------
+
+There are several environment variables which influence this:
+
+.. envvar:: CYSIGNALS_CRASH_QUIET
+
+ If set, be completely quiet whenever a crash happens.
+ No backtrace or other message is shown and GDB is not run.
+
+.. envvar:: CYSIGNALS_CRASH_NDEBUG
+
+ If set, disable the GDB backtrace.
+ The simple backtrace is still shown.
+
+.. envvar:: CYSIGNALS_CRASH_LOGS
+
+ The directory where the logs of the crashes are stored.
+ If this is empty, disable storing of crash logs.
+ The default is ``cysignals_crash_logs`` in the current directory.
+
+.. envvar:: CYSIGNALS_CRASH_DAYS
+
+ Automatically delete crash logs older than this many days
+ in the directory where crash logs are stored.
+ A negative value means that logs are never deleted.
+ The default is 7 days if ``CYSIGNALS_CRASH_LOGS`` is unset
+ and -1 days (never delete) otherwise.
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 436d21a..602263f 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -32,6 +32,7 @@ Dealing with interrupts and other signals using ``sig_check`` and ``sig_on``:
interrupt
signals
sigadvanced
+ crash
Error handling
--------------
diff --git a/docs/source/interrupt.rst b/docs/source/interrupt.rst
index 69ea3d1..bcf4891 100644
--- a/docs/source/interrupt.rst
+++ b/docs/source/interrupt.rst
@@ -220,7 +220,7 @@ raised by subroutines inside the ``try``::
finally:
sig_off()
-If you want to also catch this exception, you need a nested ``try``::
+If you also want to catch this exception, you need a nested ``try``::
from cysignals.signals cimport sig_on, sig_off
def try_finally_and_catch_example():
diff --git a/docs/source/sigadvanced.rst b/docs/source/sigadvanced.rst
index 172bfe1..a5222c8 100644
--- a/docs/source/sigadvanced.rst
+++ b/docs/source/sigadvanced.rst
@@ -22,9 +22,10 @@ SageMath function :func:`factor()` can be interrupted:
alarm!
If you use the SageMath doctesting framework, you can instead doctest
-the exception in the usual way. To avoid race conditions, make sure
-that the calls to ``alarm()`` and the function you want to test are in
-the same doctest:
+the exception in the usual way (the Python ``doctest`` module exits
+whenever a ``KeyboardInterrupt`` is raised in a doctest).
+To avoid race conditions, make sure that the calls to ``alarm()`` and
+the function you want to test are in the same doctest:
.. code-block:: pycon
diff --git a/docs/source/sigerror.rst b/docs/source/sigerror.rst
index 5e13550..718210c 100644
--- a/docs/source/sigerror.rst
+++ b/docs/source/sigerror.rst
@@ -27,9 +27,12 @@ A typical error handler implemented in Cython would look as follows::
Exceptions which are raised this way can be handled as usual by putting
the ``sig_on()`` in a ``try``/``except`` block.
-For example, in `SageMath <http://www.sagemath.org/>`_, the
-`PARI interface <http://doc.sagemath.org/html/en/reference/libs/sage/libs/pari/pari_instance.html>`_
-can raise a custom ``PariError`` exception. This can be handled as follows::
+For example, the package `cypari2 <https://github.com/defeo/cypari2>`_
+provides a wrapper around the number theory library PARI/GP.
+The `error handler <https://github.com/defeo/cypari2/blob/master/cypari2/handle_error.pyx>`_
+has a callback which turns errors from PARI/GP
+into Python exceptions of type ``PariError``.
+This can be handled as follows::
from cysignals.signals cimport sig_on, sig_off
def handle_pari_error():
@@ -40,4 +43,4 @@ can raise a custom ``PariError`` exception. This can be handled as follows::
except PariError:
# (handle error)
-SageMath uses this mechanism for libGAP, NTL and PARI.
+SageMath uses this mechanism for libGAP, GLPK, NTL and PARI.
diff --git a/setup.py b/setup.py
index 57b6b39..e9ce1c4 100755
--- a/setup.py
+++ b/setup.py
@@ -52,6 +52,26 @@ extensions = [
]
+classifiers = [
+ 'Development Status :: 5 - Production/Stable',
+ 'Intended Audience :: Developers',
+ ('License :: OSI Approved :: '
+ 'GNU Lesser General Public License v3 or later (LGPLv3+)'),
+ 'Operating System :: POSIX',
+ 'Programming Language :: C',
+ 'Programming Language :: Cython',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
+ 'Topic :: System',
+ 'Topic :: Software Development :: Debuggers',
+]
+
+
def write_if_changed(filename, text):
"""
Write ``text`` to ``filename`` but only if it differs from the
@@ -188,16 +208,23 @@ class no_egg(_bdist_egg):
raise DistutilsOptionError("The package cysignals will not function correctly when built as egg. Therefore, it cannot be installed using 'python setup.py install' or 'easy_install'. Instead, use 'pip install' to install cysignals.")
+with open("VERSION") as f:
+ VERSION = f.read().strip()
+
+with open('README.rst') as f:
+ README = f.read()
+
+
setup(
name="cysignals",
author=u"Martin R. Albrecht, François Bissey, Volker Braun, Jeroen Demeyer",
author_email="sage-devel at googlegroups.com",
- version=open("VERSION").read().strip(),
+ version=VERSION,
url="https://github.com/sagemath/cysignals",
license="GNU Lesser General Public License, version 3 or later",
description="Interrupt and signal handling for Cython",
- long_description=open('README.rst').read(),
- platforms=["POSIX"],
+ long_description=README,
+ classifiers=classifiers,
setup_requires=["Cython"],
ext_modules=extensions,
@@ -207,5 +234,5 @@ setup(
package_data={"cysignals": ["*.pxi", "*.pxd", "*.h"],
"cysignals-cython": ["*.h"]},
scripts=glob(opj("src", "scripts", "*")),
- cmdclass=dict(build=build, build_py=build_py, install=install, bdist_egg=no_egg)
+ cmdclass=dict(build=build, build_py=build_py, install=install, bdist_egg=no_egg),
)
diff --git a/src/cysignals/alarm.pyx b/src/cysignals/alarm.pyx
index a86d019..d461550 100644
--- a/src/cysignals/alarm.pyx
+++ b/src/cysignals/alarm.pyx
@@ -20,6 +20,8 @@ Fine-grained alarm function
#
#*****************************************************************************
+from __future__ import absolute_import
+
from posix.time cimport (setitimer, itimerval, ITIMER_REAL,
time_t, suseconds_t)
diff --git a/src/cysignals/implementation.c b/src/cysignals/implementation.c
index 3daf43f..c058dcf 100644
--- a/src/cysignals/implementation.c
+++ b/src/cysignals/implementation.c
@@ -228,7 +228,7 @@ static void do_raise_exception(int sig)
gettimeofday(&raisetime, NULL);
long delta_ms = (raisetime.tv_sec - sigtime.tv_sec)*1000L + ((long)raisetime.tv_usec - (long)sigtime.tv_usec)/1000;
PyGILState_STATE gilstate = PyGILState_Ensure();
- fprintf(stderr, "do_raise_exception(sig=%i)\nPyErr_Occurred() = %p\nRaising Python exception %li ms after signals...\n",
+ fprintf(stderr, "do_raise_exception(sig=%i)\nPyErr_Occurred() = %p\nRaising Python exception %li ms after signal...\n",
sig, PyErr_Occurred(), delta_ms);
PyGILState_Release(gilstate);
fflush(stderr);
@@ -400,6 +400,8 @@ static void print_enhanced_backtrace(void)
/* Print a message s and kill ourselves with signal sig */
static void sigdie(int sig, const char* s)
{
+ if (getenv("CYSIGNALS_CRASH_QUIET")) goto dienow;
+
print_sep();
print_backtrace();
@@ -410,7 +412,8 @@ static void sigdie(int sig, const char* s)
#else
#ifndef __APPLE__
/* See http://trac.sagemath.org/13889 for how Apple screwed this up */
- print_enhanced_backtrace();
+ if (getenv("CYSIGNALS_CRASH_NDEBUG") == NULL)
+ print_enhanced_backtrace();
#endif
#endif
@@ -423,6 +426,7 @@ static void sigdie(int sig, const char* s)
print_sep();
}
+dienow:
/* Suicide with signal ``sig`` */
kill(getpid(), sig);
diff --git a/src/cysignals/pselect.pyx b/src/cysignals/pselect.pyx
index 789672f..d4d3b2a 100644
--- a/src/cysignals/pselect.pyx
+++ b/src/cysignals/pselect.pyx
@@ -65,6 +65,8 @@ Now using the ``multiprocessing`` module::
#
#*****************************************************************************
+from __future__ import absolute_import
+
cimport libc.errno
from posix.signal cimport *
from posix.select cimport *
diff --git a/src/cysignals/pysignals.pyx b/src/cysignals/pysignals.pyx
index 07b5c3e..331d285 100644
--- a/src/cysignals/pysignals.pyx
+++ b/src/cysignals/pysignals.pyx
@@ -11,7 +11,7 @@ It also sets the OS-level signal handler to a specific C function
which calls the Python-level signal handler.
The Python ``signal`` module does not allow access to the OS-level
-signal handler (in particular, it does not allow to temporarily change
+signal handler (in particular, it does not allow one to temporarily change
a signal handler if the OS-level handler was not the Python one).
"""
@@ -33,6 +33,8 @@ a signal handler if the OS-level handler was not the Python one).
#
#*****************************************************************************
+from __future__ import absolute_import
+
import signal
from signal import getsignal
from libc.string cimport memcpy
diff --git a/src/cysignals/signals.pxd b/src/cysignals/signals.pxd
index be33191..1ae6375 100644
--- a/src/cysignals/signals.pxd
+++ b/src/cysignals/signals.pxd
@@ -25,7 +25,7 @@ cdef extern from "struct_signals.h":
cdef extern from "macros.h" nogil:
int sig_on() except 0
- int sig_str(char*) except 0
+ int sig_str(const char*) except 0
int sig_check() except 0
void sig_off()
void sig_retry() # Does not return
@@ -37,7 +37,7 @@ cdef extern from "macros.h" nogil:
# which are *not* declared "except 0". This is useful if some
# low-level Cython code wants to do its own exception handling.
int sig_on_no_except "sig_on"()
- int sig_str_no_except "sig_str"(char*)
+ int sig_str_no_except "sig_str"(const char*)
int sig_check_no_except "sig_check"()
diff --git a/src/cysignals/signals.pyx b/src/cysignals/signals.pyx
index d42a264..dd9f183 100644
--- a/src/cysignals/signals.pyx
+++ b/src/cysignals/signals.pyx
@@ -22,6 +22,7 @@ See ``tests.pyx`` for extensive tests.
#
#*****************************************************************************
+from __future__ import absolute_import
from libc.signal cimport *
from libc.stdio cimport freopen, stdin
diff --git a/src/cysignals/struct_signals.h b/src/cysignals/struct_signals.h
index 9fe948d..b574e63 100644
--- a/src/cysignals/struct_signals.h
+++ b/src/cysignals/struct_signals.h
@@ -72,10 +72,10 @@ typedef struct
* been received. This is set by sig_on(). */
sigjmp_buf env;
- /* An optional string may be passed to the signal handler which
- * will be used as the text for the exception. This can be set
- * using sig_str() instead of sig_on().
- */
+ /* An optional string (in UTF-8 encoding) to be used as text for
+ * the exception raised by sig_raise_exception(). If this is NULL,
+ * use some default string depending on the type of signal. This can
+ * be set using sig_str() instead of sig_on(). */
const char* s;
#if ENABLE_DEBUG_CYSIGNALS
diff --git a/src/cysignals/tests.pyx b/src/cysignals/tests.pyx
index 81e1910..2e1ed30 100644
--- a/src/cysignals/tests.pyx
+++ b/src/cysignals/tests.pyx
@@ -3,10 +3,10 @@ Test interrupt and signal handling
TESTS:
-We disable crash logs for this test run::
+We disable crash debugging for this test run::
>>> import os
- >>> os.environ["CYSIGNALS_CRASH_LOGS"] = ""
+ >>> os.environ["CYSIGNALS_CRASH_NDEBUG"] = ""
"""
@@ -28,6 +28,7 @@ We disable crash logs for this test run::
#
#*****************************************************************************
+from __future__ import absolute_import
from libc.signal cimport (SIGHUP, SIGINT, SIGABRT, SIGILL, SIGSEGV,
SIGFPE, SIGBUS, SIGQUIT)
@@ -544,7 +545,8 @@ def unguarded_dereference_null_pointer():
>>> from subprocess import *
>>> cmd = 'from cysignals.tests import *; unguarded_dereference_null_pointer()'
- >>> print(Popen(['python', '-c', cmd], stdout=PIPE, stderr=PIPE).communicate()[1].decode("utf-8"))
+ >>> msg = Popen(['python', '-c', cmd], stdout=PIPE, stderr=PIPE).communicate()[1]
+ >>> print(msg.decode("utf-8"))
------------------------------------------------------------------------
...
------------------------------------------------------------------------
@@ -555,6 +557,17 @@ def unguarded_dereference_null_pointer():
------------------------------------------------------------------------
<BLANKLINE>
+ The same but with ``CYSIGNALS_CRASH_QUIET`` set. This will crash
+ Python silently::
+
+ >>> from subprocess import *
+ >>> cmd = 'from cysignals.tests import *; unguarded_dereference_null_pointer()'
+ >>> env = dict(os.environ)
+ >>> env["CYSIGNALS_CRASH_QUIET"] = ""
+ >>> msg = Popen(['python', '-c', cmd], stdout=PIPE, stderr=PIPE, env=env).communicate()[1]
+ >>> print(msg.decode("utf-8"))
+ <BLANKLINE>
+
"""
with nogil:
dereference_null_pointer()
diff --git a/src/scripts/cysignals-CSI b/src/scripts/cysignals-CSI
index ff7bed4..24d3aef 100755
--- a/src/scripts/cysignals-CSI
+++ b/src/scripts/cysignals-CSI
@@ -26,7 +26,7 @@ description = """
this script runs and resumes when it is finished."""
# A backtrace is saved in the directory $CYSIGNALS_CRASH_LOGS, which is
-# signals_crash_logs by default. Any backtraces older than
+# cysignals_crash_logs by default. Any backtraces older than
# $CYSIGNALS_CRASH_DAYS (default: 7 if CYSIGNALS_CRASH_LOGS unset, -1 if
# set) are automatically deleted, but with a negative value they are
# never deleted.
@@ -160,7 +160,7 @@ def save_backtrace(output):
# set CYSIGNALS_CRASH_LOGS to a stupid value.
bt_days = -1
except KeyError:
- bt_dir = 'signals_crash_logs'
+ bt_dir = 'cysignals_crash_logs'
bt_days = 7
if not bt_dir:
diff --git a/testgdb.py b/testgdb.py
new file mode 100755
index 0000000..c9af713
--- /dev/null
+++ b/testgdb.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+#
+# Test interaction with gdb, i.e. the cysignals-CSI script
+#
+# NOTE: this test is known to be broken in some cases, see
+# https://github.com/sagemath/cysignals/pull/52
+#
+
+import unittest
+
+import os
+import sys
+from subprocess import Popen, PIPE
+from tempfile import mkdtemp
+from shutil import rmtree
+
+class TestGDB(unittest.TestCase):
+ def setUp(self):
+ # Store crash logs in a temporary directory
+ self.crash_dir = mkdtemp()
+ self.env = dict(os.environ)
+ self.env["CYSIGNALS_CRASH_LOGS"] = self.crash_dir
+
+ def tearDown(self):
+ rmtree(self.crash_dir)
+
+ def test_gdb(self):
+ # Run a Python subprocess which we intentionally crash to inspect the
+ # crash logfile.
+ p = Popen([sys.executable], stdin=PIPE, env=self.env)
+ with p.stdin as stdin:
+ stdin.write(b"from cysignals.tests import *\n")
+ stdin.write(b"unguarded_dereference_null_pointer()\n")
+
+ ret = p.wait()
+ self.assertLess(ret, 0)
+
+ # Check crash log
+ logs = [os.path.join(self.crash_dir, fn)
+ for fn in os.listdir(self.crash_dir) if fn.endswith(".log")]
+ self.assertEqual(len(logs), 1)
+ log = open(logs[0]).read()
+
+ self.assertIn(b"Stack backtrace", log)
+ self.assertIn(b"Cython backtrace", log)
+ self.assertIn(b"__pyx_pf_9cysignals_5tests_46unguarded_dereference_null_pointer()", log)
+ self.assertIn(b"cdef void dereference_null_pointer() nogil:", log)
+
+
+if __name__ == '__main__':
+ unittest.main()
--
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