upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-macros-private.h
blob228eb277a2f2ddacbd1b00c197200f285b8bd5bf
1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2016 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
22 #ifndef __HKL_MACROS_PRIVATE_H__
23 #define __HKL_MACROS_PRIVATE_H__
25 #include <assert.h> // for assert
26 #include "hkl.h" // for G_BEGIN_DECLS, etc
28 /* specific part for the eulerian -> kappa conversion */
29 #define HKL_EULERIAN_KAPPA_SOLUTION 1
31 /* the assert method */
32 #if !defined(NDEBUG) && !_MSC_VER
33 # include <execinfo.h>
34 # include <assert.h>
35 # define hkl_assert(x) do{ if (!(x)) {hkl_printbt(); assert(x); } } while(0)
36 #else
37 # define hkl_assert(x)
38 #endif
40 #define hkl_error(expr) do{ \
41 if(!(expr)){ \
42 g_error(__STRING(expr)); \
43 } \
44 } while(0)
46 /* use for the printf format methods took from glib */
47 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
48 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
50 /* use for the hkl_list */
51 #define alloc_nr(x) (((x)+16)*3/2)
54 * Realloc the buffer pointed at by variable 'x' so that it can hold
55 * at least 'nr' entries; the number of entries currently allocated
56 * is 'alloc', using the standard growing factor alloc_nr() macro.
58 * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
60 #define ALLOC_GROW(x, nr, alloc) \
61 do { \
62 if ((nr) > alloc) { \
63 if (alloc_nr(alloc) < (nr)) \
64 alloc = (nr); \
65 else \
66 alloc = alloc_nr(alloc); \
67 x = realloc((x), alloc * sizeof(*(x))); \
68 } \
69 } while(0)
71 #ifndef NORETURN
72 # ifdef __GNUC__
73 # define NORETURN __attribute__((__noreturn__))
74 # else
75 # define NORETURN
76 # ifndef __attribute__
77 # define __attribute__(x)
78 # endif
79 # endif
80 #endif
82 #define DARRAY(_items) {.item=_items, .size=ARRAY_SIZE(_items), .alloc=ARRAY_SIZE(_items)}
84 G_BEGIN_DECLS
86 extern void hkl_printbt(void);
88 void *_hkl_malloc(int size, const char *error);
90 G_END_DECLS
92 /* malloc method */
93 #define HKL_MALLOC(type) (type *)_hkl_malloc(sizeof(type), "Can not allocate memory for a " #type)
95 #endif