Blame SOURCES/ckdtree_bugfix.patch

bd3b80
From d945dfa4063c5cd7169acd117c15f23ba68027ed Mon Sep 17 00:00:00 2001
bd3b80
From: Pauli Virtanen <pav@iki.fi>
bd3b80
Date: Wed, 31 Jul 2019 23:31:22 +0300
bd3b80
Subject: [PATCH 1/2] BUG: spatial: use c++11 construct for getting start of
bd3b80
 vector
bd3b80
bd3b80
gcc 9.1.1 on Fedora throws asserts and crashes at runtime on
bd3b80
`&x.front()` when `x` is empty, so use a different construct for getting
bd3b80
the beginning of the data block.
bd3b80
---
bd3b80
 scipy/spatial/ckdtree.pyx | 18 +++++++++---------
bd3b80
 1 file changed, 9 insertions(+), 9 deletions(-)
bd3b80
bd3b80
diff --git a/scipy/spatial/ckdtree.pyx b/scipy/spatial/ckdtree.pyx
bd3b80
index e2eea8c9097..884d49e1d34 100644
bd3b80
--- a/scipy/spatial/ckdtree.pyx
bd3b80
+++ b/scipy/spatial/ckdtree.pyx
bd3b80
@@ -190,7 +190,7 @@ cdef class coo_entries:
bd3b80
         res_dtype = np.dtype(_dtype, align = True)
bd3b80
         n = <np.intp_t> self.buf.size()
bd3b80
         if NPY_LIKELY(n > 0):
bd3b80
-            pr = &self.buf.front()
bd3b80
+            pr = self.buf.data()
bd3b80
             uintptr = <np.uintp_t> (<void*> pr)
bd3b80
             dtype = np.dtype(np.uint8)
bd3b80
             self.__array_interface__ = dict(
bd3b80
@@ -213,7 +213,7 @@ cdef class coo_entries:
bd3b80
             dict res_dict
bd3b80
         n = <np.intp_t> self.buf.size()
bd3b80
         if NPY_LIKELY(n > 0):
bd3b80
-            pr = &self.buf.front()
bd3b80
+            pr = self.buf.data()
bd3b80
             res_dict = dict()
bd3b80
             for k in range(n):
bd3b80
                 i = pr[k].i
bd3b80
@@ -263,7 +263,7 @@ cdef class ordered_pairs:
bd3b80
             np.intp_t n
bd3b80
         n = <np.intp_t> self.buf.size()
bd3b80
         if NPY_LIKELY(n > 0):
bd3b80
-            pr = &self.buf.front()
bd3b80
+            pr = self.buf.data()
bd3b80
             uintptr = <np.uintp_t> (<void*> pr)
bd3b80
             dtype = np.dtype(np.intp)
bd3b80
             self.__array_interface__ = dict(
bd3b80
@@ -284,7 +284,7 @@ cdef class ordered_pairs:
bd3b80
             np.intp_t i, n
bd3b80
             set results
bd3b80
         results = set()
bd3b80
-        pair = &self.buf.front()
bd3b80
+        pair = self.buf.data()
bd3b80
         n = <np.intp_t> self.buf.size()
bd3b80
         if sizeof(long) < sizeof(np.intp_t):
bd3b80
             # Needed for Python 2.x on Win64
bd3b80
@@ -593,7 +593,7 @@ cdef class cKDTree:
bd3b80
         cself = self.cself
bd3b80
         # finalize the tree points, this calls _post_init_traverse
bd3b80
 
bd3b80
-        cself.ctree = &cself.tree_buffer.front()
bd3b80
+        cself.ctree = cself.tree_buffer.data()
bd3b80
 
bd3b80
         # set the size attribute after tree_buffer is built
bd3b80
         cself.size = cself.tree_buffer.size()
bd3b80
@@ -971,7 +971,7 @@ cdef class cKDTree:
bd3b80
                     m = <np.intp_t> (vvres[i].size())
bd3b80
                     tmp = m * [None]
bd3b80
 
bd3b80
-                    cur = &vvres[i].front()
bd3b80
+                    cur = vvres[i].data()
bd3b80
                     for j in range(m):
bd3b80
                         tmp[j] = cur[0]
bd3b80
                         cur += 1
bd3b80
@@ -1067,7 +1067,7 @@ cdef class cKDTree:
bd3b80
                     tmp = m * [None]
bd3b80
                     with nogil:
bd3b80
                         sort(vvres[i].begin(), vvres[i].end())
bd3b80
-                    cur = &vvres[i].front()
bd3b80
+                    cur = vvres[i].data()
bd3b80
                     for j in range(m):
bd3b80
                         tmp[j] = cur[0]
bd3b80
                         cur += 1
bd3b80
@@ -1492,7 +1492,7 @@ cdef class cKDTree:
bd3b80
         cdef ckdtree * cself = self.cself
bd3b80
         size = cself.tree_buffer.size() * sizeof(ckdtreenode)
bd3b80
 
bd3b80
-        cdef np.ndarray tree = np.asarray(<char[:size]> <char*> &cself.tree_buffer.front())
bd3b80
+        cdef np.ndarray tree = np.asarray(<char[:size]> <char*> cself.tree_buffer.data())
bd3b80
 
bd3b80
         state = (tree.copy(), self.data.copy(), self.n, self.m, self.leafsize,
bd3b80
                       self.maxes, self.mins, self.indices.copy(),
bd3b80
@@ -1511,7 +1511,7 @@ cdef class cKDTree:
bd3b80
         cself.tree_buffer = new vector[ckdtreenode]()
bd3b80
         cself.tree_buffer.resize(tree.size // sizeof(ckdtreenode))
bd3b80
 
bd3b80
-        mytree = np.asarray(<char[:tree.size]> <char*> &cself.tree_buffer.front())
bd3b80
+        mytree = np.asarray(<char[:tree.size]> <char*> cself.tree_buffer.data())
bd3b80
 
bd3b80
         # set raw pointers
bd3b80
         self._pre_init()
bd3b80
bd3b80
From ad0f91438f49bfe277e32d2689aefeb0c11c789f Mon Sep 17 00:00:00 2001
bd3b80
From: Pauli Virtanen <pav@iki.fi>
bd3b80
Date: Wed, 31 Jul 2019 23:41:40 +0300
bd3b80
Subject: [PATCH 2/2] BLD: spatial: set c++ std flags for ckdtree
bd3b80
bd3b80
---
bd3b80
 scipy/spatial/setup.py | 11 ++++++++++-
bd3b80
 1 file changed, 10 insertions(+), 1 deletion(-)
bd3b80
bd3b80
diff --git a/scipy/spatial/setup.py b/scipy/spatial/setup.py
bd3b80
index d7e334876df..19d78593c5e 100644
bd3b80
--- a/scipy/spatial/setup.py
bd3b80
+++ b/scipy/spatial/setup.py
bd3b80
@@ -4,6 +4,13 @@
bd3b80
 import glob
bd3b80
 
bd3b80
 
bd3b80
+def pre_build_hook(build_ext, ext):
bd3b80
+    from scipy._build_utils.compiler_helper import get_cxx_std_flag
bd3b80
+    std_flag = get_cxx_std_flag(build_ext._cxx_compiler)
bd3b80
+    if std_flag is not None:
bd3b80
+        ext.extra_compile_args.append(std_flag)
bd3b80
+
bd3b80
+
bd3b80
 def configuration(parent_package='', top_path=None):
bd3b80
     from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
bd3b80
     from numpy.distutils.misc_util import get_info as get_misc_info
bd3b80
@@ -55,10 +62,12 @@ def configuration(parent_package='', top_path=None):
bd3b80
     ckdtree_headers = [join('ckdtree', 'src', x) for x in ckdtree_headers]
bd3b80
 
bd3b80
     ckdtree_dep = ['ckdtree.cxx'] + ckdtree_headers + ckdtree_src
bd3b80
-    config.add_extension('ckdtree',
bd3b80
+    ext = config.add_extension('ckdtree',
bd3b80
                          sources=['ckdtree.cxx'] + ckdtree_src,
bd3b80
                          depends=ckdtree_dep,
bd3b80
                          include_dirs=inc_dirs + [join('ckdtree', 'src')])
bd3b80
+    ext._pre_build_hook = pre_build_hook
bd3b80
+
bd3b80
     # _distance_wrap
bd3b80
     config.add_extension('_distance_wrap',
bd3b80
                          sources=[join('src', 'distance_wrap.c')],