To clarify: my patch applies cleanly to current CVS.
Ah, but the one in the BTS appears to be out of date.
I attach the patch I have.
Binary files grep/src/egrep and grep-dlopen-pcre/src/egrep differ
Binary files grep/src/egrep.o and grep-dlopen-pcre/src/egrep.o differ
Binary files grep/src/fgrep and grep-dlopen-pcre/src/fgrep differ
Binary files grep/src/fgrep.o and grep-dlopen-pcre/src/fgrep.o differ
Binary files grep/src/grep and grep-dlopen-pcre/src/grep differ
Binary files grep/src/grep.o and grep-dlopen-pcre/src/grep.o differ
diff -Nur --exclude=CVS --exclude='*.pot' --exclude='*.Po' grep/src/search.c grep-dlopen-pcre/src/search.c
--- grep/src/search.c 2007-07-18 23:59:36.000000000 +0100
+++ grep-dlopen-pcre/src/search.c 2008-04-30 20:25:38.000000000 +0100
@@ -41,6 +41,7 @@
#include "error.h"
#include "xalloc.h"
#ifdef HAVE_LIBPCRE
+# include <dlfcn.h>
# include <pcre.h>
#endif
@@ -84,6 +85,35 @@
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("libpcre.so",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 +657,9 @@
char const *p;
char const *pnul;
+ if (map_pcre ())
+ error (2, 0, _("The -P option is not supported"));
+
/* FIXME: Remove these restrictions. */
if (eolbyte != '\n')
error (2, 0, _("The -P and -z options cannot be combined"));
@@ -667,11 +700,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 +722,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 = pcre_exec (cre, extra, buf, size,
+ start_ptr ? (start_ptr - buf) : 0, 0,
+ sub, sizeof sub / sizeof *sub);
if (e <= 0)
{
Binary files grep/src/search.o and grep-dlopen-pcre/src/search.o differ