File 0001-Use-reentrant-libqhull_r-instead-of-deprecated-libqh.patch of Package plplot

From 07c5fb9d551dd04dd1d4e9e287c3901b7353b948 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Sun, 4 Apr 2021 15:56:15 +0200
Subject: [PATCH] Use reentrant libqhull_r instead of deprecated libqhull

The non-reentrant version has been deprecated by upstream and is no longer
built by default.

The reentrant version is available since qhull 2015.1. As the old-style
qhull/* headers were removed with qhull 2011.1 these are no longer
relevant.
---
 cmake/modules/FindQHULL.cmake | 14 +++++++-------
 cmake/modules/csiro.cmake     |  6 +-----
 lib/nn/delaunay.c             | 21 ++++++++++-----------
 src/CMakeLists.txt            |  4 ++--
 src/plgridd.c                 | 27 +++++++++++++--------------
 5 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/cmake/modules/FindQHULL.cmake b/cmake/modules/FindQHULL.cmake
index d5485ed..ba8c7aa 100644
--- a/cmake/modules/FindQHULL.cmake
+++ b/cmake/modules/FindQHULL.cmake
@@ -16,27 +16,27 @@ include(FindPackageHandleStandardArgs)
 # that is what is supplied by upstream qhull, and if the user is
 # finding a local install of the upstream library below, he wants to
 # access that same upstream version of the headers to be consistent.
-find_file(QHULL_HEADER_FILE NAMES libqhull/qhull_a.h qhull/qhull_a.h)
+find_file(QHULL_HEADER_FILE NAMES libqhull_r/qhull_ra.h)
 if(QHULL_HEADER_FILE)
   # message(STATUS "QHULL_HEADER_FILE = ${QHULL_HEADER_FILE}")
-  if(QHULL_HEADER_FILE MATCHES "libqhull")
+  if(QHULL_HEADER_FILE MATCHES "libqhull_r")
     set(HAS_LIBQHULL_INCLUDE ON)
-  else(QHULL_HEADER_FILE MATCHES "libqhull")
+  else()
     set(HAS_LIBQHULL_INCLUDE OFF)
-  endif(QHULL_HEADER_FILE MATCHES "libqhull")
+  endif()
   # Determine grandparent directory of header file
   get_filename_component(QHULL_INCLUDE_DIRS ${QHULL_HEADER_FILE} DIRECTORY)
   get_filename_component(QHULL_INCLUDE_DIRS ${QHULL_INCLUDE_DIRS} DIRECTORY)
 elseif(NOT QHULL_HEADER_FILE AND NOT QHULL_FIND_QUIETLY)
-  message(STATUS "Neither qhull/qhull_a.h header nor libqhull/qhull_a.h could be found")
+  message(STATUS "libqhull_r/qhull_ra.h could not be found")
 endif(QHULL_HEADER_FILE)
 
-find_library(QHULL_LIBRARY qhull)
+find_library(QHULL_LIBRARY qhull_r)
 if( QHULL_LIBRARY )
   get_filename_component(QHULL_LIBRARY_DIRS ${QHULL_LIBRARY} DIRECTORY)
   set(QHULL_LIBRARIES ${QHULL_LIBRARY})
 elseif(NOT QHULL_LIBRARY AND NOT QHULL_FIND_QUIETLY)
-  message(STATUS "qhull library could not be found")
+  message(STATUS "qhull_r library could not be found")
 endif(QHULL_LIBRARY)
 
 find_package_handle_standard_args(QHULL
diff --git a/cmake/modules/csiro.cmake b/cmake/modules/csiro.cmake
index cd427c4..c0df044 100644
--- a/cmake/modules/csiro.cmake
+++ b/cmake/modules/csiro.cmake
@@ -89,11 +89,7 @@ if(PL_HAVE_QHULL)
       message(STATUS "WARNING: function qh_new_qhull not found.  Setting PL_HAVE_QHULL to OFF.")
       set(PL_HAVE_QHULL OFF CACHE BOOL "Enable use of the Qhull library" FORCE)
     endif(NOT QH_NEW_EXIST)
-    if(HAS_LIBQHULL_INCLUDE)
-      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/Check_realT_size.c "#include <libqhull/qhull_a.h>")
-    else(HAS_LIBQHULL_INCLUDE)
-      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/Check_realT_size.c "#include <qhull/qhull_a.h>")
-    endif(HAS_LIBQHULL_INCLUDE)
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/Check_realT_size.c "#include <libqhull_r/qhull_ra.h>")
     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/Check_realT_size.c
       "
 int main(void)
diff --git a/lib/nn/delaunay.c b/lib/nn/delaunay.c
index f44c990..b0143c7 100644
--- a/lib/nn/delaunay.c
+++ b/lib/nn/delaunay.c
@@ -34,11 +34,7 @@
 #include <limits.h>
 #include <float.h>
 #ifdef USE_QHULL
-#ifdef HAS_LIBQHULL_INCLUDE
-#include <libqhull/qhull_a.h>
-#else
-#include <qhull/qhull_a.h>
-#endif
+#include <libqhull_r/qhull_ra.h>
 #else
 #include "triangle.h"
 #endif
@@ -388,7 +384,10 @@ delaunay* delaunay_build( int np, point points[], int ns, int segments[], int nh
     // climax
     //
 
-    exitcode = qh_new_qhull( dim, np, qpoints, ismalloc,
+    qhT context = { 0 };
+    qhT* qh = &context;
+
+    exitcode = qh_new_qhull( qh, dim, np, qpoints, ismalloc,
         flags, outfile, errfile );
 
     if ( !exitcode )
@@ -433,8 +432,8 @@ delaunay* delaunay_build( int np, point points[], int ns, int segments[], int nh
             }
         }
 
-        qh_findgood_all( qh facet_list );
-        qh_countfacets( qh facet_list, NULL, !qh_ALL, &numfacets,
+        qh_findgood_all( qh, qh->facet_list );
+        qh_countfacets( qh, qh->facet_list, NULL, !qh_ALL, &numfacets,
             &numsimplicial, &totneighbors, &numridges,
             &numcoplanars, &numtricoplanars );
 
@@ -462,7 +461,7 @@ delaunay* delaunay_build( int np, point points[], int ns, int segments[], int nh
 
                 j = 0;
                 FOREACHvertex_( facet->vertices )
-                t->vids[j++] = qh_pointid( vertex->point );
+                t->vids[j++] = qh_pointid( qh, vertex->point );
 
                 j = 0;
                 FOREACHneighbor_( facet )
@@ -548,8 +547,8 @@ delaunay* delaunay_build( int np, point points[], int ns, int segments[], int nh
     }
 
     free( qpoints );
-    qh_freeqhull( !qh_ALL );               // free long memory
-    qh_memfreeshort( &curlong, &totlong ); // free short memory and memory allocator
+    qh_freeqhull( qh, !qh_ALL );               // free long memory
+    qh_memfreeshort( qh, &curlong, &totlong ); // free short memory and memory allocator
     if ( curlong || totlong )
         fprintf( errfile,
             "qhull: did not free %d bytes of long memory (%d pieces)\n",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 757b4ed..18c6016 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -259,9 +259,9 @@ if(PL_HAVE_QHULL)
   # No *.pc files for lib subdirectory libraries so must add relevant bits
   # to the plplot.pc file instead.
   if(QHULL_RPATH)
-    list(APPEND pc_libplplot_LINK_FLAGS -l${WRITEABLE_TARGET}csironn -L${QHULL_RPATH} -lqhull)
+    list(APPEND pc_libplplot_LINK_FLAGS -l${WRITEABLE_TARGET}csironn -L${QHULL_RPATH} -lqhull_r)
   else(QHULL_RPATH)
-    list(APPEND pc_libplplot_LINK_FLAGS -l${WRITEABLE_TARGET}csironn -lqhull)
+    list(APPEND pc_libplplot_LINK_FLAGS -l${WRITEABLE_TARGET}csironn -lqhull_r)
   endif(QHULL_RPATH)
 
   # Needed by plgridd.c.
diff --git a/src/plgridd.c b/src/plgridd.c
index 3982016..607e5a3 100644
--- a/src/plgridd.c
+++ b/src/plgridd.c
@@ -32,11 +32,7 @@
 #include "../lib/nn/nn.h"
 // PLPLOT_NONN not #defined or tested for more than a decade.
 #ifdef PLPLOT_NONN // another DTLI, based only on QHULL, not nn
-#ifdef HAS_LIBQHULL_INCLUDE
-#include <libqhull/qhull_a.h>
-#else //#ifdef HAS_LIBQHULL_INCLUDE
-#include <qhull/qhull_a.h>
-#endif //#ifdef HAS_LIBQHULL_INCLUDE
+#include <libqhull_r/qhull_ra.h>
 #endif //#ifdef PLPLOT_NONN
 #endif //#ifdef PL_HAVE_QHUL
 
@@ -852,8 +848,11 @@ grid_adtli( PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT_VECTOR z, int npts,
         points[i * dim + 1] = y[i];
     }
 
+    qhT context = { 0 };
+    qhT* qh = &context;
+
 #if 1 // easy way
-    exitcode = qh_new_qhull( dim, npts, points, ismalloc,
+    exitcode = qh_new_qhull( qh, dim, npts, points, ismalloc,
         flags, outfile, errfile );
 #else
     qh_init_A( stdin, stdout, stderr, 0, NULL );
@@ -899,17 +898,17 @@ grid_adtli( PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT_VECTOR z, int npts,
 #endif
 
         // Without the setjmp(), Qhull will exit() after reporting an error
-        exitcode = setjmp( qh errexit );
+        exitcode = setjmp( qh->errexit );
         if ( !exitcode )
         {
-            qh NOerrexit = False;
+            qh->NOerrexit = False;
             for ( i = 0; i < nptsx; i++ )
                 for ( j = 0; j < nptsy; j++ )
                 {
                     l        = 0;
                     point[0] = xg[i];
                     point[1] = yg[j];
-                    qh_setdelaunay( 3, 1, point );
+                    qh_setdelaunay( qh, 3, 1, point );
 
 
                     // several ways to find the triangle given a point follow.
@@ -942,7 +941,7 @@ grid_adtli( PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT_VECTOR z, int npts,
                     // Another possibility is to implement the 'walking
                     // triangle algorithm
 
-                    facet = qh_findfacet_all( point, &bestdist, &isoutside, &totpart );
+                    facet = qh_findfacet_all( qh, point, &bestdist, &isoutside, &totpart );
 
                     if ( facet->upperdelaunay )
                         zops->set( zgp, i, j, NaN );
@@ -950,7 +949,7 @@ grid_adtli( PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT_VECTOR z, int npts,
                     {
                         FOREACHvertex_( facet->vertices )
                         {
-                            k     = qh_pointid( vertex->point );
+                            k     = qh_pointid( qh, vertex->point );
                             xt[l] = x[k];
                             yt[l] = y[k];
                             zt[l] = z[k];
@@ -969,12 +968,12 @@ grid_adtli( PLFLT_VECTOR x, PLFLT_VECTOR y, PLFLT_VECTOR z, int npts,
                     }
                 }
         }
-        qh NOerrexit = True;
+        qh->NOerrexit = True;
     }
 
     free( points );
-    qh_freeqhull( !qh_ALL );               // free long memory
-    qh_memfreeshort( &curlong, &totlong ); // free short memory and memory allocator
+    qh_freeqhull( qh, !qh_ALL );               // free long memory
+    qh_memfreeshort( qh, &curlong, &totlong ); // free short memory and memory allocator
     if ( curlong || totlong )
         fprintf( errfile,
             "qhull: did not free %d bytes of long memory (%d pieces)\n",
-- 
2.30.2

openSUSE Build Service is sponsored by