* include/freetype/internal/{ftmemory.h,ftserv.h}: removing compiler warnings with GCC 3.3 and above...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index 6308061..0715b57 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -43,6 +43,7 @@ FT_BEGIN_HEADER
( ( error = (expression) ) != 0 )
+
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
@@ -367,49 +368,92 @@ FT_BEGIN_HEADER
/* if an error occured (i.e. if 'error != 0'). */
/* */
+
+/* GCC 3.3 and beyond will generate tons of _stupid_ warnings if we
+ * don't take special measures.
+ */
+#if defined(__GNUC__) && ( __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) )
+
+#define FT_ALLOC( _pointer_, _size_ ) \
+ ({ \
+ void* _tmp_ = NULL; \
+ error = FT_MEM_ALLOC( _tmp_, _size_ ); \
+ _pointer_ = _tmp_; \
+ error != 0; \
+ })
+
+#define FT_REALLOC( _pointer_, _cursize_, _newsize_ ) \
+ ({ \
+ void* _tmp_ = _pointer_; \
+ error = FT_MEM_REALLOC( _tmp_, _cursize_, _newsize_ ); \
+ _pointer_ = _tmp_; \
+ error != 0; \
+ })
+
+#define FT_QALLOC( _pointer_, _size_ ) \
+ ({ \
+ void* _tmp_; \
+ error = FT_MEM_QALLOC( _tmp_, _size_ ); \
+ _pointer_ = _tmp_; \
+ error != 0; \
+ })
+
+#define FT_QREALLOC( _pointer_, _cursize_, _newsize_ ) \
+ ({ \
+ void* _tmp_ = _pointer_; \
+ error = FT_MEM_QREALLOC( _tmp_, _cursize_, _newsize_ ); \
+ _pointer_ = _tmp_; \
+ error != 0; \
+ })
+
+
+#else /* !GCC || GCC < 3.3 */
+
#define FT_ALLOC( _pointer_, _size_ ) \
FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, _size_ ) )
#define FT_REALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, _current_, _size_ ) )
-#define FT_FREE( _pointer_ ) \
- FT_MEM_FREE( _pointer_ )
-
#define FT_QALLOC( _pointer_, _size_ ) \
FT_SET_ERROR( FT_MEM_QALLOC( _pointer_, _size_ ) )
#define FT_QREALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR( FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) )
+#endif /* !GCC || GCC < 3.3 */
+
+#define FT_FREE( _pointer_ ) \
+ FT_MEM_FREE( _pointer_ )
+
#define FT_NEW( _pointer_ ) \
- FT_SET_ERROR( FT_MEM_NEW( _pointer_ ) )
+ FT_ALLOC( _pointer_, sizeof(*(_pointer_)) )
#define FT_NEW_ARRAY( _pointer_, _count_ ) \
- FT_SET_ERROR( FT_MEM_NEW_ARRAY( _pointer_, _count_ ) )
+ FT_ALLOC( _pointer_, sizeof(*(_pointer_))*(_count_) )
-#define FT_RENEW_ARRAY( _pointer_, _old_, _new_ ) \
- FT_SET_ERROR( FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ ) )
+#define FT_RENEW_ARRAY( _pointer_, _old_, _new_ ) \
+ FT_REALLOC( _pointer_, sizeof(*(_pointer_))*(_old_), \
+ sizeof(*(_pointer_))*(_new_) )
#define FT_QNEW( _pointer_ ) \
- FT_SET_ERROR( FT_MEM_QNEW( _pointer_ ) )
+ FT_QALLOC( _pointer_, sizeof(*(_pointer_)) )
#define FT_QNEW_ARRAY( _pointer_, _count_ ) \
- FT_SET_ERROR( FT_MEM_QNEW_ARRAY( _pointer_, _count_ ) )
+ FT_QALLOC( _pointer_, sizeof(*(_pointer_))*(_count_) )
-#define FT_QRENEW_ARRAY( _pointer_, _old_, _new_ ) \
- FT_SET_ERROR( FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) )
+#define FT_QRENEW_ARRAY( _pointer_, _old_, _new_ ) \
+ FT_QREALLOC( _pointer_, sizeof(*(_pointer_))*(_old_), \
+ sizeof(*(_pointer_))*(_new_) )
-#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
- FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, \
- (_count_) * sizeof ( _type_ ) ) )
+#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
+ FT_ALLOC( _pointer_, (_count_)*sizeof( _type_ ) )
-#define FT_REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) \
- FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, \
- (_old_) * sizeof ( _type_ ), \
- (_new_) * sizeof ( _type_ ) ) )
+#define FT_REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) \
+ FT_REALLOC( _pointer, (_old_) * sizeof ( _type_ ), \
+ (_new_) * sizeof ( _type_ ) )
/* */
diff --git a/include/freetype/internal/ftserv.h b/include/freetype/internal/ftserv.h
index 364ebe8..fbf8654 100644
--- a/include/freetype/internal/ftserv.h
+++ b/include/freetype/internal/ftserv.h
@@ -57,18 +57,32 @@ FT_BEGIN_HEADER
* A variable that receives the service pointer. Will be NULL
* if not found.
*/
+#ifdef __cplusplus
+
#define FT_FACE_FIND_SERVICE( face, ptr, id ) \
FT_BEGIN_STMNT \
FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
- /* the strange cast is to allow C++ compilation */ \
- FT_Pointer* Pptr = (FT_Pointer*) &(ptr); \
+ FT_Pointer _tmp_ = NULL; \
+ FT_Pointer* _pptr_ = (FT_Pointer*)&(ptr); \
\
+ if ( module->clazz->get_interface ) \
+ _tmp_ = module->clazz->get_interface( module, FT_SERVICE_ID_ ## id ); \
+ *_pptr_ = _tmp_; \
+ FT_END_STMNT
+
+#else /* !C++ */
+
+#define FT_FACE_FIND_SERVICE( face, ptr, id ) \
+ FT_BEGIN_STMNT \
+ FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
+ FT_Pointer _tmp_ = NULL; \
\
- *Pptr = NULL; \
if ( module->clazz->get_interface ) \
- *Pptr = module->clazz->get_interface( module, FT_SERVICE_ID_ ## id ); \
+ _tmp_ = module->clazz->get_interface( module, FT_SERVICE_ID_ ## id ); \
+ ptr = _tmp_; \
FT_END_STMNT
+#endif /* !C++ */
/*
* @macro:
@@ -92,16 +106,30 @@ FT_BEGIN_HEADER
* A variable that receives the service pointer. Will be NULL
* if not found.
*/
+#ifdef __cplusplus
+
#define FT_FACE_FIND_GLOBAL_SERVICE( face, ptr, id ) \
FT_BEGIN_STMNT \
FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
- /* the strange cast is to allow C++ compilation */ \
- FT_Pointer* Pptr = (FT_Pointer*) &(ptr); \
+ FT_Pointer _tmp_; \
+ FT_Pointer _pptr_ = (FT_Pointer*)&(ptr); \
\
+ _tmp_ = ft_module_get_service( module, FT_SERVICE_ID_ ## id ); \
+ *_pptr_ = _tmp_; \
+ FT_END_STMNT
+
+#else /* !C++ */
+
+#define FT_FACE_FIND_GLOBAL_SERVICE( face, ptr, id ) \
+ FT_BEGIN_STMNT \
+ FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
+ FT_Pointer _tmp_; \
\
- *Pptr = ft_module_get_service( module, FT_SERVICE_ID_ ## id ); \
+ _tmp_ = ft_module_get_service( module, FT_SERVICE_ID_ ## id ); \
+ ptr = _tmp_; \
FT_END_STMNT
+#endif /* !C++ */
/*************************************************************************/
/*************************************************************************/
@@ -199,10 +227,32 @@ FT_BEGIN_HEADER
* ptr ::
* A variable receiving the service data. NULL if not available.
*/
+#ifdef __cplusplus
+
+#define FT_FACE_LOOKUP_SERVICE( face, ptr, id ) \
+ FT_BEGIN_STMNT \
+ FT_Pointer svc; \
+ FT_Pointer* Pptr = (FT_Pointer*)&(ptr); \
+ \
+ \
+ svc = FT_FACE(face)->internal->services. service_ ## id; \
+ if ( svc == FT_SERVICE_UNAVAILABLE ) \
+ svc = NULL; \
+ else if ( svc == NULL ) \
+ { \
+ FT_FACE_FIND_SERVICE( face, svc, id ); \
+ \
+ FT_FACE(face)->internal->services. service_ ## id = \
+ (FT_Pointer)( svc != NULL ? svc \
+ : FT_SERVICE_UNAVAILABLE ); \
+ } \
+ *Pptr = svc; \
+ FT_END_STMNT
+
+#else /* !C++ */
+
#define FT_FACE_LOOKUP_SERVICE( face, ptr, id ) \
FT_BEGIN_STMNT \
- /* the strange cast is to allow C++ compilation */ \
- FT_Pointer* pptr = (FT_Pointer*)&(ptr); \
FT_Pointer svc; \
\
\
@@ -217,9 +267,10 @@ FT_BEGIN_HEADER
(FT_Pointer)( svc != NULL ? svc \
: FT_SERVICE_UNAVAILABLE ); \
} \
- *pptr = svc; \
+ ptr = svc; \
FT_END_STMNT
+#endif /* !C++ */
/*
* A macro used to define new service structure types.