bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] Re: (x)memdup


From: Paul Eggert
Subject: [Bug-gnulib] Re: (x)memdup
Date: Mon, 04 Oct 2004 23:57:22 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Jim Meyering <address@hidden> writes:
> I like the idea of renaming xclone to xmemdup.

Simon Josefsson wrote:
> Another nit: how about merging xstrdup.c into xmalloc.c?

OK, and while we're on the subject, let's remove XCLONE and the
related macros which have long been marked obsolete.  I installed this
patch into both gnulib and coreutils.

2004-10-04  Paul Eggert  <address@hidden>
 
        * lib/xalloc.h (xmemdup): Renamed from xclone.
        * lib/xmalloc.c (xmemdup): Likewise.
        * lib/xalloc.h (CCLONE, CLONE, NEW, XCALLOC, XMALLOC, XREALLOC,
        XFREE): Remove these long-obsolescent macros.
        * lib/xmalloc.c (xstrdup): Implementation moved here from xstrdup.c
        * lib/xstrdup.c: Remove.

        * m4/xalloc.m4 (gl_PREREQ_XSTRDUP): Remove.  All uses removed.
        
        * modules/xalloc (Files, Makefile.am): Remove xstrdup.c.

Index: lib/xalloc.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xalloc.h,v
retrieving revision 1.26
diff -p -u -r1.26 xalloc.h
--- lib/xalloc.h        9 Aug 2004 18:31:09 -0000       1.26
+++ lib/xalloc.h        5 Oct 2004 06:43:32 -0000
@@ -53,8 +53,8 @@ void *xrealloc (void *p, size_t s);
 void *xnrealloc (void *p, size_t n, size_t s);
 void *x2realloc (void *p, size_t *pn);
 void *x2nrealloc (void *p, size_t *pn, size_t s);
-void *xclone (void const *p, size_t s);
-char *xstrdup (const char *str);
+void *xmemdup (void const *p, size_t s);
+char *xstrdup (char const *str);
 
 /* Return 1 if an array of N objects, each of size S, cannot exist due
    to size arithmetic overflow.  S must be positive and N must be
@@ -71,17 +71,6 @@ char *xstrdup (const char *str);
 # define xalloc_oversized(n, s) \
     ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
 
-/* These macros are deprecated; they will go away soon, and are retained
-   temporarily only to ease conversion to the functions described above.  */
-# define CCLONE(p, n) xclone (p, (n) * sizeof *(p))
-# define CLONE(p) xclone (p, sizeof *(p))
-# define NEW(type, var) type *var = xmalloc (sizeof (type))
-# define XCALLOC(type, n) xcalloc (n, sizeof (type))
-# define XMALLOC(type, n) xnmalloc (n, sizeof (type))
-# define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type))
-# define XFREE(p) free (p)
-
-
 # ifdef __cplusplus
 }
 # endif
Index: lib/xmalloc.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xmalloc.c,v
retrieving revision 1.34
diff -p -u -r1.34 xmalloc.c
--- lib/xmalloc.c       9 Aug 2004 18:31:09 -0000       1.34
+++ lib/xmalloc.c       5 Oct 2004 06:43:32 -0000
@@ -211,11 +211,19 @@ xcalloc (size_t n, size_t s)
 }
 
 /* Clone an object P of size S, with error checking.  There's no need
-   for xnclone (P, N, S), since xclone (P, N * S) works without any
+   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
    need for an arithmetic overflow check.  */
 
 void *
-xclone (void const *p, size_t s)
+xmemdup (void const *p, size_t s)
 {
   return memcpy (xmalloc (s), p, s);
 }
+
+/* Clone STRING.  */
+
+char *
+xstrdup (char const *string)
+{
+  return xmemdup (string, strlen (string) + 1);
+}
Index: m4/xalloc.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/xalloc.m4,v
retrieving revision 1.11
diff -p -u -r1.11 xalloc.m4
--- m4/xalloc.m4        1 Jun 2004 03:49:49 -0000       1.11
+++ m4/xalloc.m4        5 Oct 2004 06:43:33 -0000
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 9
+# xalloc.m4 serial 10
 dnl Copyright (C) 2002-2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -10,7 +10,6 @@ AC_DEFUN([gl_XALLOC],
 [
   gl_PREREQ_XALLOC
   gl_PREREQ_XMALLOC
-  gl_PREREQ_XSTRDUP
 ])
 
 # Prerequisites of lib/xalloc.h.
@@ -23,8 +22,3 @@ AC_DEFUN([gl_PREREQ_XMALLOC], [
   AC_REQUIRE([AC_C_INLINE])
   :
 ])
-
-# Prerequisites of lib/xstrdup.c.
-AC_DEFUN([gl_PREREQ_XSTRDUP], [
-  :
-])
Index: modules/xalloc
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/xalloc,v
retrieving revision 1.13
diff -p -u -r1.13 xalloc
--- modules/xalloc      22 Sep 2004 15:11:04 -0000      1.13
+++ modules/xalloc      5 Oct 2004 06:43:33 -0000
@@ -4,7 +4,6 @@ Memory allocation with out-of-memory che
 Files:
 lib/xalloc.h
 lib/xmalloc.c
-lib/xstrdup.c
 m4/xalloc.m4
 
 Depends-on:
@@ -13,7 +12,7 @@ configure.ac:
 gl_XALLOC
 
 Makefile.am:
-lib_SOURCES += xalloc.h xmalloc.c xstrdup.c
+lib_SOURCES += xalloc.h xmalloc.c
 
 Include:
 "xalloc.h"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]