summaryrefslogtreecommitdiff
path: root/include/freetype/internal/ftmemory.h
diff options
context:
space:
mode:
authorDavid Turner <david@freetype.org>2006-05-03 09:40:33 +0000
committerDavid Turner <david@freetype.org>2006-05-03 09:40:33 +0000
commit679a252c24e3ccbe2dadfacd363139f7e1dd01cb (patch)
tree2cabb382727787bf9a1a37fc23ef9a37950b65df /include/freetype/internal/ftmemory.h
parent58eed04d5aa034c9af3e2919a0b49fc92a4df75b (diff)
downloadfreetype2-679a252c24e3ccbe2dadfacd363139f7e1dd01cb.tar.gz
* include/freetype/internal/ftmemory.h: allow compilation with
C++ compilers
Diffstat (limited to 'include/freetype/internal/ftmemory.h')
-rw-r--r--include/freetype/internal/ftmemory.h99
1 files changed, 58 insertions, 41 deletions
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index de8278ec0..d7f4ded5d 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -57,18 +57,35 @@ FT_BEGIN_HEADER
/*************************************************************************/
+ /* C++ absolutely hates statements like p = (void*)anything; where 'p' is
+ * a typed pointer. Since we don't have a typeof operator in standard C++,
+ * we need some really ugly casts, like:
+ */
+#ifdef __cplusplus
+# define FT_ASSIGNP(p,val) *((void**)&(p)) = (val)
+#else
+# define FT_ASSIGNP(p,val) (p) = (val)
+#endif
+
+
+
#ifdef FT_DEBUG_MEMORY
FT_BASE( const char* ) _ft_debug_file;
FT_BASE( long ) _ft_debug_lineno;
-#define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
- _ft_debug_lineno = __LINE__, \
- (exp) )
+# define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
+ _ft_debug_lineno = __LINE__, \
+ (exp) )
+
+# define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
+ _ft_debug_lineno = __LINE__, \
+ FT_ASSIGNP( p, exp ) )
#else /* !FT_DEBUG_MEMORY */
-#define FT_DEBUG_INNER( exp ) (exp)
+# define FT_DEBUG_INNER( exp ) (exp)
+# define FT_ASSIGNP_INNER( p, exp ) FT_ASSIGNP( p, exp )
#endif /* !FT_DEBUG_MEMORY */
@@ -111,7 +128,7 @@ FT_BEGIN_HEADER
#define FT_MEM_ALLOC( ptr, size ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_alloc( memory, (size), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, (size), &error ) )
#define FT_MEM_FREE( ptr ) \
FT_BEGIN_STMNT \
@@ -122,46 +139,46 @@ FT_BEGIN_HEADER
#define FT_MEM_NEW( ptr ) \
FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
-#define FT_MEM_REALLOC( ptr, cursz, newsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_realloc( memory, 1, \
- (cursz), (newsz), \
- (ptr), &error ) )
+#define FT_MEM_REALLOC( ptr, cursz, newsz ) \
+ FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, 1, \
+ (cursz), (newsz), \
+ (ptr), &error ) )
#define FT_MEM_QALLOC( ptr, size ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qalloc( memory, (size), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, (size), &error ) )
#define FT_MEM_QNEW( ptr ) \
FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
#define FT_MEM_QREALLOC( ptr, cursz, newsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, 1, \
- (cursz), (newsz), \
- (ptr), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, 1, \
+ (cursz), (newsz), \
+ (ptr), &error ) )
#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
- (cursz), (newsz), \
- (ptr), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
+ (cursz), (newsz), \
+ (ptr), &error ) )
#define FT_MEM_ALLOC_MULT( ptr, count, item_size ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_realloc( memory, (item_size), \
- 0, (count), \
- NULL, &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (item_size), \
+ 0, (count), \
+ NULL, &error ) )
#define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_realloc( memory, (itmsz), \
- (oldcnt), (newcnt), \
- (ptr), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (itmsz), \
+ (oldcnt), (newcnt), \
+ (ptr), &error ) )
#define FT_MEM_QALLOC_MULT( ptr, count, item_size ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, (item_size), \
- 0, (count), \
- NULL, &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (item_size), \
+ 0, (count), \
+ NULL, &error ) )
-#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, (itmsz), \
- (oldcnt), (newcnt), \
- (ptr), &error ) )
+#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz) \
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (itmsz), \
+ (oldcnt), (newcnt), \
+ (ptr), &error ) )
#define FT_MEM_SET_ERROR( cond ) ( (cond), error != 0 )
@@ -206,24 +223,24 @@ FT_BEGIN_HEADER
/* */
#define FT_MEM_NEW_ARRAY( ptr, count ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_realloc( memory, sizeof ( *(ptr) ), \
- 0, (count), \
- NULL, &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
+ 0, (count), \
+ NULL, &error ) )
#define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_realloc( memory, sizeof ( *(ptr) ), \
- (cursz), (newsz), \
- (ptr), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
+ (cursz), (newsz), \
+ (ptr), &error ) )
#define FT_MEM_QNEW_ARRAY( ptr, count ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
- 0, (count), \
- NULL, &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
+ 0, (count), \
+ NULL, &error ) )
#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
- FT_DEBUG_INNER( (ptr) = ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
- (cursz), (newsz), \
- (ptr), &error ) )
+ FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
+ (cursz), (newsz), \
+ (ptr), &error ) )
#define FT_ALLOC( ptr, size ) \