changeset 17177:902795f52835

xalloc: better 'inline' * lib/xmalloc.c, lib/xalloc.h (XALLOC_INLINE): New macro. Replace all uses of 'static inline' with it. (static_inline): Remove. * lib/xalloc.h (xnmalloc, xnrealloc, x2nrealloc, xcharalloc): Let 'extern inline' do the work automatically, instead of doing it by hand. * m4/xalloc.m4 (gl_PREREQ_XALLOC, gl_PREREQ_XMALLOC): Remove. All uses removed. * modules/xalloc (Depends-on): Remove 'inline'. Add 'extern-inline'.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 20 Nov 2012 22:25:07 -0800
parents fe213f3f2c57
children 86c983ca0522
files ChangeLog lib/xalloc.h lib/xmalloc.c m4/xalloc.m4 modules/xalloc
diffstat 5 files changed, 51 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 20 22:25:07 2012 -0800
+++ b/ChangeLog	Tue Nov 20 22:25:07 2012 -0800
@@ -1,5 +1,16 @@
 2012-11-29  Paul Eggert  <eggert@cs.ucla.edu>
 
+	xalloc: better 'inline'
+	* lib/xmalloc.c, lib/xalloc.h (XALLOC_INLINE):
+	New macro.  Replace all uses of 'static inline' with it.
+	(static_inline): Remove.
+	* lib/xalloc.h (xnmalloc, xnrealloc, x2nrealloc, xcharalloc):
+	Let 'extern inline' do the work automatically, instead of doing
+	it by hand.
+	* m4/xalloc.m4 (gl_PREREQ_XALLOC, gl_PREREQ_XMALLOC):
+	Remove.  All uses removed.
+	* modules/xalloc (Depends-on): Remove 'inline'.  Add 'extern-inline'.
+
 	gethrxtime: better 'inline'
 	* lib/xtime.c: New file.
 	* lib/gethrxtime.c, lib/gethrxtime.h (GETHRXTIME_INLINE):
--- a/lib/xalloc.h	Tue Nov 20 22:25:07 2012 -0800
+++ b/lib/xalloc.h	Tue Nov 20 22:25:07 2012 -0800
@@ -16,28 +16,33 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifndef XALLOC_H_
-# define XALLOC_H_
+#define XALLOC_H_
 
-# include <stddef.h>
+#include <stddef.h>
+
+#include "xalloc-oversized.h"
 
-# include "xalloc-oversized.h"
+_GL_INLINE_HEADER_BEGIN
+#ifndef XALLOC_INLINE
+# define XALLOC_INLINE _GL_INLINE
+#endif
 
-# ifdef __cplusplus
+#ifdef __cplusplus
 extern "C" {
-# endif
+#endif
 
 
-# if __GNUC__ >= 3
-#  define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-# else
-#  define _GL_ATTRIBUTE_MALLOC
-# endif
+#if __GNUC__ >= 3
+# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define _GL_ATTRIBUTE_MALLOC
+#endif
 
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-#  define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
-# else
-#  define _GL_ATTRIBUTE_ALLOC_SIZE(args)
-# endif
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
+#else
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
+#endif
 
 /* This function is always triggered when memory is exhausted.
    It must be defined by the application, either explicitly
@@ -67,45 +72,31 @@
 
 /* Allocate an object of type T dynamically, with error checking.  */
 /* extern t *XMALLOC (typename t); */
-# define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
+#define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
 
 /* Allocate memory for N elements of type T, with error checking.  */
 /* extern t *XNMALLOC (size_t n, typename t); */
-# define XNMALLOC(n, t) \
-    ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
+#define XNMALLOC(n, t) \
+   ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
 
 /* Allocate an object of type T dynamically, with error checking,
    and zero it.  */
 /* extern t *XZALLOC (typename t); */
-# define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
+#define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
 
 /* Allocate memory for N elements of type T, with error checking,
    and zero it.  */
 /* extern t *XCALLOC (size_t n, typename t); */
-# define XCALLOC(n, t) \
-    ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
-
+#define XCALLOC(n, t) \
+   ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
 
-# if HAVE_INLINE
-#  define static_inline static inline
-# else
-void *xnmalloc (size_t n, size_t s)
-      _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
-void *xnrealloc (void *p, size_t n, size_t s)
-      _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
-void *x2nrealloc (void *p, size_t *pn, size_t s);
-char *xcharalloc (size_t n)
-      _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
-# endif
-
-# ifdef static_inline
 
 /* Allocate an array of N objects, each with S bytes of memory,
    dynamically, with error checking.  S must be nonzero.  */
 
-static_inline void *xnmalloc (size_t n, size_t s)
+XALLOC_INLINE void *xnmalloc (size_t n, size_t s)
                     _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
-static_inline void *
+XALLOC_INLINE void *
 xnmalloc (size_t n, size_t s)
 {
   if (xalloc_oversized (n, s))
@@ -116,9 +107,9 @@
 /* Change the size of an allocated block of memory P to an array of N
    objects each of S bytes, with error checking.  S must be nonzero.  */
 
-static_inline void *xnrealloc (void *p, size_t n, size_t s)
+XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s)
                     _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
-static_inline void *
+XALLOC_INLINE void *
 xnrealloc (void *p, size_t n, size_t s)
 {
   if (xalloc_oversized (n, s))
@@ -181,7 +172,7 @@
 
    */
 
-static_inline void *
+XALLOC_INLINE void *
 x2nrealloc (void *p, size_t *pn, size_t s)
 {
   size_t n = *pn;
@@ -218,17 +209,15 @@
 /* Return a pointer to a new buffer of N bytes.  This is like xmalloc,
    except it returns char *.  */
 
-static_inline char *xcharalloc (size_t n)
+XALLOC_INLINE char *xcharalloc (size_t n)
                     _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
-static_inline char *
+XALLOC_INLINE char *
 xcharalloc (size_t n)
 {
   return XNMALLOC (n, char);
 }
 
-# endif
-
-# ifdef __cplusplus
+#ifdef __cplusplus
 }
 
 /* C++ does not allow conversions from void * to other pointer types
@@ -265,7 +254,7 @@
   return (T *) xmemdup ((void const *) p, s);
 }
 
-# endif
+#endif
 
 
 #endif /* !XALLOC_H_ */
--- a/lib/xmalloc.c	Tue Nov 20 22:25:07 2012 -0800
+++ b/lib/xmalloc.c	Tue Nov 20 22:25:07 2012 -0800
@@ -17,11 +17,9 @@
 
 #include <config.h>
 
-#if ! HAVE_INLINE
-# define static_inline
-#endif
+#define XALLOC_INLINE _GL_EXTERN_INLINE
+
 #include "xalloc.h"
-#undef static_inline
 
 #include <stdlib.h>
 #include <string.h>
--- a/m4/xalloc.m4	Tue Nov 20 22:25:07 2012 -0800
+++ b/m4/xalloc.m4	Tue Nov 20 22:25:07 2012 -0800
@@ -1,22 +1,7 @@
-# xalloc.m4 serial 17
+# xalloc.m4 serial 18
 dnl Copyright (C) 2002-2006, 2009-2012 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.
 
-AC_DEFUN([gl_XALLOC],
-[
-  gl_PREREQ_XALLOC
-  gl_PREREQ_XMALLOC
-])
-
-# Prerequisites of lib/xalloc.h.
-AC_DEFUN([gl_PREREQ_XALLOC], [
-  AC_REQUIRE([gl_INLINE])
-  :
-])
-
-# Prerequisites of lib/xmalloc.c.
-AC_DEFUN([gl_PREREQ_XMALLOC], [
-  :
-])
+AC_DEFUN([gl_XALLOC], [:])
--- a/modules/xalloc	Tue Nov 20 22:25:07 2012 -0800
+++ b/modules/xalloc	Tue Nov 20 22:25:07 2012 -0800
@@ -7,7 +7,7 @@
 m4/xalloc.m4
 
 Depends-on:
-inline
+extern-inline
 xalloc-die
 xalloc-oversized