* include/freetype/internal/ftmemory.h: allow compilation with C++ compilers
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
diff --git a/ChangeLog b/ChangeLog
index 018d619..5f9aec6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-03 David Turner <david@freetype.org>
+
+ * include/freetype/internal/ftmemory.h: allow compilation with
+ C++ compilers
+
2006-05-03 Werner Lemberg <wl@gnu.org>
* include/freetype/config/ftoption.h (FT_STRICT_ALIASING): Removed.
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index de8278e..d7f4ded 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 ) \