Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to PCRE2 #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MAINTAINER Godefroid Chapelle <[email protected]>

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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand All @@ -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:

Expand All @@ -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:

Expand All @@ -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:

Expand Down
12 changes: 6 additions & 6 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand All @@ -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:

Expand All @@ -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:

Expand All @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ 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)?"
if [ $TRAVIS_OS_NAME == "linux" ]; then
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
elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
otool -L src/gsl || true
else
echo "Unsupported platform $TRAVIS_OS_NAME"
Expand Down
2 changes: 1 addition & 1 deletion packaging/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: GSL Developers <[email protected]>
Standards-Version: 4.1.0
Build-Depends: debhelper (>= 9),
libpcre3-dev,
libpcre2-dev,
Homepage: https://github.com/zeromq/gsl

Package: generator-scripting-language
Expand Down
2 changes: 1 addition & 1 deletion packaging/debian/generator-scripting-language.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Maintainer: GSL Developers <[email protected]>
Architecture: any
Standards-Version: 4.1.0
Build-Depends: debhelper (>= 9),
libpcre3-dev,
libpcre2-dev,
Homepage: https://github.com/zeromq/gsl

Files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
70 changes: 39 additions & 31 deletions src/ggpcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ CLASS_DESCRIPTOR
regexp_functions, tblsize (regexp_functions) };


#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>


static int
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -179,15 +187,15 @@ 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);
}
i++;
}

mem_free (ovector);
pcre2_match_data_free (md);
}

return 0; /* Just in case */
Expand Down
Loading