From e0d39a9133e1507345d73ac5aff85f037f39aa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Fri, 12 Nov 2021 16:45:04 -0800 Subject: grep: migrate to pcre2 Mostly a bug by bug translation of the original code to the PCRE2 API. Code still could do with some optimizations but should be good as a starting point. The API changes the sign of some types and therefore some ugly casts were needed, some of the changes are just to make sure all variables fit into the newer types better. Includes backward compatibility and could be made to build all the way to 10.00, but assumes a recent enough version and has been tested with 10.23 (from CentOS 7, the oldest). Performance seems equivalent, and it also seems functionally complete. * m4/pcre.m4 (gl_FUNC_PCRE): Check for PCRE2, not the original PCRE. * src/pcresearch.c (struct pcre_comp, jit_exec) (Pcompile, Pexecute): Use PCRE2, not the original PCRE. * tests/filename-lineno.pl: Adjust to match PCRE2 diagnostics. --- m4/pcre.m4 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'm4') diff --git a/m4/pcre.m4 b/m4/pcre.m4 index 78b7fda7..a1c6c824 100644 --- a/m4/pcre.m4 +++ b/m4/pcre.m4 @@ -1,4 +1,4 @@ -# pcre.m4 - check for libpcre support +# pcre.m4 - check for PCRE library support # Copyright (C) 2010-2021 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -9,7 +9,7 @@ AC_DEFUN([gl_FUNC_PCRE], [ AC_ARG_ENABLE([perl-regexp], AS_HELP_STRING([--disable-perl-regexp], - [disable perl-regexp (pcre) support]), + [disable perl-regexp (pcre2) support]), [case $enableval in yes|no) test_pcre=$enableval;; *) AC_MSG_ERROR([invalid value $enableval for --disable-perl-regexp]);; @@ -21,24 +21,25 @@ AC_DEFUN([gl_FUNC_PCRE], use_pcre=no if test $test_pcre != no; then - PKG_CHECK_MODULES([PCRE], [libpcre], [], [: ${PCRE_LIBS=-lpcre}]) + PKG_CHECK_MODULES([PCRE], [libpcre2-8], [], [: ${PCRE_LIBS=-lpcre2-8}]) - AC_CACHE_CHECK([for pcre_compile], [pcre_cv_have_pcre_compile], + AC_CACHE_CHECK([for pcre2_compile], [pcre_cv_have_pcre2_compile], [pcre_saved_CFLAGS=$CFLAGS pcre_saved_LIBS=$LIBS CFLAGS="$CFLAGS $PCRE_CFLAGS" LIBS="$PCRE_LIBS $LIBS" AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[#include + [AC_LANG_PROGRAM([[#define PCRE2_CODE_UNIT_WIDTH 8 + #include ]], - [[pcre *p = pcre_compile (0, 0, 0, 0, 0); + [[pcre2_code *p = pcre2_compile (0, 0, 0, 0, 0, 0); return !p;]])], - [pcre_cv_have_pcre_compile=yes], - [pcre_cv_have_pcre_compile=no]) + [pcre_cv_have_pcre2_compile=yes], + [pcre_cv_have_pcre2_compile=no]) CFLAGS=$pcre_saved_CFLAGS LIBS=$pcre_saved_LIBS]) - if test "$pcre_cv_have_pcre_compile" = yes; then + if test "$pcre_cv_have_pcre2_compile" = yes; then use_pcre=yes elif test $test_pcre = maybe; then AC_MSG_WARN([AC_PACKAGE_NAME will be built without pcre support.]) @@ -50,7 +51,7 @@ AC_DEFUN([gl_FUNC_PCRE], if test $use_pcre = yes; then AC_DEFINE([HAVE_LIBPCRE], [1], [Define to 1 if you have the Perl Compatible Regular Expressions - library (-lpcre).]) + library (-lpcre2).]) else PCRE_CFLAGS= PCRE_LIBS= -- cgit v1.2.1