| 1 |
/* |
| 2 |
* common.h - some common macros |
| 3 |
*/ |
| 4 |
|
| 5 |
|
| 6 |
#ifndef MDJVU_COMMON_H |
| 7 |
#define MDJVU_COMMON_H |
| 8 |
|
| 9 |
|
| 10 |
#ifdef HAVE_CONFIG_H |
| 11 |
#include "config.h" |
| 12 |
#endif |
| 13 |
|
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
# define FUNCTIONS_BEGIN extern "C" { |
| 17 |
# define FUNCTIONS_END } |
| 18 |
#else |
| 19 |
# define FUNCTIONS_BEGIN |
| 20 |
# define FUNCTIONS_END |
| 21 |
#endif |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
|
| 27 |
#ifdef __cplusplus |
| 28 |
/* Stuff for not using malloc in C++ |
| 29 |
* (made by Leon Bottou; has no use in minidjvu, |
| 30 |
* but left here for potential DjVuLibre compatibility) |
| 31 |
*/ |
| 32 |
# define MALLOC1(Type) new Type |
| 33 |
# define FREE1(p) delete (p) |
| 34 |
# define MALLOC(Type,n) new Type[n] |
| 35 |
# define FREE(p) delete [] (p) |
| 36 |
# define REALLOC oops! I hope we have no REALLOC in minidjvu... |
| 37 |
#else |
| 38 |
# define MALLOC1(TYPE) ( (TYPE *) malloc(sizeof(TYPE)) ) |
| 39 |
# define MALLOC(TYPE, N) ( (TYPE *) malloc((N) * sizeof(TYPE)) ) |
| 40 |
# define REALLOC(TYPE, PTR, N) ( (TYPE *) realloc(PTR, (N) * sizeof(TYPE)) ) |
| 41 |
# define FREE1(PTR) free(PTR) |
| 42 |
# define FREE(PTR) free(PTR) |
| 43 |
#endif |
| 44 |
|
| 45 |
/* Yeah, I know this is ugly and there are C++ templates for that. |
| 46 |
* But this is for C code. |
| 47 |
*/ |
| 48 |
#define LIST_APPEND(TYPE, LIST, COUNT, ALLOCATED) \ |
| 49 |
{ \ |
| 50 |
if ((COUNT) == (ALLOCATED)) \ |
| 51 |
{ \ |
| 52 |
(ALLOCATED) <<= 1; /* double the list */ \ |
| 53 |
(LIST) = REALLOC(TYPE, LIST, ALLOCATED); \ |
| 54 |
} \ |
| 55 |
return &(LIST)[(COUNT)++]; \ |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
#endif |