Fix type-punning issues with C++. * include/freetype/internal/ftmemory.h (FT_ASSIGNP) [__cplusplus]: Emulate a `typeof' operator with an inline template which uses `static_cast'.
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
diff --git a/ChangeLog b/ChangeLog
index 49c22c9..c3da8c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,17 @@
+2010-07-12 malc <av1474@comtv.ru>
+
+ Fix type-punning issues with C++.
+
+ * include/freetype/internal/ftmemory.h (FT_ASSIGNP) [__cplusplus]:
+ Emulate a `typeof' operator with an inline template which uses
+ `static_cast'.
+
2010-07-11 Werner Lemberg <wl@gnu.org>
Fix C++ compilation issue.
* src/tools/apinames.c (names_dump) <OUTPUT_WATCOM_LBC>: Fix
- typo of `dot' variable.
+ type of `dot' variable.
2010-07-10 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index 2010ca9..026aa63 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -4,7 +4,7 @@
/* */
/* The FreeType memory management macros (specification). */
/* */
-/* Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007 by */
+/* Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -58,15 +58,27 @@ FT_BEGIN_HEADER
/*
- * C++ refuses to handle statements like p = (void*)anything; where `p'
- * is a typed pointer. Since we don't have a `typeof' operator in
- * standard C++, we have to use ugly casts.
+ * C++ refuses to handle statements like p = (void*)anything, with `p' a
+ * typed pointer. Since we don't have a `typeof' operator in standard
+ * C++, we have to use a template to emulate it.
*/
#ifdef __cplusplus
-#define FT_ASSIGNP( p, val ) *((void**)&(p)) = (val)
+
+ extern "C++"
+ template <typename T> inline T*
+ cplusplus_typeof( T*,
+ void *v )
+ {
+ return static_cast <T*> ( v );
+ }
+
+#define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
+
#else
+
#define FT_ASSIGNP( p, val ) (p) = (val)
+
#endif