From 5743e8a0d04188cbbb621bb7db5f325c596dc56d Mon Sep 17 00:00:00 2001 From: bnavigator Date: Mon, 18 May 2020 22:39:20 +0200 Subject: [PATCH 1/3] override XERBLA with noop --- slycot/CMakeLists.txt | 4 ++-- slycot/src/XERBLA.f | 13 +++++++++++++ slycot/src/_helper.pyf | 6 ++++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 slycot/src/XERBLA.f diff --git a/slycot/CMakeLists.txt b/slycot/CMakeLists.txt index c481cea6..928c4737 100644 --- a/slycot/CMakeLists.txt +++ b/slycot/CMakeLists.txt @@ -104,7 +104,7 @@ set(FSOURCES src/delctg.f src/select.f src/SLCT_DLATZM.f src/SLCT_ZLATZM.f - src/ftruefalse.f + src/ftruefalse.f src/XERBLA.f ) set(F2PYSOURCE src/_wrapper.pyf) @@ -139,7 +139,7 @@ add_custom_command( add_library( ${SLYCOT_MODULE} MODULE - _wrappermodule.c + _wrappermodule.c ${PYTHON_SITE}/numpy/f2py/src/fortranobject.c _wrapper-f2pywrappers.f ${FSOURCES}) diff --git a/slycot/src/XERBLA.f b/slycot/src/XERBLA.f new file mode 100644 index 00000000..0d3c8067 --- /dev/null +++ b/slycot/src/XERBLA.f @@ -0,0 +1,13 @@ + SUBROUTINE XERBLA(SRNAME, INFO) +C +C SLYCOT +C Override LAPACK XERBLA routine to noop instead +C of PRINT and STOP +C + CHARACTER*(*) SRNAME + INTEGER INFO +C + RETURN +C + END +C diff --git a/slycot/src/_helper.pyf b/slycot/src/_helper.pyf index ed59e106..41bf0459 100644 --- a/slycot/src/_helper.pyf +++ b/slycot/src/_helper.pyf @@ -6,5 +6,7 @@ subroutine ftruefalse(ftrue,ffalse) ! in src/ftruefalse.f logical intent(out) :: ffalse end subroutine ftruefalse -! This file was auto-generated with f2py (version:2). -! See http://cens.ioc.ee/projects/f2py2e/ +subroutine xerbla(srname, info) ! in src/XERBLA.f + character*(*) :: srname + integer :: info +end subroutine From 73cd89c7e5e97205be8fa856158e25901b4b0914 Mon Sep 17 00:00:00 2001 From: bnavigator Date: Mon, 18 May 2020 23:26:13 +0200 Subject: [PATCH 2/3] add test for overidden XERBLA We call the _wrapper function directly so the python wrapper in analysis.py does not raise an exception or in a future version does not eventually handle the wrong parameter by checking it before the Fortran call. Because the file descriptors for the Fortran module are set at import time, we cannot use the pytest fixtures capsys or capfd, but need to start a new process. --- slycot/tests/test_exceptions.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/slycot/tests/test_exceptions.py b/slycot/tests/test_exceptions.py index 631a4cb7..13e2da27 100644 --- a/slycot/tests/test_exceptions.py +++ b/slycot/tests/test_exceptions.py @@ -19,6 +19,8 @@ """ import pytest +import subprocess +import sys from slycot.exceptions import raise_if_slycot_error, \ SlycotError, SlycotWarning, SlycotParameterError @@ -88,3 +90,19 @@ def test_unhandled_info_iwarn(): assert wm[1].message.info == 0 +# Test code for test_xerbla_override +CODE = """ +from slycot._wrapper import ab08nd +# equil='X' is invalid +out = ab08nd(1, 1, 1, [1], [1], [1], [1], equil='X') +print("INFO={}".format(out[-1])) +""" + + +def test_xerbla_override(): + """Test that Fortran routines calling XERBLA do not print to stdout.""" + + stdout = subprocess.check_output([sys.executable, '-c', CODE], + stderr=subprocess.STDOUT, + text=True) + assert stdout == "INFO=-1\n" From db2c5354e159a6305148327948c11457a7d28389 Mon Sep 17 00:00:00 2001 From: bnavigator Date: Tue, 19 May 2020 02:55:05 +0200 Subject: [PATCH 3/3] make compatible with older pythons --- slycot/tests/test_exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slycot/tests/test_exceptions.py b/slycot/tests/test_exceptions.py index 13e2da27..beb3fa0c 100644 --- a/slycot/tests/test_exceptions.py +++ b/slycot/tests/test_exceptions.py @@ -104,5 +104,5 @@ def test_xerbla_override(): stdout = subprocess.check_output([sys.executable, '-c', CODE], stderr=subprocess.STDOUT, - text=True) + universal_newlines=True) assert stdout == "INFO=-1\n"