From 8d872ae8f85dc409340b9ac37c269f44815b016e Mon Sep 17 00:00:00 2001 From: kevans Date: Mon, 22 Jan 2018 02:44:41 +0000 Subject: [PATCH] Add libregex, connect it to the build libregex is a regex(3) implementation intended to feature GNU extensions and any other non-POSIX compliant extensions that are deemed worthy. These extensions are separated out into a separate library for the sake of not cluttering up libc further with them as well as not deteriorating the speed (or lack thereof) of the libc implementation. libregex is implemented as a build of the libc implementation with LIBREGEX defined to distinguish this from a libc build. The reasons for implementation like this are two-fold: 1.) Maintenance- This reduces the overhead induced by adding yet another regex implementation to base. 2.) Ease of use- Flipping on GNU extensions will be as simple as linking against libregex, and POSIX-compliant compilations can be guaranteed with a REG_POSIX cflag that should be ignored by libc/regex and disables extensions in libregex. It is also easier to keep REG_POSIX sane and POSIX pure when implemented in this fashion. Tests are added for future functionality, but left disconnected for the time being while other testing is done. Reviewed by: cem (previous version) Differential Revision: https://reviews.freebsd.org/D12934 --- etc/mtree/BSD.tests.dist | 4 ++ lib/Makefile | 1 + lib/libc/regex/Makefile.inc | 3 ++ lib/libc/tests/regex/Makefile | 60 +---------------------------- lib/libc/tests/regex/Makefile.inc | 57 +++++++++++++++++++++++++++ lib/libregex/Makefile | 19 +++++++++ lib/libregex/tests/Makefile | 20 ++++++++++ lib/libregex/tests/gnuext.in | 30 +++++++++++++++ lib/libregex/tests/libregex_test.sh | 55 ++++++++++++++++++++++++++ share/mk/bsd.libnames.mk | 1 + share/mk/src.libnames.mk | 1 + 11 files changed, 193 insertions(+), 58 deletions(-) create mode 100644 lib/libc/tests/regex/Makefile.inc create mode 100644 lib/libregex/Makefile create mode 100644 lib/libregex/tests/Makefile create mode 100644 lib/libregex/tests/gnuext.in create mode 100755 lib/libregex/tests/libregex_test.sh diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 540b1521ba2d..8a8a28ad7e1e 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -354,6 +354,10 @@ .. libproc .. + libregex + data + .. + .. librt .. libsbuf diff --git a/lib/Makefile b/lib/Makefile index 67d9c3a2d090..be57493f7a34 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -71,6 +71,7 @@ SUBDIR= ${SUBDIR_BOOTSTRAP} \ libpjdlog \ ${_libproc} \ libprocstat \ + libregex \ librpcsvc \ librss \ librt \ diff --git a/lib/libc/regex/Makefile.inc b/lib/libc/regex/Makefile.inc index 4595361b2813..19c2ffcee5ab 100644 --- a/lib/libc/regex/Makefile.inc +++ b/lib/libc/regex/Makefile.inc @@ -10,8 +10,11 @@ SRCS+= regcomp.c regerror.c regexec.c regfree.c SYM_MAPS+=${LIBC_SRCTOP}/regex/Symbol.map +# manpages only included in libc version +.if ${LIB} == "c" MAN+= regex.3 MAN+= re_format.7 MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3 MLINKS+=regexec.3 regfree.3 +.endif diff --git a/lib/libc/tests/regex/Makefile b/lib/libc/tests/regex/Makefile index b16f503c65f1..9a940a0239ee 100644 --- a/lib/libc/tests/regex/Makefile +++ b/lib/libc/tests/regex/Makefile @@ -1,63 +1,7 @@ # $FreeBSD$ -.include - PACKAGE= tests -BINDIR= ${TESTSDIR} - -# SKIP_LEFTASSOC -> these testcases fail on FreeBSD. -IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC - -CFLAGS.h_regex+=-I${TESTSRC} -I${.CURDIR:H:H}/regex -PROGS+= h_regex -SRCS.h_regex= main.c split.c debug.c - -NETBSD_ATF_TESTS_SH= regex_test - -${PACKAGE}FILES+= README - -FILESGROUPS+= ${PACKAGE}DATA_FILES -${PACKAGE}DATA_FILESPACKAGE=${PACKAGE} - -${PACKAGE}DATA_FILESDIR= ${TESTSDIR}/data -${PACKAGE}DATA_FILES+= data/anchor.in -${PACKAGE}DATA_FILES+= data/backref.in -${PACKAGE}DATA_FILES+= data/basic.in -${PACKAGE}DATA_FILES+= data/bracket.in -${PACKAGE}DATA_FILES+= data/c_comments.in -${PACKAGE}DATA_FILES+= data/complex.in -${PACKAGE}DATA_FILES+= data/error.in -${PACKAGE}DATA_FILES+= data/meta.in -${PACKAGE}DATA_FILES+= data/nospec.in -${PACKAGE}DATA_FILES+= data/paren.in -${PACKAGE}DATA_FILES+= data/regress.in -${PACKAGE}DATA_FILES+= data/repet_bounded.in -${PACKAGE}DATA_FILES+= data/repet_multi.in -${PACKAGE}DATA_FILES+= data/repet_ordinary.in -${PACKAGE}DATA_FILES+= data/startend.in -${PACKAGE}DATA_FILES+= data/subexp.in -${PACKAGE}DATA_FILES+= data/subtle.in -${PACKAGE}DATA_FILES+= data/word_bound.in -${PACKAGE}DATA_FILES+= data/zero.in -#${PACKAGE}DATA_FILES+= data/att/README -${PACKAGE}DATA_FILES+= data/att/basic.dat -${PACKAGE}DATA_FILES+= data/att/categorization.dat -${PACKAGE}DATA_FILES+= data/att/forcedassoc.dat -${PACKAGE}DATA_FILES+= data/att/leftassoc.dat -${PACKAGE}DATA_FILES+= data/att/nullsubexpr.dat -${PACKAGE}DATA_FILES+= data/att/repetition.dat -${PACKAGE}DATA_FILES+= data/att/rightassoc.dat - -NETBSD_ATF_TESTS_C= exhaust_test -NETBSD_ATF_TESTS_C+= regex_att_test - -.for t in ${NETBSD_ATF_TESTS_C} -CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION} -.endfor - -.include "../Makefile.netbsd-tests" - -LIBADD.regex_att_test+= util - +.include "Makefile.inc" +.include "${.CURDIR:H}/Makefile.netbsd-tests" .include diff --git a/lib/libc/tests/regex/Makefile.inc b/lib/libc/tests/regex/Makefile.inc new file mode 100644 index 000000000000..00aa7c0e212b --- /dev/null +++ b/lib/libc/tests/regex/Makefile.inc @@ -0,0 +1,57 @@ +# $FreeBSD$ + +.include + +BINDIR?= ${TESTSDIR} + +# SKIP_LEFTASSOC -> these testcases fail on FreeBSD. +IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC + +CFLAGS.h_regex+=-I${TESTSRC} -I${SRCTOP}/lib/libc/regex +PROGS+= h_regex +SRCS.h_regex= main.c split.c debug.c + +NETBSD_ATF_TESTS_SH= regex_test + +${PACKAGE}FILES+= README + +FILESGROUPS+= ${PACKAGE}DATA_FILES +${PACKAGE}DATA_FILESPACKAGE=${PACKAGE} + +${PACKAGE}DATA_FILESDIR= ${TESTSDIR}/data +${PACKAGE}DATA_FILES+= data/anchor.in +${PACKAGE}DATA_FILES+= data/backref.in +${PACKAGE}DATA_FILES+= data/basic.in +${PACKAGE}DATA_FILES+= data/bracket.in +${PACKAGE}DATA_FILES+= data/c_comments.in +${PACKAGE}DATA_FILES+= data/complex.in +${PACKAGE}DATA_FILES+= data/error.in +${PACKAGE}DATA_FILES+= data/meta.in +${PACKAGE}DATA_FILES+= data/nospec.in +${PACKAGE}DATA_FILES+= data/paren.in +${PACKAGE}DATA_FILES+= data/regress.in +${PACKAGE}DATA_FILES+= data/repet_bounded.in +${PACKAGE}DATA_FILES+= data/repet_multi.in +${PACKAGE}DATA_FILES+= data/repet_ordinary.in +${PACKAGE}DATA_FILES+= data/startend.in +${PACKAGE}DATA_FILES+= data/subexp.in +${PACKAGE}DATA_FILES+= data/subtle.in +${PACKAGE}DATA_FILES+= data/word_bound.in +${PACKAGE}DATA_FILES+= data/zero.in +#${PACKAGE}DATA_FILES+= data/att/README +${PACKAGE}DATA_FILES+= data/att/basic.dat +${PACKAGE}DATA_FILES+= data/att/categorization.dat +${PACKAGE}DATA_FILES+= data/att/forcedassoc.dat +${PACKAGE}DATA_FILES+= data/att/leftassoc.dat +${PACKAGE}DATA_FILES+= data/att/nullsubexpr.dat +${PACKAGE}DATA_FILES+= data/att/repetition.dat +${PACKAGE}DATA_FILES+= data/att/rightassoc.dat + +NETBSD_ATF_TESTS_C= exhaust_test +NETBSD_ATF_TESTS_C+= regex_att_test + +.for t in ${NETBSD_ATF_TESTS_C} +CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION} +.endfor + +LIBADD.regex_att_test+= util diff --git a/lib/libregex/Makefile b/lib/libregex/Makefile new file mode 100644 index 000000000000..71d5b2279cbb --- /dev/null +++ b/lib/libregex/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=lib${LIB} +LIB= regex +SHLIB_MAJOR= 1 +SHLIB_MINOR= 0 + +CFLAGS+= -DLIBREGEX +LIBC_SRCTOP= ${.CURDIR:H}/libc +SYMBOL_MAPS= ${SYM_MAPS} + +#HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + +.include "../Makefile.inc" +.include "${LIBC_SRCTOP}/regex/Makefile.inc" +.include diff --git a/lib/libregex/tests/Makefile b/lib/libregex/tests/Makefile new file mode 100644 index 000000000000..cc05decc9cc6 --- /dev/null +++ b/lib/libregex/tests/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +PACKAGE= tests +TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libc/regex + +.PATH: ${SRCTOP}/tests + +.include "${SRCTOP}/lib/libc/tests/regex/Makefile.inc" + +ATF_TESTS_SH+= libregex_test + +${PACKAGE}DATA_FILES+= gnuext.in + +LIBADD.h_regex+=regex +.for t in ${NETBSD_ATF_TESTS_C} +LIBADD.$t+= regex +.endfor + +.include +.include diff --git a/lib/libregex/tests/gnuext.in b/lib/libregex/tests/gnuext.in new file mode 100644 index 000000000000..86afe499f50a --- /dev/null +++ b/lib/libregex/tests/gnuext.in @@ -0,0 +1,30 @@ +# BRE Quantifiers +ab\?c b abc abc +ab\+c b abc abc +# BRE Branching +abc\|de b abc abc +a\|b\|c b abc a +\(ab\|bc\) b abcd ab +# ERE Backrefs +(ab)\1 - ab +(ab)\1 - abab abab +\1(ab) C ESUBREG +(a)(b)(c)(d)(e)(f)(g)(h)(i)\9 - abcdefghii abcdefghii +# \w, \W, \s, \S (alnum, ^alnum, space, ^space) +\w+ - -%@a0X- a0X +\w\+ b -%@a0X- a0X +\s+ - aSNTb SNT +\s\+ b aSNTb SNT +# Word boundaries (\b, \B, \<, \>, \`, \') +# (is/not boundary, start/end word, start/end subject string) +\babc\b & abc +\ & abc +\Babc\B & abc +\B[abc]\B & b +\B[abc]+ - bc +\B[abc]\+ b bc +\`abc\' & abc abc +\`.+\' - abNc abNc +\`.\+\' b abNc abNc +(\`a) - Na +(a\') - aN diff --git a/lib/libregex/tests/libregex_test.sh b/lib/libregex/tests/libregex_test.sh new file mode 100755 index 000000000000..8ebe9b64ab63 --- /dev/null +++ b/lib/libregex/tests/libregex_test.sh @@ -0,0 +1,55 @@ +# +# Copyright (c) 2017 Kyle Evans +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD$ + +check() +{ + local dataname="${1}"; shift + + prog="$(atf_get_srcdir)/h_regex" + data="$(atf_get_srcdir)/data/${dataname}.in" + + atf_check -x "${prog} <${data}" + atf_check -x "${prog} -el <${data}" + atf_check -x "${prog} -er <${data}" +} + +create_tc() +{ + local name="${1}"; shift + local descr="${1}"; shift + + atf_test_case "${name}" + eval "${name}_head() { atf_set 'descr' '${descr}'; }" + eval "${name}_body() { check '${name}'; }" + + atf_add_test_case "${name}" +} + +atf_init_test_cases() +{ + create_tc gnuext "Check GNU extension functionality" +} diff --git a/share/mk/bsd.libnames.mk b/share/mk/bsd.libnames.mk index b303ccc9b9c9..9e64ce50fae8 100644 --- a/share/mk/bsd.libnames.mk +++ b/share/mk/bsd.libnames.mk @@ -132,6 +132,7 @@ LIBPROCSTAT?= ${LIBDESTDIR}${LIBDIR_BASE}/libprocstat.a LIBPTHREAD?= ${LIBDESTDIR}${LIBDIR_BASE}/libpthread.a LIBRADIUS?= ${LIBDESTDIR}${LIBDIR_BASE}/libradius.a LIBRDMACM?= ${LIBDESTDIR}${LIBDIR_BASE}/librdmacm.a +LIBREGEX?= ${LIBDESTDIR}${LIBDIR_BASE}/libregex.a LIBROKEN?= ${LIBDESTDIR}${LIBDIR_BASE}/libroken.a LIBRPCSEC_GSS?= ${LIBDESTDIR}${LIBDIR_BASE}/librpcsec_gss.a LIBRPCSVC?= ${LIBDESTDIR}${LIBDIR_BASE}/librpcsvc.a diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk index fdd1a4866620..5f0454de1c24 100644 --- a/share/mk/src.libnames.mk +++ b/share/mk/src.libnames.mk @@ -148,6 +148,7 @@ _LIBRARIES= \ pthread \ radius \ readline \ + regex \ roken \ rpcsec_gss \ rpcsvc \