1 /* -*- Mode: c; c-basic-offset: 2 -*- 2 * 3 * rdf_internal.h - Redland RDF Application Framework internal API (header never shipped) 4 * 5 * Copyright (C) 2000-2008, David Beckett http://www.dajobe.org/ 6 * Copyright (C) 2000-2004, University of Bristol, UK http://www.bristol.ac.uk/ 7 * 8 * This package is Free Software and part of Redland http://librdf.org/ 9 * 10 * It is licensed under the following three licenses as alternatives: 11 * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version 12 * 2. GNU General Public License (GPL) V2 or any newer version 13 * 3. Apache License, V2.0 or any newer version 14 * 15 * You may not use this file except in compliance with at least one of 16 * the above three licenses. 17 * 18 * See LICENSE.html or LICENSE.txt at the top of this package for the 19 * complete terms and further detail along with the license texts for 20 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. 21 * 22 * 23 */ 24 25 26 /* This file is never shipped outside the source tree and neither 27 * are any of the included headers files. It is only included 28 * inside librdf.h when LIBRDF_INTERNAL is defined; when compiling 29 * Redland. 30 */ 31 32 #ifndef RDF_INTERNAL_H 33 #define RDF_INTERNAL_H 34 35 #ifdef __cplusplus 36 #define REDLAND_EXTERN_C extern "C" 37 #else 38 #define REDLAND_EXTERN_C 39 #endif 40 41 /* Can be over-ridden or undefined in a config.h file or -Ddefine */ 42 #ifndef REDLAND_INLINE 43 #define REDLAND_INLINE inline 44 #endif 45 46 /* error handling */ 47 #ifdef LIBRDF_DEBUG 48 /* DEBUGGING TURNED ON */ 49 50 /* Debugging messages */ 51 #define LIBRDF_DEBUG1(msg) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__); } while(0) 52 #define LIBRDF_DEBUG2(msg, arg1) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1);} while(0) 53 #define LIBRDF_DEBUG3(msg, arg1, arg2) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2);} while(0) 54 #define LIBRDF_DEBUG4(msg, arg1, arg2, arg3) do {fprintf(stderr, "%s:%d:%s: " msg, __FILE__, __LINE__, __func__, arg1, arg2, arg3);} while(0) 55 56 #define SYSTEM_MALLOC(size) malloc(size) 57 #define SYSTEM_FREE(ptr) free(ptr) 58 59 #ifndef LIBRDF_ASSERT_DIE 60 #define LIBRDF_ASSERT_DIE abort(); 61 #endif 62 63 #else 64 /* DEBUGGING TURNED OFF */ 65 66 /* No debugging messages */ 67 #define LIBRDF_DEBUG1(msg) 68 #define LIBRDF_DEBUG2(msg, arg1) 69 #define LIBRDF_DEBUG3(msg, arg1, arg2) 70 #define LIBRDF_DEBUG4(msg, arg1, arg2, arg3) 71 72 #define SYSTEM_MALLOC(size) malloc(size) 73 #define SYSTEM_FREE(ptr) free(ptr) 74 75 #ifndef LIBRDF_ASSERT_DIE 76 #define LIBRDF_ASSERT_DIE 77 #endif 78 79 #endif 80 81 82 #ifdef LIBRDF_ASSERT_MESSAGES 83 #define LIBRDF_ASSERT_REPORT(msg) fprintf(stderr, "%s:%d: (%s) assertion failed: " msg "\n", __FILE__, __LINE__, __func__); 84 #else 85 #define LIBRDF_ASSERT_REPORT(line) 86 #endif 87 88 89 #ifdef LIBRDF_ASSERT 90 91 #define LIBRDF_ASSERT_CONDITION(condition) do { \ 92 if(!condition) { \ 93 LIBRDF_ASSERT_REPORT("assertion " #condition " failed.") \ 94 LIBRDF_ASSERT_DIE \ 95 return; \ 96 } \ 97 } while(0) 98 99 #define LIBRDF_ASSERT_RETURN(condition, msg, ret) do { \ 100 if(condition) { \ 101 LIBRDF_ASSERT_REPORT(msg) \ 102 LIBRDF_ASSERT_DIE \ 103 return ret; \ 104 } \ 105 } while(0) 106 107 #define LIBRDF_ASSERT_OBJECT_POINTER_RETURN(pointer, type) do { \ 108 if(!pointer) { \ 109 LIBRDF_ASSERT_REPORT("object pointer of type " #type " is NULL.") \ 110 LIBRDF_ASSERT_DIE \ 111 return; \ 112 } \ 113 } while(0) 114 115 #define LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret) do { \ 116 if(!pointer) { \ 117 LIBRDF_ASSERT_REPORT("object pointer of type " #type " is NULL.") \ 118 LIBRDF_ASSERT_DIE \ 119 return ret; \ 120 } \ 121 } while(0) 122 123 #else 124 125 #define LIBRDF_ASSERT_CONDITION(condition) 126 #define LIBRDF_ASSERT_RETURN(condition, msg, ret) 127 #define LIBRDF_ASSERT_OBJECT_POINTER_RETURN(pointer, type) 128 #define LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(pointer, type, ret) 129 130 #endif 131 132 133 /* for the memory allocation functions */ 134 #ifdef HAVE_STDLIB_H 135 #include <stdlib.h> 136 #undef HAVE_STDLIB_H 137 #endif 138 139 #define LIBRDF_MALLOC(type, size) (type)malloc(size) 140 #define LIBRDF_CALLOC(type, size, count) (type)calloc(size, count) 141 #define LIBRDF_FREE(type, ptr) free(ptr) 142 143 /* Fatal errors - always happen */ 144 #define LIBRDF_FATAL1(world, facility, message) librdf_fatal(world, facility, __FILE__, __LINE__ , __func__, message) 145 146 147 /* Safe casts: widening a value */ 148 #define LIBRDF_GOOD_CAST(t, v) (t)(v) 149 150 /* Unsafe casts: narrowing a value */ 151 #define LIBRDF_BAD_CAST(t, v) (t)(v) 152 153 154 #include <rdf_list.h> 155 #include <rdf_files.h> 156 #include <rdf_heuristics.h> 157 158 #endif 159