fix build with reentrant qhull

https://salsa.debian.org/science-team/plplot/-/blob/master/debian/patches/reentrant-qhull.patch

Index: src/plgridd.c
--- src/plgridd.c.orig
+++ 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_VECT
         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_VECT
 #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_VECT
                     // 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_VECT
                     {
                         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_VECT
                     }
                 }
         }
-        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",
