[77] | 1 | /* $Id: xmalloc.h 13 2011-04-20 15:41:43Z mmamonski $ */ |
---|
| 2 | /* |
---|
| 3 | * PSNC DRMAA 2.0 utilities library |
---|
| 4 | * Copyright (C) 2012 Poznan Supercomputing and Networking Center |
---|
| 5 | * |
---|
| 6 | * This program is free software: you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * @file xmalloc.h |
---|
| 22 | * Memory allocation/deallocation routines. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef __DRMAA_UTILS__XMALLOC_H |
---|
| 26 | #define __DRMAA_UTILS__XMALLOC_H |
---|
| 27 | |
---|
| 28 | #ifdef HAVE_CONFIG_H |
---|
| 29 | # include <config.h> |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | #include <drmaa_utils/compat.h> |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * @defgroup xmalloc Memory allocation/deallocation routines. |
---|
| 36 | */ |
---|
| 37 | /* @{ */ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * Allocates <code> sizeof(type) </code> bytes. Address of block is stored |
---|
| 42 | * in @a p. Upon failure FSD_ERRNO_NO_MEMORY is raised and @a p is NULL. |
---|
| 43 | */ |
---|
| 44 | #define fsd_malloc( p, type ) \ |
---|
| 45 | fsd_malloc_( (void**)(void*)&(p), sizeof(type) ) |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Allocates <code> n * sizeof(type) </code> bytes of memory and stores |
---|
| 49 | * address in \a p. Allocated block is filled with zeros. Upon failure |
---|
| 50 | * error FSD_ERRNO_NO_MEMORY is raised. |
---|
| 51 | * \c NULL is assigned to \a p on error or when <code> n == 0 </code>. |
---|
| 52 | */ |
---|
| 53 | #define fsd_calloc( p, n, type ) \ |
---|
| 54 | fsd_calloc_( (void**)(void*)&(p), (n), sizeof(type) ) |
---|
| 55 | |
---|
| 56 | #define fsd_realloc( p, n, type ) \ |
---|
| 57 | fsd_realloc_( (void**)(void*)&(p), (n)*sizeof(type) ) |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Fress previously allocated memory pointed by @a p. |
---|
| 61 | * When <code> p == NULL </code> it does nothing. |
---|
| 62 | */ |
---|
| 63 | void fsd_free( void *p ); |
---|
| 64 | |
---|
| 65 | void *fsd_malloc_( void **p, size_t size ); |
---|
| 66 | void *fsd_calloc_( void **p, size_t n, size_t size ); |
---|
| 67 | void *fsd_realloc_( void **p, size_t size ); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | #define fsd_malloc_noraise( p, type ) \ |
---|
| 71 | fsd_malloc_noraise_( (void**)(void*)&(p), sizeof(type) ) |
---|
| 72 | |
---|
| 73 | #define fsd_calloc_noraise( p, n, type ) \ |
---|
| 74 | fsd_calloc_noraise_( (void**)(void*)&(p), (n), sizeof(type) ) |
---|
| 75 | |
---|
| 76 | #define fsd_realloc_noraise( p, n, type ) \ |
---|
| 77 | fsd_realloc_noraise_( (void**)(void*)&(p), (n)*sizeof(type) ) |
---|
| 78 | |
---|
| 79 | #define fsd_free_noraise( p ) (fsd_free(p), 0) |
---|
| 80 | |
---|
| 81 | int fsd_malloc_noraise_( void **p, size_t size ); |
---|
| 82 | int fsd_calloc_noraise_( void **p, size_t n, size_t size ); |
---|
| 83 | int fsd_realloc_noraise_( void **p, size_t size ); |
---|
| 84 | |
---|
| 85 | /* @} */ |
---|
| 86 | |
---|
| 87 | #endif /* __DRMAA_UTILS__XMALLOC_H */ |
---|
| 88 | |
---|