Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Aug 2017 00:23:59 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r322557 - in stable/11/usr.bin/grep: . regex
Message-ID:  <201708160023.v7G0NxG3029799@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Aug 16 00:23:59 2017
New Revision: 322557
URL: https://svnweb.freebsd.org/changeset/base/322557

Log:
  MFC r316492: bsdgrep(1): Rip out "xmalloc" bits
  
  xmalloc was a debug malloc implementation, but the x{malloc,calloc,free}
  functions default to calling the malloc(3) equivalents.
  
  Instead of relying on this malloc shim, we can devise better ways to debug
  malloc issues that aren't misleading upon initial inspection.  (I.e., using
  jemalloc's various built-in debugging capabilities.)
  
  Approved by:	emaste (mentor, blanket MFC)

Deleted:
  stable/11/usr.bin/grep/regex/xmalloc.c
  stable/11/usr.bin/grep/regex/xmalloc.h
Modified:
  stable/11/usr.bin/grep/Makefile
  stable/11/usr.bin/grep/regex/fastmatch.c
  stable/11/usr.bin/grep/regex/tre-compile.c
  stable/11/usr.bin/grep/regex/tre-fastmatch.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/grep/Makefile
==============================================================================
--- stable/11/usr.bin/grep/Makefile	Wed Aug 16 00:19:59 2017	(r322556)
+++ stable/11/usr.bin/grep/Makefile	Wed Aug 16 00:23:59 2017	(r322557)
@@ -17,7 +17,7 @@ SRCS=	file.c grep.c queue.c util.c
 
 # Extra files ported backported form some regex improvements
 .PATH: ${.CURDIR}/regex
-SRCS+=	fastmatch.c hashtable.c tre-compile.c tre-fastmatch.c xmalloc.c
+SRCS+=	fastmatch.c hashtable.c tre-compile.c tre-fastmatch.c
 CFLAGS+=-I${.CURDIR}/regex
 
 CFLAGS.gcc+= --param max-inline-insns-single=500

Modified: stable/11/usr.bin/grep/regex/fastmatch.c
==============================================================================
--- stable/11/usr.bin/grep/regex/fastmatch.c	Wed Aug 16 00:19:59 2017	(r322556)
+++ stable/11/usr.bin/grep/regex/fastmatch.c	Wed Aug 16 00:23:59 2017	(r322557)
@@ -34,7 +34,6 @@
 #include <string.h>
 
 #include "tre-fastmatch.h"
-#include "xmalloc.h"
 
 int
 tre_fixncomp(fastmatch_t *preg, const char *regex, size_t n, int cflags)

Modified: stable/11/usr.bin/grep/regex/tre-compile.c
==============================================================================
--- stable/11/usr.bin/grep/regex/tre-compile.c	Wed Aug 16 00:19:59 2017	(r322556)
+++ stable/11/usr.bin/grep/regex/tre-compile.c	Wed Aug 16 00:23:59 2017	(r322557)
@@ -9,8 +9,6 @@
 #include <string.h>
 #include <wchar.h>
 
-#include "xmalloc.h"
-
 int
 tre_convert_pattern(const char *regex, size_t n, tre_char_t **w,
 		    size_t *wn)
@@ -19,7 +17,7 @@ tre_convert_pattern(const char *regex, size_t n, tre_c
   tre_char_t *wregex;
   size_t wlen;
 
-  wregex = xmalloc(sizeof(tre_char_t) * (n + 1));
+  wregex = malloc(sizeof(tre_char_t) * (n + 1));
   if (wregex == NULL)
     return REG_ESPACE;
 
@@ -60,13 +58,13 @@ tre_convert_pattern(const char *regex, size_t n, tre_c
 		consumed = 1;
 	      else
 		{
-		  xfree(wregex);
+		  free(wregex);
 		  return REG_BADPAT;
 		}
 	      break;
 	    case -1:
 	      DPRINT(("mbrtowc: error %d: %s.\n", errno, strerror(errno)));
-	      xfree(wregex);
+	      free(wregex);
 	      return REG_BADPAT;
 	    case -2:
 	      /* The last character wasn't complete.  Let's not call it a
@@ -98,6 +96,6 @@ void
 tre_free_pattern(tre_char_t *wregex)
 {
 #if TRE_WCHAR
-  xfree(wregex);
+  free(wregex);
 #endif
 }

Modified: stable/11/usr.bin/grep/regex/tre-fastmatch.c
==============================================================================
--- stable/11/usr.bin/grep/regex/tre-fastmatch.c	Wed Aug 16 00:19:59 2017	(r322556)
+++ stable/11/usr.bin/grep/regex/tre-fastmatch.c	Wed Aug 16 00:23:59 2017	(r322557)
@@ -42,7 +42,6 @@
 
 #include "hashtable.h"
 #include "tre-fastmatch.h"
-#include "xmalloc.h"
 
 static int	fastcmp(const fastmatch_t *fg, const void *data,
 			tre_str_type_t type);
@@ -53,9 +52,9 @@ static int	fastcmp(const fastmatch_t *fg, const void *
 #define FAIL_COMP(errcode)						\
   {									\
     if (fg->pattern)							\
-      xfree(fg->pattern);						\
+      free(fg->pattern);						\
     if (fg->wpattern)							\
-      xfree(fg->wpattern);						\
+      free(fg->wpattern);						\
     if (fg->qsBc_table)							\
       hashtable_free(fg->qsBc_table);					\
     fg = NULL;								\
@@ -92,7 +91,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
     if (siz == (size_t)-1)						\
       return REG_BADPAT;						\
     fg->len = siz;							\
-    fg->pattern = xmalloc(siz + 1);					\
+    fg->pattern = malloc(siz + 1);					\
     if (fg->pattern == NULL)						\
       return REG_ESPACE;						\
     wcstombs(fg->pattern, fg->wpattern, siz);				\
@@ -340,7 +339,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
 #define FILL_BMGS							\
   if (!fg->hasdot)							\
     {									\
-      fg->sbmGs = xmalloc(fg->len * sizeof(int));			\
+      fg->sbmGs = malloc(fg->len * sizeof(int));			\
       if (!fg->sbmGs)							\
 	return REG_ESPACE;						\
       if (fg->len == 1)							\
@@ -356,7 +355,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
 #define FILL_BMGS_WIDE							\
   if (!fg->hasdot)							\
     {									\
-      fg->bmGs = xmalloc(fg->wlen * sizeof(int));			\
+      fg->bmGs = malloc(fg->wlen * sizeof(int));			\
       if (!fg->bmGs)							\
 	return REG_ESPACE;						\
       if (fg->wlen == 1)						\
@@ -376,13 +375,13 @@ static int	fastcmp(const fastmatch_t *fg, const void *
       {									\
 	if (fg->icase)							\
 	  {								\
-	    wp = xmalloc(plen * sizeof(tre_char_t));			\
+	    wp = malloc(plen * sizeof(tre_char_t));			\
 	    if (wp == NULL)						\
 	      return REG_ESPACE;					\
 	    for (unsigned int i = 0; i < plen; i++)			\
 	      wp[i] = towlower(pat[i]);					\
 	    _CALC_BMGS(arr, wp, plen);					\
-	    xfree(wp);							\
+	    free(wp);							\
 	  }								\
 	else								\
 	  _CALC_BMGS(arr, pat, plen);					\
@@ -391,13 +390,13 @@ static int	fastcmp(const fastmatch_t *fg, const void *
       {									\
 	if (fg->icase)							\
 	  {								\
-	    p = xmalloc(plen);						\
+	    p = malloc(plen);						\
 	    if (p == NULL)						\
 	      return REG_ESPACE;					\
 	    for (unsigned int i = 0; i < plen; i++)			\
 	      p[i] = tolower((unsigned char)pat[i]);                    \
 	    _CALC_BMGS(arr, p, plen);					\
-	    xfree(p);							\
+	    free(p);							\
 	  }								\
 	else								\
 	  _CALC_BMGS(arr, pat, plen);					\
@@ -408,7 +407,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
   {									\
     int f = 0, g;							\
 									\
-    int *suff = xmalloc(plen * sizeof(int));				\
+    int *suff = malloc(plen * sizeof(int));				\
     if (suff == NULL)							\
       return REG_ESPACE;						\
 									\
@@ -440,7 +439,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
     for (unsigned int i = 0; i <= plen - 2; i++)			\
       arr[plen - 1 - suff[i]] = plen - 1 - i;				\
 									\
-    xfree(suff);							\
+    free(suff);							\
   }
 
 /*
@@ -449,7 +448,7 @@ static int	fastcmp(const fastmatch_t *fg, const void *
  */
 #define SAVE_PATTERN(src, srclen, dst, dstlen)				\
   dstlen = srclen;							\
-  dst = xmalloc((dstlen + 1) * sizeof(tre_char_t));			\
+  dst = malloc((dstlen + 1) * sizeof(tre_char_t));			\
   if (dst == NULL)							\
     return REG_ESPACE;							\
   if (dstlen > 0)							\
@@ -489,11 +488,11 @@ static int	fastcmp(const fastmatch_t *fg, const void *
   if (n == 0)								\
     {									\
       fg->matchall = true;						\
-      fg->pattern = xmalloc(sizeof(char));				\
+      fg->pattern = malloc(sizeof(char));				\
       if (!fg->pattern)							\
 	FAIL_COMP(REG_ESPACE);						\
       fg->pattern[0] = '\0';						\
-      fg->wpattern = xmalloc(sizeof(tre_char_t));			\
+      fg->wpattern = malloc(sizeof(tre_char_t));			\
       if (!fg->wpattern)						\
 	FAIL_COMP(REG_ESPACE);						\
       fg->wpattern[0] = TRE_CHAR('\0');					\
@@ -580,7 +579,7 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t *pa
   if (fg->word && (TRE_MB_CUR_MAX > 1))
     return REG_BADPAT;
 
-  tmp = xmalloc((n + 1) * sizeof(tre_char_t));
+  tmp = malloc((n + 1) * sizeof(tre_char_t));
   if (tmp == NULL)
     return REG_ESPACE;
 
@@ -631,10 +630,10 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t *pa
 	    if (escaped)
 	      {
 		if (!_escmap)
-		  _escmap = xmalloc(n * sizeof(bool));
+		  _escmap = malloc(n * sizeof(bool));
 		if (!_escmap)
 		  {
-		    xfree(tmp);
+		    free(tmp);
 		    return REG_ESPACE;
 		  }
 		_escmap[i] = true;
@@ -688,7 +687,7 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t *pa
 	}
       continue;
 badpat:
-      xfree(tmp);
+      free(tmp);
       DPRINT(("tre_compile_fast: compilation of pattern failed, falling"
 	      "back to NFA\n"));
       return REG_BADPAT;
@@ -715,7 +714,7 @@ badpat:
     {
       if (fg->wescmap != NULL)
 	{
-	  fg->escmap = xmalloc(fg->len * sizeof(bool));
+	  fg->escmap = malloc(fg->len * sizeof(bool));
 	  if (!fg->escmap)
 	    {
 	      tre_free_fast(fg);
@@ -746,7 +745,7 @@ badpat:
   fg->escmap = _escmap;
 #endif
 
-  xfree(tmp);
+  free(tmp);
 
   DPRINT(("tre_compile_fast: pattern: %s, len %zu, bol %c, eol %c, "
 	 "icase: %c, word: %c, newline %c\n", fg->pattern, fg->len,
@@ -977,16 +976,16 @@ tre_free_fast(fastmatch_t *fg)
 #ifdef TRE_WCHAR
   hashtable_free(fg->qsBc_table);
   if (!fg->hasdot)
-    xfree(fg->bmGs);
+    free(fg->bmGs);
   if (fg->wescmap)
-    xfree(fg->wescmap);
-  xfree(fg->wpattern);
+    free(fg->wescmap);
+  free(fg->wpattern);
 #endif
   if (!fg->hasdot)
-    xfree(fg->sbmGs);
+    free(fg->sbmGs);
   if (fg->escmap)
-    xfree(fg->escmap);
-  xfree(fg->pattern);
+    free(fg->escmap);
+  free(fg->pattern);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708160023.v7G0NxG3029799>