8000 BUG: Xerbla doesn't get linked in 1.10-devel. · numpy/numpy@75666e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75666e3

Browse files
committed
BUG: Xerbla doesn't get linked in 1.10-devel.
Add our python_xerbla to the multiarray sources. That function is needed for all modules that link to the ATLAS 3.10 libraries, which are now all located in two files, libsatlas and libtatlas. Also make the test for xerbla linkage work better. If xerbla is not linked the test will be skipped with a message. Closes #5362.
1 parent 3ef77ee commit 75666e3

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

numpy/core/bscript

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,9 @@ def pre_build(context):
479479
]
480480

481481
if bld.env.HAS_CBLAS:
482-
sources.append(pjoin('src', 'multiarray', 'cblasfuncs.c'))
482+
sources.extend([pjoin('src', 'multiarray', 'cblasfuncs.c'),
483+
pjoin('src', 'multiarray', 'python_xerbla.c'),
484+
])
483485
else:
484486
sources = extension.sources
485487

numpy/core/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,9 @@ def generate_multiarray_templated_sources(ext, build_dir):
839839
blas_info = get_info('blas_opt', 0)
840840
if blas_info and ('HAVE_CBLAS', None) in blas_info.get('define_macros', []):
841841
extra_info = blas_info
842-
multiarray_src.append(join('src', 'multiarray', 'cblasfuncs.c'))
842+
multiarray_src.extend([join('src', 'multiarray', 'cblasfuncs.c'),
843+
join('src', 'multiarray', 'python_xerbla.c'),
844+
])
843845
else:
844846
extra_info = {}
845847

numpy/core/src/multiarray/multiarraymodule_onefile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
#include "multiarraymodule.c"
5757

5858
#if defined(HAVE_CBLAS)
59+
#include "python_xerbla.c"
5960
#include "cblasfuncs.c"
6061
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "Python.h"
2+
3+
/*
4+
* From f2c.h, this should be safe unless fortran is set to use 64
5+
* bit integers. We don't seem to have any good way to detect that.
6+
*/
7+
typedef int integer;
8+
9+
/*
10+
From the original manpage:
11+
--------------------------
12+
XERBLA is an error handler for the LAPACK routines.
13+
It is called by an LAPACK routine if an input parameter has an invalid value.
14+
A message is printed and execution stops.
15+
16+
Instead of printing a message and stopping the execution, a
17+
ValueError is raised with the message.
18+
19+
Parameters:
20+
-----------
21+
srname: Subroutine name to use in error message, maximum six characters.
22+
Spaces at the end are skipped.
23+
info: Number of the invalid parameter.
24+
*/
25+
26+
int xerbla_(char *srname, integer *info)
27+
{
28+
static const char format[] = "On entry to %.*s" \
29+
" parameter number %d had an illegal value";
30+
char buf[sizeof(format) + 6 + 4]; /* 6 for name, 4 for param. num. */
31+
32+
int len = 0; /* length of subroutine name*/
33+
#ifdef WITH_THREAD
34+
PyGILState_STATE save;
35+
#endif
36+
37+
while( len<6 && srname[len]!='\0' )
38+
len++;
39+
while( len && srname[len-1]==' ' )
40+
len--;
41+
#ifdef WITH_THREAD
42+
save = PyGILState_Ensure();
43+
#endif
44+
PyOS_snprintf(buf, sizeof(buf), format, len, srname, *info);
45+
PyErr_SetString(PyExc_ValueError, buf);
46+
#ifdef WITH_THREAD
47+
PyGILState_Release(save);
48+
#endif
49+
50+
return 0;
51+
}

numpy/linalg/tests/test_linalg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,8 @@ def test_xerbla_override():
11521152
# and may, or may not, abort the process depending on the LAPACK package.
11531153
from nose import SkipTest
11541154

1155+
XERBLA_OK = 255
1156+
11551157
try:
11561158
pid = os.fork()
11571159
except (OSError, AttributeError):
@@ -1181,15 +1183,16 @@ def test_xerbla_override():
11811183
a, a, 0, 0)
11821184
except ValueError as e:
11831185
if "DORGQR parameter number 5" in str(e):
1184-
# success
1185-
os._exit(os.EX_OK)
1186+
# success, reuse error code to mark success as
1187+
# FORTRAN STOP returns as success.
1188+
os._exit(XERBLA_OK)
11861189

11871190
# Did not abort, but our xerbla was not linked in.
11881191
os._exit(os.EX_CONFIG)
11891192
else:
11901193
# parent
11911194
pid, status = os.wait()
1192-
if os.WEXITSTATUS(status) != os.EX_OK or os.WIFSIGNALED(status):
1195+
if os.WEXITSTATUS(status) != XERBLA_OK:
11931196
raise SkipTest('Numpy xerbla not linked in.')
11941197

11951198

0 commit comments

Comments
 (0)
0