From f46d7f4289c1388aaa967dbb87967bbc1338d411 Mon Sep 17 00:00:00 2001 From: Yavor Doganov Date: Sat, 13 Apr 2024 12:16:23 +0200 Subject: [PATCH 1/3] Problem: depends on obsolete PCRE library Solution: port to PCRE2 Link: https://bugs.debian.org/1000118 --- src/Makefile | 4 +-- src/ggpcre.c | 70 ++++++++++++++++++++++++++---------------------- src/ggpcre.gxl | 72 ++++++++++++++++++++++++++++---------------------- 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/src/Makefile b/src/Makefile index 3d809db..b4a54b4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -50,9 +50,7 @@ LIB = .a EXE = DBG = CC = ./c -q -export CCLIBS = -lpcre - -CPPFLAGS ?= -I/usr/include/pcre +export CCLIBS = -lpcre2-8 # Reset the suffixes that will be considered to just our own list. # diff --git a/src/ggpcre.c b/src/ggpcre.c index 304d8c3..b917ce8 100644 --- a/src/ggpcre.c +++ b/src/ggpcre.c @@ -51,7 +51,8 @@ CLASS_DESCRIPTOR regexp_functions, tblsize (regexp_functions) }; -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include static int @@ -86,13 +87,17 @@ regexp_match (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THR { GGCODE_TCB *tcb = gsl_thread-> tcb; - pcre + pcre2_code *re; + pcre2_match_data + *md; char *error; - int + int + errcode; + size_t erroffset; - int + size_t *ovector; int oveccount, @@ -103,47 +108,50 @@ regexp_match (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THR VALUE value; - re = pcre_compile (string_value (&pattern-> value), - 0, - (const char **) &error, - &erroffset, - NULL); + re = pcre2_compile ((PCRE2_SPTR) string_value (&pattern-> value), + PCRE2_ZERO_TERMINATED, + 0, + &errcode, + &erroffset, + NULL); if (! re) { + PCRE2_UCHAR buf[120]; + + pcre2_get_error_message (errcode, buf, sizeof(buf)); snprintf (object_error, LINE_MAX, "Regular expression pattern error: %s\n%s\n%*c", - error, + buf, pattern-> value. s, - erroffset + 1, '^'); + (int) erroffset + 1, '^'); return -1; } - rc = pcre_fullinfo (re, - NULL, - PCRE_INFO_CAPTURECOUNT, - &oveccount); + rc = pcre2_pattern_info (re, + PCRE2_INFO_CAPTURECOUNT, + &oveccount); oveccount = (oveccount + 1) * 3; - ovector = mem_alloc (oveccount * sizeof (int)); + md = pcre2_match_data_create (oveccount, NULL); string_value (&subject-> value); - rc = pcre_exec (re, - NULL, - subject-> value. s, - (int) strlen (subject-> value. s), - 0, - 0, - ovector, - oveccount); - - (pcre_free) (re); - - if (rc == PCRE_ERROR_NOMATCH) + rc = pcre2_match (re, + (PCRE2_SPTR) subject-> value. s, + strlen (subject-> value. s), + 0, + 0, + md, + NULL); + + (pcre2_code_free) (re); + ovector = pcre2_get_ovector_pointer (md); + + if (rc == PCRE2_ERROR_NOMATCH) rc = 0; else if (rc < 0) { snprintf (object_error, LINE_MAX, "Regular expression matching error: %d", rc); - mem_free (ovector); + pcre2_match_data_free (md); return -1; } else if (rc == 1) @@ -179,7 +187,7 @@ regexp_match (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THR { strncpy (object_error, error, LINE_MAX); mem_free (value.s); - mem_free (ovector); + pcre2_match_data_free (md); return -1; } destroy_value (& value); @@ -187,7 +195,7 @@ regexp_match (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THR i++; } - mem_free (ovector); + pcre2_match_data_free (md); } return 0; /* Just in case */ diff --git a/src/ggpcre.gxl b/src/ggpcre.gxl index 91c8ca8..0e1bc59 100644 --- a/src/ggpcre.gxl +++ b/src/ggpcre.gxl @@ -21,7 +21,8 @@ -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include @@ -36,13 +37,17 @@ { GGCODE_TCB *tcb = gsl_thread-> tcb; - pcre + pcre2_code *re; + pcre2_match_data + *md; char *error; - int + int + errcode; + size_t erroffset; - int + size_t *ovector; int oveccount, @@ -53,47 +58,50 @@ VALUE value; - re = pcre_compile (string_value (&pattern-> value), - 0, - (const char **) &error, - &erroffset, - NULL); + re = pcre2_compile ((PCRE2_SPTR) string_value (&pattern-> value), + PCRE2_ZERO_TERMINATED, + 0, + &errcode, + &erroffset, + NULL); if (! re) { + PCRE2_UCHAR buf[120]; + + pcre2_get_error_message (errcode, buf, sizeof(buf)); snprintf (object_error, LINE_MAX, "Regular expression pattern error: %s\n%s\n%*c", - error, + buf, pattern-> value. s, - erroffset + 1, '^'); + (int) erroffset + 1, '^'); return -1; } - rc = pcre_fullinfo (re, - NULL, - PCRE_INFO_CAPTURECOUNT, - &oveccount); + rc = pcre2_pattern_info (re, + PCRE2_INFO_CAPTURECOUNT, + &oveccount); oveccount = (oveccount + 1) * 3; - ovector = mem_alloc (oveccount * sizeof (int)); + md = pcre2_match_data_create (oveccount, NULL); string_value (&subject-> value); - rc = pcre_exec (re, - NULL, - subject-> value. s, - (int) strlen (subject-> value. s), - 0, - 0, - ovector, - oveccount); - - (pcre_free) (re); - - if (rc == PCRE_ERROR_NOMATCH) + rc = pcre2_match (re, + (PCRE2_SPTR) subject-> value. s, + strlen (subject-> value. s), + 0, + 0, + md, + NULL); + + (pcre2_code_free) (re); + ovector = pcre2_get_ovector_pointer (md); + + if (rc == PCRE2_ERROR_NOMATCH) rc = 0; - else if (rc < 0) + else if (rc < 0) { snprintf (object_error, LINE_MAX, "Regular expression matching error: %d", rc); - mem_free (ovector); + pcre2_match_data_free (md); return -1; } else if (rc == 1) @@ -129,7 +137,7 @@ { strncpy (object_error, error, LINE_MAX); mem_free (value.s); - mem_free (ovector); + pcre2_match_data_free (md); return -1; } destroy_value (& value); @@ -137,7 +145,7 @@ i++; } - mem_free (ovector); + pcre2_match_data_free (md); } From bf4e61be17683a5c0644452237aee93a804fc631 Mon Sep 17 00:00:00 2001 From: Bastian Germann Date: Sat, 20 Apr 2024 12:06:52 +0200 Subject: [PATCH 2/3] Replace pcre[3] references with pcre2 Outside of builds/msvc, replace the pcre references. --- .github/workflows/CI.yaml | 2 +- Dockerfile | 2 +- README.md | 12 ++++++------ README.txt | 12 ++++++------ ci_build.sh | 2 +- packaging/debian/control | 2 +- packaging/debian/generator-scripting-language.dsc | 2 +- .../rpm/SPECS/generator-scripting-language.spec | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index e4a6b79..5c1931f 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -13,7 +13,7 @@ jobs: include: - os: ubuntu-latest BUILD_TYPE: default - PACKAGES: libpcre3-dev + PACKAGES: libpcre2-dev env: # Set CI_TIME: true to enable build-step profiling # Set CI_TRACE: true to enable shell script tracing diff --git a/Dockerfile b/Dockerfile index d7c41f9..a856702 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER Godefroid Chapelle RUN DEBIAN_FRONTEND=noninteractive apt-get update -y -q RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes build-essential -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes libpcre3-dev +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes libpcre2-dev RUN mkdir /tmp/gsl COPY src /tmp/gsl/src diff --git a/README.md b/README.md index 003b117..44f1d35 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ The scripts that runs docker inside the container will place the script director Dependencies: -* pcre package (e.g. libpcre3-dev) +* pcre2 package (e.g. libpcre2-dev) To build from git on a UNIX-like box, and install into `/usr/local/bin`: @@ -159,11 +159,11 @@ To show command-line help: Install GNU Make and GNU Compiler. For example, with `pkg`, `pkg install gmake gcc`. Then edit `src/Makefile` and add "-lm" to `src/Makefile` where you see CCLIBS configured. It may look similar to: - export CCLIBS = -lpcre + export CCLIBS = -lpcre2-8 You want to add the math library: - export CCLIBS = -lpcre -lm + export CCLIBS = -lpcre2-8 -lm Cd to `src` and run: @@ -183,7 +183,7 @@ Install git: Install gcc's dependencies: - apt-cyg install wget gcc-g++ make diffutils libmpfr-devel libgmp-devel libmpc-devel libpcre-devel libcrypt-devel + apt-cyg install wget gcc-g++ make diffutils libmpfr-devel libgmp-devel libmpc-devel libpcre2-devel libcrypt-devel Download, Build and Install gcc: @@ -210,9 +210,9 @@ Finally build gsl: #### Building on MacOS -The modern way of building on MacOS is to make sure you have pcre installed and use brew. +The modern way of building on MacOS is to make sure you have pcre2 installed and use brew. - brew install pcre + brew install pcre2 And then build gsl as above: diff --git a/README.txt b/README.txt index c564442..b769b1b 100644 --- a/README.txt +++ b/README.txt @@ -52,7 +52,7 @@ The scripts that runs docker inside the container will place the script director Dependencies: -* pcre package (e.g. libpcre3-dev) +* pcre2 package (e.g. libpcre2-dev) To build from git on a UNIX-like box, and install into `/usr/local/bin`: @@ -73,11 +73,11 @@ To show command-line help: Install GNU Make and GNU Compiler. For example, with `pkg`, `pkg install gmake gcc`. Then edit `src/Makefile` and add "-lm" to `src/Makefile` where you see CCLIBS configured. It may look similar to: - export CCLIBS = -lpcre + export CCLIBS = -lpcre2-8 You want to add the math library: - export CCLIBS = -lpcre -lm + export CCLIBS = -lpcre2-8 -lm Cd to `src` and run: @@ -97,7 +97,7 @@ Install git: Install gcc's dependencies: - apt-cyg install wget gcc-g++ make diffutils libmpfr-devel libgmp-devel libmpc-devel libpcre-devel libcrypt-devel + apt-cyg install wget gcc-g++ make diffutils libmpfr-devel libgmp-devel libmpc-devel libpcre2-devel libcrypt-devel Download, Build and Install gcc: @@ -124,9 +124,9 @@ Finally build gsl: #### Building on MacOS -The modern way of building on MacOS is to make sure you have pcre installed and use brew. +The modern way of building on MacOS is to make sure you have pcre2 installed and use brew. - brew install pcre + brew install pcre2 And then build gsl as above: diff --git a/ci_build.sh b/ci_build.sh index 7616d3a..ea1853c 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -48,7 +48,7 @@ case "$BUILD_TYPE" in [ -z "$CI_TIME" ] || echo "`date`: Builds completed without fatal errors!" - echo "=== What is the GSL binary linked against (note libpcre in particular)?" + echo "=== What is the GSL binary linked against (note libpcre2 in particular)?" if [ $TRAVIS_OS_NAME == "linux" ]; then ldd src/gsl || true elif [ $TRAVIS_OS_NAME == "osx" ]; then diff --git a/packaging/debian/control b/packaging/debian/control index 684f245..ecd49d4 100644 --- a/packaging/debian/control +++ b/packaging/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: GSL Developers Standards-Version: 4.1.0 Build-Depends: debhelper (>= 9), - libpcre3-dev, + libpcre2-dev, Homepage: https://github.com/zeromq/gsl Package: generator-scripting-language diff --git a/packaging/debian/generator-scripting-language.dsc b/packaging/debian/generator-scripting-language.dsc index 1603666..e018a27 100644 --- a/packaging/debian/generator-scripting-language.dsc +++ b/packaging/debian/generator-scripting-language.dsc @@ -6,7 +6,7 @@ Maintainer: GSL Developers Architecture: any Standards-Version: 4.1.0 Build-Depends: debhelper (>= 9), - libpcre3-dev, + libpcre2-dev, Homepage: https://github.com/zeromq/gsl Files: diff --git a/packaging/linux/rpm/SPECS/generator-scripting-language.spec b/packaging/linux/rpm/SPECS/generator-scripting-language.spec index 2a596c7..6c0cd68 100644 --- a/packaging/linux/rpm/SPECS/generator-scripting-language.spec +++ b/packaging/linux/rpm/SPECS/generator-scripting-language.spec @@ -9,7 +9,7 @@ License: GPL-3.0-or-later Group: Libraries Source0: http://download.zeromq.org/%{name}-%{version}.tar.gz URL: http://zeromq.org/ -BuildRequires: pcre-devel +BuildRequires: pcre2-devel BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) From 80e2c9e82ca5f27b645f8f8969b69ecba9c6b18a Mon Sep 17 00:00:00 2001 From: Bastian Germann Date: Sat, 20 Apr 2024 12:14:00 +0200 Subject: [PATCH 3/3] Problem: Travis environment may be empty on GitHub Actions Solution: Prevent syntax error by quoting. --- ci_build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci_build.sh b/ci_build.sh index ea1853c..ee0487c 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -49,9 +49,9 @@ case "$BUILD_TYPE" in [ -z "$CI_TIME" ] || echo "`date`: Builds completed without fatal errors!" echo "=== What is the GSL binary linked against (note libpcre2 in particular)?" - if [ $TRAVIS_OS_NAME == "linux" ]; then + if [ "$TRAVIS_OS_NAME" == "linux" ]; then ldd src/gsl || true - elif [ $TRAVIS_OS_NAME == "osx" ]; then + elif [ "$TRAVIS_OS_NAME" == "osx" ]; then otool -L src/gsl || true else echo "Unsupported platform $TRAVIS_OS_NAME"