All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: cocci@inria.fr
Subject: [cocci] [PATCH v1] replace pcre with pcre2
Date: Mon, 17 Mar 2025 16:08:17 +0100	[thread overview]
Message-ID: <20250317150941.32415-1-olaf@aepfle.de> (raw)

Since pcre is unmaintained, I was asked to remove usage of ocaml-pcre.

This is the minimal change to use ocaml-pcre2. The question is what kind
of change the maintainers want to see here. There are 5 possible
variantes to support regular expressions: Str.regex, Pcre, Pcre2, Re and
Re2.

This patch just exchanges one with another. Would there be some benefit to
support all five in a single binary, for correctness and/or performance
comparison?

Please let me know how to proceed.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 Makefile               |  6 +++---
 Makefile.config.in     | 18 +++++++++---------
 Makefile.libs          | 18 +++++++++---------
 configure.ac           | 14 +++++++-------
 globals/regexp_pcre.ml | 10 +++++-----
 5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/Makefile b/Makefile
index 55dbe849a..0c45127bd 100644
--- a/Makefile
+++ b/Makefile
@@ -101,7 +101,7 @@ PREFIX_spgen := tools/spgen/source/
 CORE_LIBS := unix str ocamlcommon \
 	$(STDCOMPATDIR)/stdcompat \
 	$(patsubst %,bytes,$(BYTESDIR)) \
-	$(patsubst %,pcre,$(filter %/pcre.cma,$(LNKLIBS)))
+	$(patsubst %,pcre2,$(filter %/pcre2.cma,$(LNKLIBS)))
 
 ifeq ($(OCAMLATLEAST50),no)
 CORE_LIBS += bigarray
@@ -121,7 +121,7 @@ LIBRARIES_spatch := $(LIBRARIES)
 
 LIBRARIES_spgen := $(CORE_LIBRARIES)
 
-CORE_BUNDLES=stdcompat menhirLib pcre
+CORE_BUNDLES=stdcompat menhirLib pcre2
 
 ALL_BUNDLES=$(CORE_BUNDLES) parmap pyml
 
@@ -214,7 +214,7 @@ MENHIR_LIB := \
 	$(addsuffix /menhirLib$(LIBSUFFIX),$(filter %/menhirLib,$(MAKELIBS)))
 PARMAP_LIB := $(addsuffix /parmap$(LIBSUFFIX),$(filter %/parmap,$(MAKELIBS)))
 PYML_LIB := $(addsuffix /pyml$(LIBSUFFIX),$(filter %/pyml,$(MAKELIBS)))
-PCRE_LIB := $(addsuffix /pcre$(LIBSUFFIX),$(filter %/pcre,$(MAKELIBS)))
+PCRE_LIB := $(addsuffix /pcre2$(LIBSUFFIX),$(filter %/pcre2,$(MAKELIBS)))
 STDCOMPAT_LIB := $(STDCOMPATDIR)/stdcompat$(LIBSUFFIX)
 
 STDCOMPAT_USERS := parsing_c/type_annoter_c cocci parsing_cocci/check_meta \
diff --git a/Makefile.config.in b/Makefile.config.in
index dbafa35a5..6bad1a7a6 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -5,18 +5,18 @@
 VERSION=@PACKAGE_VERSION@
 
 # * for each library $1, add another entry in the same manner
-MAKELIBS=@MAKE_dynlink@ @MAKE_menhirLib@ @MAKE_pyml@ @MAKE_pcre@ \
+MAKELIBS=@MAKE_dynlink@ @MAKE_menhirLib@ @MAKE_pyml@ @MAKE_pcre2@ \
   @MAKE_parmap@
-LNKLIBS=@MODULES_dynlink@ @MODULES_menhirLib@ @MODULES_pcre@ @MODULES_pyml@ \
+LNKLIBS=@MODULES_dynlink@ @MODULES_menhirLib@ @MODULES_pcre2@ @MODULES_pyml@ \
   @MODULES_parmap@
 OPTLNKLIBS=@MODULESOPT_dynlink@ @MODULESOPT_menhirLib@ @MODULESOPT_pyml@ \
-  @MODULESOPT_pcre@ @MODULESOPT_parmap@
-INCLIBS=@PATH_dynlink@ @PATH_menhirLib@ @PATH_pyml@ @PATH_pcre@ \
+  @MODULESOPT_pcre2@ @MODULESOPT_parmap@
+INCLIBS=@PATH_dynlink@ @PATH_menhirLib@ @PATH_pyml@ @PATH_pcre2@ \
   @PATH_parmap@
-FLAGSLIBS=@FLAGS_dynlink@ @FLAGS_menhirLib@ @FLAGS_pyml@ @FLAGS_pcre@ \
+FLAGSLIBS=@FLAGS_dynlink@ @FLAGS_menhirLib@ @FLAGS_pyml@ @FLAGS_pcre2@ \
   @FLAGS_parmap@
 OPTFLAGSLIBS=@OPTFLAGS_dynlink@ @OPTFLAGS_menhirLib@ @OPTFLAGS_pyml@ \
-  @OPTFLAGS_pcre@ @OPTFLAGS_parmap@
+  @OPTFLAGS_pcre2@ @OPTFLAGS_parmap@
 # * end of library variables
 
 # system packages inc libs
@@ -106,7 +106,7 @@ METAINFO_DIR=@METAINFO_DIR@
 
 # selected libraries
 FEATURE_menhirLib=@FEATURE_menhirLib@
-FEATURE_pcre=@FEATURE_pcre@
+FEATURE_pcre=@FEATURE_pcre2@
 
 # Features
 FEATURE_PYTHON=@FEATURE_PYTHON@
@@ -114,7 +114,7 @@ FEATURE_OCAML=@FEATURE_OCAML@
 NO_OCAMLFIND=@SUBSTITUTED_OCAMLFIND@
 
 # Include paths
-PCREDIR=@PATH_pcre@
+PCREDIR=@PATH_pcre2@
 PARMAPDIR=@PATH_parmap@
 PYMLDIR=@PATH_pyml@
 MENHIRDIR=@PATH_menhirLib@
@@ -129,4 +129,4 @@ REGEXP_FILE=@REGEXP_FILE@
 
 MENHIR_FLAGS=@DEFAULT_MENHIR_FLAGS@
 
-OCAMLATLEAST50=@OCAMLATLEAST50@
\ No newline at end of file
+OCAMLATLEAST50=@OCAMLATLEAST50@
diff --git a/Makefile.libs b/Makefile.libs
index 96e05d26f..ed6ce302f 100644
--- a/Makefile.libs
+++ b/Makefile.libs
@@ -36,15 +36,15 @@ OPTFLAGS_pyml  = $(CFLAGS_pyml:%=-ccopt %) -cclib -lpyml_stubs
 
 # pcre library
 # Note: see the comment of the pycaml library about the double appearance of the stubs library.
-LOCAL_pcre     = $(BYTESDIR:=/bytes.cma) $(PCREDIR)/pcre.cma
-LOCALOPT_pcre  = $(BYTESDIR:=/bytes.cmxa) $(PCREDIR)/pcre.cmxa
-GLOBAL_pcre    = $(BYTESDIR:=/bytes.cma) $(PCREDIR)/pcre.cma
-GLOBALOPT_pcre = $(BYTESDIR:=/bytes.cmxa) $(PCREDIR)/pcre.cmxa
-FLAGS_pcre     = \
-	$(PCRE_LIBS:%=-ccopt %) -cclib -L$(PCREDIR) -dllib -lpcre_stubs \
-	-cclib -lpcre_stubs
-OPTFLAGS_pcre  = \
-	$(PCRE_LIBS:%=-ccopt %) -cclib -L$(PCREDIR) -cclib -lpcre_stubs
+LOCAL_pcre2     = $(BYTESDIR:=/bytes.cma) $(PCREDIR)/pcre2.cma
+LOCALOPT_pcre2  = $(BYTESDIR:=/bytes.cmxa) $(PCREDIR)/pcre2.cmxa
+GLOBAL_pcre2    = $(BYTESDIR:=/bytes.cma) $(PCREDIR)/pcre2.cma
+GLOBALOPT_pcre2 = $(BYTESDIR:=/bytes.cmxa) $(PCREDIR)/pcre2.cmxa
+FLAGS_pcre2     = \
+	$(PCRE_LIBS:%=-ccopt %) -cclib -L$(PCREDIR) -dllib -lpcre2_stubs \
+	-cclib -lpcre2_stubs
+OPTFLAGS_pcre2  = \
+	$(PCRE_LIBS:%=-ccopt %) -cclib -L$(PCREDIR) -cclib -lpcre2_stubs
 
 # dynlink library
 LOCAL_dynlink     =
diff --git a/configure.ac b/configure.ac
index f0c585329..234d46fb4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,7 +145,7 @@ dnl  add a line for each package that is
 dnl  configured via AC_CHECK_COCCI_EXTPKG
 dnl  or AC_REQ_COCCI_EXTPKG
 AC_COCCI_INIT_PKG_EMPTY([dynlink])
-AC_COCCI_INIT_PKG_EMPTY([pcre])
+AC_COCCI_INIT_PKG_EMPTY([pcre2])
 AC_COCCI_INIT_PKG_EMPTY([bytes]) dnl for recent versions of pcre on old OCaml
 AC_COCCI_INIT_PKG_EMPTY([pyml])
 AC_COCCI_INIT_PKG_EMPTY([stdcompat])
@@ -369,18 +369,18 @@ dnl    OCAML_PKG_pcre: if "local" use str package
 AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)]))
 AS_IF([test "x$enable_pcre_syntax" != "xno"],
 [dnl
-  PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])])
+  PKG_CHECK_MODULES([PCRE], [libpcre2-8],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])])
   AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes],
   [dnl
     AC_SUBST([enable_pcre_syntax], [no])
   ],
   [dnl
     AS_IF([test "x$enable_pcre" = "xno"], [AC_SUBST([enable_pcre], [local])])
-    AC_CHECK_COCCI_EXTPKG([pcre])  dnl  will set $enable_pcre to 'yes', 'no', or 'local'
+    AC_CHECK_COCCI_EXTPKG([pcre2])  dnl  will set $enable_pcre to 'yes', 'no', or 'local'
     AS_IF([test "x$enable_pcre" = "xyes"],
     [dnl
       AC_MSG_CHECKING([if pcre depends on bytes])
-      AS_IF([test "x`$OCAMLFIND query -r -format '%p' pcre 2>/dev/null | grep bytes`" = "xbytes"],
+      AS_IF([test "x`$OCAMLFIND query -r -format '%p' pcre2 2>/dev/null | grep bytes`" = "xbytes"],
       [dnl
         AC_MSG_RESULT([yes])
         AC_MSG_CHECKING([if bytes is an actual module])
@@ -407,14 +407,14 @@ AS_IF([test "x$enable_pcre_syntax" != xno],
     AC_MSG_NOTICE([support for pcre syntax is enabled])
   ],
   [dnl
-    AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found])
+    AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre2-8 library is not found])
   ])
 
   AC_SUBST([REGEXP_MODULE], [Regexp_pcre])
   AC_SUBST([REGEXP_FILE], [regexp_pcre.ml])
 ],
 [dnl
-  AC_COCCI_INIT_PKG_EMPTY([pcre])
+  AC_COCCI_INIT_PKG_EMPTY([pcre2])
   AC_SUBST([REGEXP_MODULE], [Regexp_str])
   AC_SUBST([REGEXP_FILE], [regexp_str.ml])
 ])
@@ -571,7 +571,7 @@ AS_IF([test "$MAKE_stdcompat"],
 AS_IF([test "$MAKE_parmap"],
   AC_CONFIG_SUBDIRS(bundles/parmap))
 
-AS_IF([test "$MAKE_pcre"],
+AS_IF([test "$MAKE_pcre2"],
   [AS_IF([test "x$OCAMLATLEAST4030" = xno  ],
     [AC_SUBST([CAMLnoreturn_start], [])
      AC_SUBST([CAMLnoreturn_end], [])],
diff --git a/globals/regexp_pcre.ml b/globals/regexp_pcre.ml
index d09f8528f..4fa1b61b5 100644
--- a/globals/regexp_pcre.ml
+++ b/globals/regexp_pcre.ml
@@ -5,7 +5,7 @@
  *)
 
 type regexp =
-    Pcre of int (* Pcre.regexp *)
+    Pcre2 of int (* Pcre2.regexp *)
   | Str of Str.regexp
 
 (* A table is used because PCRE regular expressions are not comparable.
@@ -26,16 +26,16 @@ let regexp string =
     begin
       let c = !pcre_ctr in
       pcre_ctr := !pcre_ctr + 1;
-      Hashtbl.add pcre_table c (Pcre.regexp string);
-      Pcre c
+      Hashtbl.add pcre_table c (Pcre2.regexp string);
+      Pcre2 c
     end
   else Str (Str.regexp string)
 
 let string_match regexp string =
   match regexp with
-      Pcre regexp ->
+      Pcre2 regexp ->
 	let regexp = Hashtbl.find pcre_table regexp in
-	Pcre.pmatch ~rex:regexp string
+	Pcre2.pmatch ~rex:regexp string
     | Str regexp ->
       try
 	ignore(Str.search_forward regexp string 0);

base-commit: cca22217d1b4316224e80a18d0b08dd351234497

             reply	other threads:[~2025-03-17 15:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 15:08 Olaf Hering [this message]
2025-03-17 16:17 ` [cocci] [PATCH] replace pcre with pcre2 Markus Elfring
2025-03-17 17:26 ` Markus Elfring
2025-03-17 17:44   ` Olaf Hering
2025-03-17 22:24   ` Olaf Hering
2025-03-18 10:55     ` [cocci] " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250317150941.32415-1-olaf@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=cocci@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.