On Sat, Mar 28, 2009 at 12:38:54AM +1100, Anibal Monsalve Salazar wrote:
>On Fri, Mar 27, 2009 at 02:05:25PM +0100, Marco d'Itri wrote:
>>On Mar 27, Aníbal Monsalve Salazar <ani...@debian.org> wrote:
>>>The file attached is based on your patch.
>>Removing the HAVE_LIBPCRE ifdefs looks wrong and unmaintenable, you
>>should just unconditionally define it.
>
>I'll look into that and having libpcre3-dev as a build-dependency later.
>It's late here.

The attached file is the new patch.

It has my patch to configure and a few changes to Reuben's patch.

My changes to Reuben's patch are:


-+static int map_pcre(void)
++static int
++map_pcre(void)


-+  library = dlopen("libpcre.so",RTLD_NOW);
++  library = dlopen("/usr/lib/libpcre.so.3",RTLD_NOW);


-+    error (2, 0, _("The -P option is not supported"));
++    {
++      error (2, 0, _("The -P option is not supported: dynamic loading of 
/usr/lib/libpcre.so.3 failed"));
++      return -1;
++    }


-+  e = pcre_exec (cre, extra, buf, size,
++  e = dl_pcre_exec (cre, extra, buf, size,
--- a/configure	2009-02-10 15:35:29.000000000 +1100
+++ b/configure	2009-03-26 20:50:05.000000000 +1100
@@ -10623,10 +10623,6 @@
 
 # support for pcre
 if test x"$testpcre" = x"yes"; then
-	if pcre-config --cflags >/dev/null 2>&1; then
-		CPPFLAGS="$CPPFLAGS `pcre-config --cflags`"
-		LIBS="$LIBS `pcre-config --libs`"
-	fi
 
 { echo "$as_me:$LINENO: checking for pcre_exec in -lpcre" >&5
 echo $ECHO_N "checking for pcre_exec in -lpcre... $ECHO_C" >&6; }
@@ -10685,8 +10681,8 @@
 
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
 fi
+LIBS=$ac_check_lib_save_LIBS
 { echo "$as_me:$LINENO: result: $ac_cv_lib_pcre_pcre_exec" >&5
 echo "${ECHO_T}$ac_cv_lib_pcre_pcre_exec" >&6; }
 if test $ac_cv_lib_pcre_pcre_exec = yes; then
@@ -10694,7 +10690,7 @@
 #define HAVE_LIBPCRE 1
 _ACEOF
 
-  LIBS="-lpcre $LIBS"
+  LIBS="-ldl $LIBS"
 
 fi
 
--- a/src/search.c	2009-01-31 16:39:54.000000000 +1100
+++ b/src/search.c	2009-03-27 17:04:15.000000000 +1100
@@ -41,6 +41,7 @@
 #include "error.h"
 #include "xalloc.h"
 #ifdef HAVE_LIBPCRE
+# include <dlfcn.h>
 # include <pcre.h>
 #endif
 
@@ -84,6 +85,34 @@
 struct patterns *patterns;
 size_t pcount;
 
+static pcre *(*dl_pcre_compile)(const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr);
+static pcre_extra *(*dl_pcre_study)(const pcre *code, int options, const char **errptr);
+static int (*dl_pcre_exec)(const pcre *code, const pcre_extra *extra, const char *subject, int length, int startoffset, int options, int *ovector, int ovecsize);
+static const unsigned char *(*dl_pcre_maketables)(void);
+
+static int
+map_pcre(void)
+{
+  static int library_mapped = 0;
+  void *library;
+
+  if (library_mapped) return 0;
+
+  library = dlopen("/usr/lib/libpcre.so.3",RTLD_NOW);
+
+  if (!(dl_pcre_compile = dlsym(library,"pcre_compile")))
+    return -1;
+  if (!(dl_pcre_study = dlsym(library,"pcre_study")))
+    return -1;
+  if (!(dl_pcre_exec = dlsym(library,"pcre_exec")))
+    return -1;
+  if (!(dl_pcre_maketables = dlsym(library,"pcre_maketables")))
+    return -1;
+
+  library_mapped++;
+  return 0;
+}
+
 void
 dfaerror (char const *mesg)
 {
@@ -627,6 +656,12 @@
   char const *p;
   char const *pnul;
 
+  if (map_pcre ())
+    {
+      error (2, 0, _("The -P option is not supported: dynamic loading of /usr/lib/libpcre.so.3 failed"));
+      return -1;
+    }
+
   /* FIXME: Remove these restrictions.  */
   if (eolbyte != '\n')
     error (2, 0, _("The -P and -z options cannot be combined"));
@@ -667,11 +702,11 @@
   if (match_lines)
     strcpy (n, ")$");
 
-  cre = pcre_compile (re, flags, &ep, &e, pcre_maketables ());
+  cre = dl_pcre_compile (re, flags, &ep, &e, dl_pcre_maketables ());
   if (!cre)
     error (2, 0, ep);
 
-  extra = pcre_study (cre, 0, &ep);
+  extra = dl_pcre_study (cre, 0, &ep);
   if (ep)
     error (2, 0, ep);
 
@@ -689,9 +724,17 @@
      is just for performance improvement in pcre_exec.  */
   int sub[300];
 
-  int e = pcre_exec (cre, extra, buf, size,
-		     start_ptr ? (start_ptr - buf) : 0, 0,
-		     sub, sizeof sub / sizeof *sub);
+  int e;
+
+  if (map_pcre ())
+    {
+      abort ();
+      return -1;
+    }
+
+  e = dl_pcre_exec (cre, extra, buf, size,
+                 start_ptr ? (start_ptr - buf) : 0, 0,
+                 sub, sizeof sub / sizeof *sub);
 
   if (e <= 0)
     {

Attachment: signature.asc
Description: Digital signature

Reply via email to