bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 2/3] xalloc: better 'inline'


From: Paul Eggert
Subject: [PATCH 2/3] xalloc: better 'inline'
Date: Tue, 30 Oct 2012 11:09:27 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

* 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'.
---
 ChangeLog      | 11 ++++++++
 lib/xalloc.h   | 81 +++++++++++++++++++++++++---------------------------------
 lib/xmalloc.c  |  6 ++---
 m4/xalloc.m4   | 19 ++------------
 modules/xalloc |  2 +-
 5 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ebf5c5c..47d03c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2012-10-29  Paul Eggert  <address@hidden>
 
+       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):
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 6f5b87e..acf30a1 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -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"
 
-# ifdef __cplusplus
+_GL_INLINE_HEADER_BEGIN
+#ifndef XALLOC_INLINE
+# define XALLOC_INLINE _GL_INLINE
+#endif
+
+#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 @@ char *xstrdup (char const *str)
 
 /* 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))))
-
-
-# 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
+#define XCALLOC(n, t) \
+   ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
 
-# 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 @@ xnmalloc (size_t n, size_t s)
 /* 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 @@ xnrealloc (void *p, size_t n, size_t s)
 
    */
 
-static_inline void *
+XALLOC_INLINE void *
 x2nrealloc (void *p, size_t *pn, size_t s)
 {
   size_t n = *pn;
@@ -218,17 +209,15 @@ x2nrealloc (void *p, size_t *pn, size_t s)
 /* 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 @@ xmemdup (T const *p, size_t s)
   return (T *) xmemdup ((void const *) p, s);
 }
 
-# endif
+#endif
 
 
 #endif /* !XALLOC_H_ */
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index 3b5f86c..9755985 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -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>
diff --git a/m4/xalloc.m4 b/m4/xalloc.m4
index f47b649..6c2d5d0 100644
--- a/m4/xalloc.m4
+++ b/m4/xalloc.m4
@@ -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], [:])
diff --git a/modules/xalloc b/modules/xalloc
index 19e7a0b..c6c2083 100644
--- a/modules/xalloc
+++ b/modules/xalloc
@@ -7,7 +7,7 @@ lib/xmalloc.c
 m4/xalloc.m4
 
 Depends-on:
-inline
+extern-inline
 xalloc-die
 xalloc-oversized
 
-- 
1.7.11.7




reply via email to

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