Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/safe-alloc.h @ 14351:724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
* lib/di-set.h (_GL_ATTRIBUTE_NONNULL): Renamed from
_ATTRIBUTE_NONNULL_.
* lib/ino-map.h (_GL_ATTRIBUTE_NONNULL): Likewise.
* lib/hash.h (_GL_ATTRIBUTE_WUR): Renamed from ATTRIBUTE_WUR.
* lib/ignore-value.h (_GL_ATTRIBUTE_DEPRECATED): Renamed from
ATTRIBUTE_DEPRECATED.
* lib/openat.h (_GL_ATTRIBUTE_NORETURN): Renamed from
ATTRIBUTE_NORETURN.
* lib/sigpipe-die.h (_GL_ATTRIBUTE_NORETURN): Likewise.
* lib/xmemdup0.h (_GL_ATTRIBUTE_NORETURN): Likewise.
* lib/xstrtol.h (_GL_ATTRIBUTE_NORETURN): Likewise.
* lib/xalloc.h (_GL_ATTRIBUTE_NORETURN): Likewise.
(_GL_ATTRIBUTE_MALLOC): Renamed from ATTRIBUTE_MALLOC.
(_GL_ATTRIBUTE_ALLOC_SIZE): Renamed from ATTRIBUTE_ALLOC_SIZE.
* lib/version-etc.h (_GL_ATTRIBUTE_SENTINEL): Renamed from
ATTRIBUTE_SENTINEL.
* lib/safe-alloc.h (_GL_ATTRIBUTE_RETURN_CHECK): Renamed from
ATTRIBUTE_RETURN_CHECK.
* tests/test-ignore-value.c (_GL_ATTRIBUTE_RETURN_CHECK): Likewise.
* tests/test-argmatch.c (_GL_ATTRIBUTE_NORETURN): Renamed from
ATTRIBUTE_NORETURN.
* tests/test-exclude.c (_GL_ATTRIBUTE_NORETURN): Likewise.
Reported by Paul Eggert.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 13 Feb 2011 23:44:28 +0100 |
parents | 97fc9a21a8fb |
children | 8250f2777afc |
rev | line source |
---|---|
12023
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
1 /* safe-alloc.h: safer memory allocation |
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
2 |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
13051
diff
changeset
|
3 Copyright (C) 2009-2011 Free Software Foundation, Inc. |
12023
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
4 |
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it |
12024
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
6 under the terms of the GNU General Public License as published by the |
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
7 Free Software Foundation; either version 3 of the License, or any |
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
8 later version. |
12023
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
9 |
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
12024
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
13 GNU General Public License for more details. |
12023
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
14 |
12024
200a0145c440
Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
12023
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
12023
e1d31e5feef2
Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents:
11253
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
11173 | 17 |
18 /* Written by Daniel Berrange <berrange@redhat.com>, 2008 */ | |
19 | |
20 #ifndef SAFE_ALLOC_H_ | |
21 # define SAFE_ALLOC_H_ | |
22 | |
23 # include <stdlib.h> | |
24 | |
11253
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
25 #ifndef __GNUC_PREREQ |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
26 # if defined __GNUC__ && defined __GNUC_MINOR__ |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
27 # define __GNUC_PREREQ(maj, min) \ |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
28 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
29 # else |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
30 # define __GNUC_PREREQ(maj, min) 0 |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
31 # endif |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
32 #endif |
c90f22b1783e
Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents:
11204
diff
changeset
|
33 |
14351
724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
34 # ifndef _GL_ATTRIBUTE_RETURN_CHECK |
11173 | 35 # if __GNUC_PREREQ (3, 4) |
14351
724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
36 # define _GL_ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__)) |
11173 | 37 # else |
14351
724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
38 # define _GL_ATTRIBUTE_RETURN_CHECK |
11173 | 39 # endif |
40 # endif | |
41 | |
42 /* Don't call these directly - use the macros below */ | |
43 int | |
44 safe_alloc_alloc_n (void *ptrptr, size_t size, size_t count, int zeroed) | |
14351
724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
45 _GL_ATTRIBUTE_RETURN_CHECK; |
11173 | 46 |
47 int | |
48 safe_alloc_realloc_n (void *ptrptr, size_t size, size_t count) | |
14351
724011432f7b
Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
49 _GL_ATTRIBUTE_RETURN_CHECK; |
11173 | 50 |
51 /** | |
52 * ALLOC: | |
53 * @ptr: pointer to hold address of allocated memory | |
54 * | |
55 * Allocate sizeof(*ptr) bytes of memory and store | |
56 * the address of allocated memory in 'ptr'. Fill the | |
57 * newly allocated memory with zeros. | |
58 * | |
59 * Return -1 on failure to allocate, zero on success | |
60 */ | |
61 # define ALLOC(ptr) \ | |
13051 | 62 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), 1, 1) |
11173 | 63 |
64 /** | |
65 * ALLOC_N: | |
66 * @ptr: pointer to hold address of allocated memory | |
67 * @count: number of elements to allocate | |
68 * | |
69 * Allocate an array of 'count' elements, each sizeof(*ptr) | |
70 * bytes long and store the address of allocated memory in | |
71 * 'ptr'. Fill the newly allocated memory with zeros. | |
72 * | |
73 * Return -1 on failure, 0 on success | |
74 */ | |
75 # define ALLOC_N(ptr, count) \ | |
13051 | 76 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), (count), 1) |
11173 | 77 |
78 /** | |
79 * ALLOC_N_UNINITIALIZED: | |
80 * @ptr: pointer to hold address of allocated memory | |
81 * @count: number of elements to allocate | |
82 * | |
83 * Allocate an array of 'count' elements, each sizeof(*ptr) | |
84 * bytes long and store the address of allocated memory in | |
85 * 'ptr'. Do not initialize the new memory at all. | |
86 * | |
87 * Return -1 on failure to allocate, zero on success | |
88 */ | |
89 # define ALLOC_N_UNINITIALIZED(ptr, count) \ | |
13051 | 90 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), (count), 0) |
11173 | 91 |
92 /** | |
93 * REALLOC_N: | |
94 * @ptr: pointer to hold address of allocated memory | |
95 * @count: number of elements to allocate | |
96 * | |
97 * Re-allocate an array of 'count' elements, each sizeof(*ptr) | |
98 * bytes long and store the address of allocated memory in | |
99 * 'ptr'. Fill the newly allocated memory with zeros | |
100 * | |
101 * Return -1 on failure to reallocate, zero on success | |
102 */ | |
103 # define REALLOC_N(ptr, count) \ | |
13051 | 104 safe_alloc_realloc_n (&(ptr), sizeof (*(ptr)), (count)) |
11173 | 105 |
106 /** | |
107 * FREE: | |
108 * @ptr: pointer holding address to be freed | |
109 * | |
110 * Free the memory stored in 'ptr' and update to point | |
111 * to NULL. | |
112 */ | |
113 # define FREE(ptr) \ | |
114 do \ | |
115 { \ | |
11204
55b4123a6159
Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents:
11173
diff
changeset
|
116 free (ptr); \ |
11173 | 117 (ptr) = NULL; \ |
118 } \ | |
13051 | 119 while (0) |
11173 | 120 |
121 #endif /* SAFE_ALLOC_H_ */ |