[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xalloc.h, system.h changes for X2REALLOC etc.
From: |
Paul Eggert |
Subject: |
xalloc.h, system.h changes for X2REALLOC etc. |
Date: |
Wed, 21 Sep 2005 23:36:41 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
When merging from gnulib I discovered I'm still a bit at sea about
what to do about the X2REALLOC and X2NREALLOC macros; instead of
thinking it through I thought it best for now to revert xalloc.h to
gnulib and move the new stuff to src/system.h. I installed this:
2005-09-21 Paul Eggert <address@hidden>
* lib/xalloc.h (VERIFY_EXPR, X2NREALLOC, X2REALLOC): Remove.
The latter two macros are moving to ../src/system.h for now.
This reverts this file to the gnulib version.
* src/system.h (X2NREALLOC, X2REALLOC): Moved here from
../lib/xalloc.h, with args properly parenthesized, and using
verify_expr rather than the old VERIFY_EXPR.
Index: lib/xalloc.h
===================================================================
RCS file: /fetish/cu/lib/xalloc.h,v
retrieving revision 1.32
diff -p -u -r1.32 xalloc.h
--- lib/xalloc.h 13 Sep 2005 21:11:25 -0000 1.32
+++ lib/xalloc.h 22 Sep 2005 06:24:28 -0000
@@ -1,7 +1,7 @@
/* xalloc.h -- malloc with out-of-memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -56,24 +56,6 @@ void *x2nrealloc (void *p, size_t *pn, s
void *xmemdup (void const *p, size_t s);
char *xstrdup (char const *str);
-/* Verify a requirement at compile-time (unlike assert, which is runtime). */
-# undef VERIFY_EXPR
-# define VERIFY_EXPR(assertion) \
- (void)((struct {char a[(assertion) ? 1 : -1]; } *) 0)
-
-/* This is simply a shorthand for the common case in which
- the third argument to x2nrealloc would be `sizeof (*P)'.
- Ensure that sizeof (*P) is *not* 1. In that case, it'd be
- better to use X2REALLOC, although not strictly necessary. */
-# define X2NREALLOC(P, PN) (VERIFY_EXPR (sizeof(*P) != 1), \
- x2nrealloc (P, PN, sizeof (*P)))
-
-/* Using x2realloc (when appropriate) usually makes your code more
- readable than using x2nrealloc, but it also makes it so your
- code will malfunction if sizeof (*P) ever becomes 2 or greater.
- So use this macro instead of using x2realloc directly. */
-# define X2REALLOC(P, PN) (VERIFY_EXPR (sizeof(*P) == 1), x2realloc (P, PN))
-
/* 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
nonnegative. This is a macro, not an inline function, so that it
Index: src/system.h
===================================================================
RCS file: /fetish/cu/src/system.h,v
retrieving revision 1.134
diff -p -u -r1.134 system.h
--- src/system.h 23 Aug 2005 15:05:54 -0000 1.134
+++ src/system.h 22 Sep 2005 06:25:10 -0000
@@ -513,6 +513,20 @@ uid_t getuid ();
#endif
#include "xalloc.h"
+#include "verify.h"
+
+/* This is simply a shorthand for the common case in which
+ the third argument to x2nrealloc would be `sizeof *(P)'.
+ Ensure that sizeof *(P) is *not* 1. In that case, it'd be
+ better to use X2REALLOC, although not strictly necessary. */
+#define X2NREALLOC(P, PN) (verify_expr (sizeof *(P) != 1), \
+ x2nrealloc (P, PN, sizeof *(P)))
+
+/* Using x2realloc (when appropriate) usually makes your code more
+ readable than using x2nrealloc, but it also makes it so your
+ code will malfunction if sizeof *(P) ever becomes 2 or greater.
+ So use this macro instead of using x2realloc directly. */
+#define X2REALLOC(P, PN) (verify_expr (sizeof *(P) == 1), x2realloc (P, PN))
#if ! defined HAVE_MEMPCPY && ! defined mempcpy
/* Be CAREFUL that there are no side effects in N. */
@@ -585,7 +599,6 @@ enum
_(" --version output version information and exit\n")
#include "closeout.h"
-#include "verify.h"
#include "version-etc.h"
#define case_GETOPT_VERSION_CHAR(Program_name, Authors)
\
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- xalloc.h, system.h changes for X2REALLOC etc.,
Paul Eggert <=