prelude-lml/master: Use GnuLib realloc() in place of _prelude_realloc

[email protected] Wed, 24 Feb 2010 14:03:25 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 05dd9f774139ba710a30159da5db8ff7265a6528
Author: Yoann Vandoorselaere <[email protected]>
Date:   Mon Feb 8 17:47:24 2010 +0100

    Use GnuLib realloc() in place of _prelude_realloc


========================================

 libmissing/Makefile.am        |   20 +++++++++-
 libmissing/m4/gnulib-cache.m4 |    3 +-
 libmissing/m4/gnulib-comp.m4  |    6 +++
 libmissing/m4/realloc.m4      |   23 +++++++++++
 libmissing/realloc.c          |   88 +++++++++++++++++++++++++++++++++++++++++
 src/lml-options.c             |    2 +-
 6 files changed, 139 insertions(+), 3 deletions(-)

========================================

diff --git a/libmissing/Makefile.am b/libmissing/Makefile.am
index e10a83c..c8826a3 100644
--- a/libmissing/Makefile.am
+++ b/libmissing/Makefile.am
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu fseeko ftello getaddrinfo glob iconv imaxabs inet_ntop ioctl mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf-posix socket socklen strptime strsep sys_select
+# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu fseeko ftello getaddrinfo glob iconv imaxabs inet_ntop ioctl mktime nl_langinfo pathmax realloc recvfrom servent sigaction sleep snprintf-posix socket socklen strptime strsep sys_select
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -893,6 +893,24 @@ EXTRA_libmissing_la_SOURCES += printf-frexp.c
 
 ## end   gnulib module printf-frexpl
 
+## begin gnulib module realloc
+
+
+EXTRA_DIST += realloc.c
+
+EXTRA_libmissing_la_SOURCES += realloc.c
+
+## end   gnulib module realloc
+
+## begin gnulib module realloc-posix
+
+
+EXTRA_DIST += realloc.c
+
+EXTRA_libmissing_la_SOURCES += realloc.c
+
+## end   gnulib module realloc-posix
+
 ## begin gnulib module recvfrom
 
 
diff --git a/libmissing/m4/gnulib-cache.m4 b/libmissing/m4/gnulib-cache.m4
index 99cd2aa..d79f70c 100644
--- a/libmissing/m4/gnulib-cache.m4
+++ b/libmissing/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu fseeko ftello getaddrinfo glob iconv imaxabs inet_ntop ioctl mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf-posix socket socklen strptime strsep sys_select
+#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu fseeko ftello getaddrinfo glob iconv imaxabs inet_ntop ioctl mktime nl_langinfo pathmax realloc recvfrom servent sigaction sleep snprintf-posix socket socklen strptime strsep sys_select
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
@@ -34,6 +34,7 @@ gl_MODULES([
   mktime
   nl_langinfo
   pathmax
+  realloc
   recvfrom
   servent
   sigaction
diff --git a/libmissing/m4/gnulib-comp.m4 b/libmissing/m4/gnulib-comp.m4
index eb9c789..97d1943 100644
--- a/libmissing/m4/gnulib-comp.m4
+++ b/libmissing/m4/gnulib-comp.m4
@@ -138,6 +138,10 @@ AC_SUBST([LTALLOCA])
   gl_FUNC_PRINTF_FREXP
   gl_FUNC_PRINTF_FREXPL
   m4_divert_text([INIT_PREPARE], [gl_printf_safe=yes])
+  AC_FUNC_REALLOC
+  AC_DEFINE([GNULIB_REALLOC_GNU], 1, [Define to indicate the 'realloc' module.])
+  gl_FUNC_REALLOC_POSIX
+  gl_STDLIB_MODULE_INDICATOR([realloc-posix])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
     AC_LIBOBJ([recvfrom])
@@ -436,6 +440,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/printf-frexpl.h
   lib/printf-parse.c
   lib/printf-parse.h
+  lib/realloc.c
   lib/recvfrom.c
   lib/ref-add.sin
   lib/ref-del.sin
@@ -554,6 +559,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/printf-frexp.m4
   m4/printf-frexpl.m4
   m4/printf.m4
+  m4/realloc.m4
   m4/servent.m4
   m4/sigaction.m4
   m4/signal_h.m4
diff --git a/libmissing/m4/realloc.m4 b/libmissing/m4/realloc.m4
new file mode 100644
index 0000000..dc30235
--- /dev/null
+++ b/libmissing/m4/realloc.m4
@@ -0,0 +1,23 @@
+# realloc.m4 serial 9
+dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# gl_FUNC_REALLOC_POSIX
+# ---------------------
+# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
+# fails), and replace realloc if it is not.
+AC_DEFUN([gl_FUNC_REALLOC_POSIX],
+[
+  AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
+  if test $gl_cv_func_malloc_posix = yes; then
+    HAVE_REALLOC_POSIX=1
+    AC_DEFINE([HAVE_REALLOC_POSIX], [1],
+      [Define if the 'realloc' function is POSIX compliant.])
+  else
+    AC_LIBOBJ([realloc])
+    HAVE_REALLOC_POSIX=0
+  fi
+  AC_SUBST([HAVE_REALLOC_POSIX])
+])
diff --git a/libmissing/realloc.c b/libmissing/realloc.c
new file mode 100644
index 0000000..76b62b5
--- /dev/null
+++ b/libmissing/realloc.c
@@ -0,0 +1,88 @@
+/* realloc() function that is glibc compatible.
+
+   Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2010 Free Software
+   Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* written by Jim Meyering and Bruno Haible */
+
+#include <config.h>
+
+/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h.  */
+#ifdef realloc
+# define NEED_REALLOC_GNU 1
+#endif
+
+/* Infer the properties of the system's malloc function.
+   Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h.  */
+#if GNULIB_MALLOC_GNU && !defined malloc
+# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
+#endif
+
+/* Below we want to call the system's malloc and realloc.
+   Undefine the symbols here so that including <stdlib.h> provides a
+   declaration of malloc(), not of rpl_malloc(), and likewise for realloc.  */
+#undef malloc
+#undef realloc
+
+/* Specification.  */
+#include <stdlib.h>
+
+#include <errno.h>
+
+/* Below we want to call the system's malloc and realloc.
+   Undefine the symbols, if they were defined by gnulib's <stdlib.h>
+   replacement.  */
+#undef malloc
+#undef realloc
+
+/* Change the size of an allocated block of memory P to N bytes,
+   with error checking.  If N is zero, change it to 1.  If P is NULL,
+   use malloc.  */
+
+void *
+rpl_realloc (void *p, size_t n)
+{
+  void *result;
+
+#if NEED_REALLOC_GNU
+  if (n == 0)
+    {
+      n = 1;
+
+      /* In theory realloc might fail, so don't rely on it to free.  */
+      free (p);
+      p = NULL;
+    }
+#endif
+
+  if (p == NULL)
+    {
+#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
+      if (n == 0)
+        n = 1;
+#endif
+      result = malloc (n);
+    }
+  else
+    result = realloc (p, n);
+
+#if !HAVE_REALLOC_POSIX
+  if (result == NULL)
+    errno = ENOMEM;
+#endif
+
+  return result;
+}
diff --git a/src/lml-options.c b/src/lml-options.c
index 9b16db4..9c79a1d 100644
--- a/src/lml-options.c
+++ b/src/lml-options.c
@@ -474,7 +474,7 @@ static int add_server(lml_log_source_t *ls, const char *addr, unsigned int port)
 {
         config.udp_nserver++;
 
-        config.udp_server = _prelude_realloc(config.udp_server, sizeof(*config.udp_server) * config.udp_nserver);
+        config.udp_server = realloc(config.udp_server, sizeof(*config.udp_server) * config.udp_nserver);
         if ( ! config.udp_server )
                 return -1;
 
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-technologies.com/mailman/listinfo/prelude-cvslog