Skip to content

Commit

Permalink
Merge pull request #108 from dag-erling/des/misc-fixes
Browse files Browse the repository at this point in the history
Miscellaneous bug fixes
  • Loading branch information
dag-erling authored Aug 16, 2024
2 parents c504ac3 + 3cfb56c commit 98fd780
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 163 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You will need the following tools installed on your system:

- autoconf
- automake
- gettext
- gettext (including autopoint)
- libtool
- zip (optional)

Expand Down
41 changes: 20 additions & 21 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(TRE, 0.8.0)
AC_INIT([TRE], [0.8.0])
AC_CONFIG_SRCDIR([lib/regcomp.c])
AC_CONFIG_AUX_DIR([utils])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([foreign])
AC_PREREQ(2.59)
AC_PREREQ([2.63])
AM_GNU_GETTEXT_VERSION(0.17)

dnl Checks for programs.
Expand All @@ -22,16 +22,19 @@ AC_DEFINE_UNQUOTED(TRE_VERSION_1, $tre_version_1, [ TRE version level 1. ])
AC_DEFINE_UNQUOTED(TRE_VERSION_2, $tre_version_2, [ TRE version level 2. ])
AC_DEFINE_UNQUOTED(TRE_VERSION_3, $tre_version_3, [ TRE version level 3. ])
AC_SUBST(TRE_VERSION, $tre_version)
AC_SUBST(TRE_VERSION_1, $tre_version_1)
AC_SUBST(TRE_VERSION_2, $tre_version_2)
AC_SUBST(TRE_VERSION_3, $tre_version_3)

dnl Options
AC_ARG_ENABLE(profile,
AC_HELP_STRING([--enable-profile],
AS_HELP_STRING([--enable-profile],
[enable profiling with gprof @<:@default=disabled@:>@]),
[ tre_profile="$enableval" ],
[ tre_profile="no" ])

AC_ARG_ENABLE(debug,
AC_HELP_STRING(
AS_HELP_STRING(
[--enable-debug],
[enable development-time debugging @<:@default=disabled@:>@]),
[ tre_debug="$enableval" ],
Expand All @@ -53,7 +56,7 @@ else
fi

AC_ARG_ENABLE(warnings,
AC_HELP_STRING(
AS_HELP_STRING(
[--disable-warnings],
[disable C compiler warning messages @<:@default=enabled@:>@]),
[ tre_cc_warnings="$enableval" ],
Expand All @@ -63,7 +66,7 @@ if test "$tre_cc_warnings" = "yes"; then
fi

AC_ARG_ENABLE(approx,
AC_HELP_STRING(
AS_HELP_STRING(
[--disable-approx],
[disable the approximate matching functionality @<:@default=enabled@:>@]),
[ tre_approx="$enableval" ],
Expand All @@ -78,7 +81,7 @@ fi

if test "$tre_approx" = "yes"; then
AC_ARG_ENABLE(agrep,
AC_HELP_STRING([--disable-agrep],
AS_HELP_STRING([--disable-agrep],
[Do not build and install the agrep tool @<:@default=install@:>@]),
[ tre_agrep="$enableval" ],
[ tre_agrep="yes" ])
Expand All @@ -96,16 +99,13 @@ fi
dnl Checks for compiler characteristics.
AC_C_CONST
AC_C_INLINE

dnl Checks for headers, functions, types, and macros
AC_DEFINE(_GNU_SOURCE, 1, [ Define to enable GNU extensions in glibc ])
AC_HEADER_STDC
AC_USE_SYSTEM_EXTENSIONS

dnl Make sure locally configured headers are used (this adds the #define to config.h).
AC_DEFINE(USE_LOCAL_TRE_H, 1, [ Define to ensure locally configured headers are used ])

AC_ARG_WITH(alloca,
AC_HELP_STRING(
AS_HELP_STRING(
[--without-alloca],
[don't use alloca @<:@default=use@:>@]),
[ tre_use_alloca="$withval" ],
Expand All @@ -122,7 +122,7 @@ if test "$tre_use_alloca" = "yes"; then
fi

AC_ARG_ENABLE(system-abi,
AC_HELP_STRING(
AS_HELP_STRING(
[--enable-system-abi],
[try to make TRE compatible with the system \
regex ABI @<:@default=disabled@:>@]),
Expand Down Expand Up @@ -274,18 +274,18 @@ AC_CHECK_FUNCS([getopt_long],,

dnl Check whether wide character support should be enabled.
AC_ARG_ENABLE(wchar,
AC_HELP_STRING(
AS_HELP_STRING(
[--disable-wchar],
[disable the wide character (wchar_t) support @<:@default=detect@:>@]),
[ tre_enable_wchar="$enableval" ],
[ tre_enable_wchar="detect" ])

dnl Check whether libutf8 location has been given.
AC_ARG_WITH(libutf8,
AC_HELP_STRING(
AS_HELP_STRING(
[--with-libutf8@<:@=DIR@:>@],
[search for libutf8 from DIR/include and DIR/lib])
AC_HELP_STRING(
AS_HELP_STRING(
[--without-libutf8],
[do not use libutf8 @<:@default=use if needed@:>@]),
[ if test "$with_val" = "no"; then
Expand Down Expand Up @@ -465,7 +465,7 @@ fi

dnl Check for multibyte character set support
AC_ARG_ENABLE(multibyte,
AC_HELP_STRING(
AS_HELP_STRING(
[--disable-multibyte],
[disable multibyte character set support @<:@default=detect@:>@]),
[ tre_enable_multibyte="$enableval" ],
Expand Down Expand Up @@ -517,10 +517,7 @@ fi
AC_SYS_LARGEFILE

AM_GNU_GETTEXT([external])
AC_LIBTOOL_TAGS([])
AC_LIBTOOL_WIN32_DLL
AM_DISABLE_STATIC
AC_PROG_LIBTOOL
LT_INIT([win32-dll, disable-static])

dnl Output files
AC_CONFIG_HEADERS([config.h local_includes/tre-config.h])
Expand All @@ -532,12 +529,14 @@ local_includes/Makefile
lib/Makefile
m4/Makefile
po/Makefile.in
python/setup.py
src/Makefile
tests/Makefile
tests/agrep/Makefile
tre.pc
tre.spec
utils/Makefile
win32/tre-config.h
])
AC_OUTPUT

Expand Down
3 changes: 1 addition & 2 deletions lib/tre-compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,7 @@ tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node, int *tags,
}
break;
case ASSERTION:
assert(lit->code_max >= 1
|| lit->code_max <= ASSERT_LAST);
assert(lit->code_max >= 1 && lit->code_max <= ASSERT_LAST);
if (assertions != NULL)
*assertions |= lit->code_max;
break;
Expand Down
6 changes: 3 additions & 3 deletions lib/tre-match-parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len,
everything in a single large block from the stack frame using alloca()
or with malloc() if alloca is unavailable. */
{
int tbytes, rbytes, pbytes, xbytes, total_bytes;
size_t tbytes, rbytes, pbytes, xbytes, total_bytes;
char *tmp_buf;
/* Compute the length of the block we need. */
tbytes = sizeof(*tmp_tags) * num_tags;
Expand All @@ -167,11 +167,11 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len,
#ifdef TRE_USE_ALLOCA
buf = alloca(total_bytes);
#else /* !TRE_USE_ALLOCA */
buf = xmalloc((unsigned)total_bytes);
buf = xmalloc(total_bytes);
#endif /* !TRE_USE_ALLOCA */
if (buf == NULL)
return REG_ESPACE;
memset(buf, 0, (size_t)total_bytes);
memset(buf, 0, total_bytes);

/* Get the various pointers within tmp_buf (properly aligned). */
tmp_tags = (void *)buf;
Expand Down
4 changes: 2 additions & 2 deletions lib/tre-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,15 +1492,15 @@ tre_parse(tre_parse_ctx_t *ctx)
else if (ctx->re < ctx->re_end)
{
/* Wide char. */
char tmp[32];
char tmp[9]; /* max 8 hex digits + terminator */
long val;
int i = 0;
ctx->re++;
while (ctx->re_end - ctx->re >= 0)
{
if (ctx->re[0] == CHAR_RBRACE)
break;
if (tre_isxdigit(ctx->re[0]))
if (tre_isxdigit(ctx->re[0]) && i < sizeof(tmp) - 1)
{
tmp[i] = (char)ctx->re[0];
i++;
Expand Down
1 change: 0 additions & 1 deletion m4/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
EXTRA_DIST = \
ac_libtool_tags.m4 \
ax_check_funcs_comp.m4 \
ax_check_sign.m4 \
ax_decl_wchar_max.m4 \
Expand Down
55 changes: 0 additions & 55 deletions m4/ac_libtool_tags.m4

This file was deleted.

2 changes: 1 addition & 1 deletion m4/ax_check_funcs_comp.m4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AC_DEFUN([AX_CHECK_FUNCS_COMP],[
dnl This is magic to make autoheader pick up the config.h.in templates
dnl automatically. This uses macros which are probably not public
dnl (not documented anyway) but this works at least with Automake 2.59.
AC_FOREACH([AX_Func], [$1],
m4_foreach_w([AX_Func], [$1],
[AH_TEMPLATE(AS_TR_CPP(HAVE_[]AX_Func),
[Define to 1 if you have the `]AX_Func[' function or macro.])])dnl
for ax_func in $1; do
Expand Down
73 changes: 45 additions & 28 deletions m4/ax_check_sign.m4
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
dnl @synopsis AX_CHECK_SIGN (TYPE, [ACTION-IF-SIGNED], [ACTION-IF-UNSIGNED], [INCLUDES])
dnl
dnl Checks whether TYPE is signed or not. If no INCLUDES are specified,
dnl the default includes are used. If ACTION-IF-SIGNED is given, it is
dnl additional shell code to execute when the type is signed. If
dnl ACTION-IF-UNSIGNED is given, it is executed when the type is unsigned.
dnl
dnl This macro assumes that the type exists. Therefore the existence of
dnl the type should be checked before calling this macro. For example:
dnl
dnl AC_CHECK_HEADERS([wchar.h])
dnl AC_CHECK_TYPE([wchar_t],,[ AC_MSG_ERROR([Type wchar_t not found.]) ])
dnl AX_CHECK_SIGN([wchar_t],
dnl [ AC_DEFINE(WCHAR_T_SIGNED, 1, [Define if wchar_t is signed]) ],
dnl [ AC_DEFINE(WCHAR_T_UNSIGNED, 1, [Define if wchar_t is unsigned]) ], [
dnl #ifdef HAVE_WCHAR_H
dnl #include <wchar.h>
dnl #endif
dnl ])
dnl
dnl @version 1.1
dnl @author Ville Laurikari <vl@iki.fi>
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_check_sign.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_SIGN (TYPE, [ACTION-IF-SIGNED], [ACTION-IF-UNSIGNED], [INCLUDES])
#
# DESCRIPTION
#
# Checks whether TYPE is signed or not. If no INCLUDES are specified, the
# default includes are used. If ACTION-IF-SIGNED is given, it is
# additional shell code to execute when the type is signed. If
# ACTION-IF-UNSIGNED is given, it is executed when the type is unsigned.
#
# This macro assumes that the type exists. Therefore the existence of the
# type should be checked before calling this macro. For example:
#
# AC_CHECK_HEADERS([wchar.h])
# AC_CHECK_TYPE([wchar_t],,[ AC_MSG_ERROR([Type wchar_t not found.]) ])
# AX_CHECK_SIGN([wchar_t],
# [ AC_DEFINE(WCHAR_T_SIGNED, 1, [Define if wchar_t is signed]) ],
# [ AC_DEFINE(WCHAR_T_UNSIGNED, 1, [Define if wchar_t is unsigned]) ], [
# #ifdef HAVE_WCHAR_H
# #include <wchar.h>
# #endif
# ])
#
# LICENSE
#
# Copyright (c) 2008 Ville Laurikari <vl@iki.fi>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 10

AU_ALIAS([VL_CHECK_SIGN], [AX_CHECK_SIGN])
AC_DEFUN([AX_CHECK_SIGN], [
typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"`
AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([$4],
[ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ])],
[AC_LANG_PROGRAM([[$4]],
[[ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ; (void)foo[0] ]])],
[ eval "ax_cv_decl_${typename}_signed=\"yes\"" ],
[ eval "ax_cv_decl_${typename}_signed=\"no\"" ])])
symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "@<:@a-z@:>@" "@<:@A-Z@:>@"`
[ eval "ax_cv_decl_${typename}_signed=\"no\"" ])
])
symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"`
if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
true
$2
elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
true
$3
fi
])dnl
Loading

0 comments on commit 98fd780

Please sign in to comment.