ref: 0780817a61528391d7a85023b3c3c23ef6565729
parent: 07eac1779377b88e553d053bf4ad5a0690f76e47
author: David Turner <[email protected]>
date: Thu Mar 3 08:58:13 EST 2005
* include/freetype/internal/{ftmemory.h,ftserv.h}: removing compiler warnings with GCC 3.3 and above...
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -43,6 +43,7 @@
( ( error = (expression) ) != 0 )
+
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
@@ -367,6 +368,47 @@
/* 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_ ) )
@@ -373,9 +415,6 @@
#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_ ) )
@@ -382,34 +421,39 @@
#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_ ) )
/* */
--- a/include/freetype/internal/ftserv.h
+++ b/include/freetype/internal/ftserv.h
@@ -57,18 +57,32 @@
* 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 @@
* 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,11 +227,12 @@
* ptr ::
* A variable receiving the service data. NULL if not available.
*/
+#ifdef __cplusplus
+
#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; \
+ FT_Pointer* Pptr = (FT_Pointer*)&(ptr); \
\
\
svc = FT_FACE(face)->internal->services. service_ ## id; \
@@ -217,9 +246,31 @@
(FT_Pointer)( svc != NULL ? svc \
: FT_SERVICE_UNAVAILABLE ); \
} \
- *pptr = svc; \
+ *Pptr = svc; \
FT_END_STMNT
+#else /* !C++ */
+
+#define FT_FACE_LOOKUP_SERVICE( face, ptr, id ) \
+ FT_BEGIN_STMNT \
+ FT_Pointer svc; \
+ \
+ \
+ 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 ); \
+ } \
+ ptr = svc; \
+ FT_END_STMNT
+
+#endif /* !C++ */
/*
* A macro used to define new service structure types.