freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] wl/cplusplus-casts 3f7c17f: Provide C++ versions for public


From: Werner Lemberg
Subject: [freetype2] wl/cplusplus-casts 3f7c17f: Provide C++ versions for public macros with casts.
Date: Sat, 13 Nov 2021 03:19:32 -0500 (EST)

branch: wl/cplusplus-casts
commit 3f7c17f22d790a1a540fe03c12c597685d675da5
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    Provide C++ versions for public macros with casts.
    
    Many FreeType clients use C++.  However `g++ -Wold-style-cast` warns for
    macros with C-style casts even for system header files; this also affects
    directories included with `-isystem`.
    
    * include/freetype/freetype.h (FT_ENC_TAG, FT_LOAD_TARGET_,
    FT_LOAD_TARGET_MODE): Provide C++ version.
    * include/freetype/ftimage.h (FT_IMAGE_TAG): Ditto.
    * include/freetype/ftmodapi.h (FT_FACE_DRIVER_NAME): Ditto.
    * include/freetype/fttypes.h (FT_MAKE_TAG, FT_BOOL): Ditto.
---
 include/freetype/freetype.h | 24 +++++++++++++++++++++++-
 include/freetype/ftimage.h  | 13 +++++++++++++
 include/freetype/ftmodapi.h | 13 ++++++++++++-
 include/freetype/fttypes.h  | 19 ++++++++++++++++++-
 4 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index b457183..163f7d3 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -616,12 +616,25 @@ FT_BEGIN_HEADER
    */
 
 #ifndef FT_ENC_TAG
+
+#ifndef __cplusplus
+
 #define FT_ENC_TAG( value, a, b, c, d )         \
           value = ( ( (FT_UInt32)(a) << 24 ) |  \
                     ( (FT_UInt32)(b) << 16 ) |  \
                     ( (FT_UInt32)(c) <<  8 ) |  \
                       (FT_UInt32)(d)         )
 
+#else
+
+#define FT_ENC_TAG( value, a, b, c, d )                    \
+          value = ( ( static_cast<FT_UInt32>(a) << 24 ) |  \
+                    ( static_cast<FT_UInt32>(b) << 16 ) |  \
+                    ( static_cast<FT_UInt32>(c) <<  8 ) |  \
+                      static_cast<FT_UInt32>(d)         )
+
+#endif
+
 #endif /* FT_ENC_TAG */
 
 
@@ -3181,7 +3194,11 @@ FT_BEGIN_HEADER
    *   necessary to empty the cache after a mode switch to avoid false hits.
    *
    */
+#ifndef __cplusplus
 #define FT_LOAD_TARGET_( x )   ( (FT_Int32)( (x) & 15 ) << 16 )
+#else
+#define FT_LOAD_TARGET_( x )   ( static_cast<FT_Int32>( (x) & 15 ) << 16 )
+#endif
 
 #define FT_LOAD_TARGET_NORMAL  FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL )
 #define FT_LOAD_TARGET_LIGHT   FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT  )
@@ -3200,7 +3217,12 @@ FT_BEGIN_HEADER
    *   @FT_LOAD_TARGET_XXX value.
    *
    */
-#define FT_LOAD_TARGET_MODE( x )  ( (FT_Render_Mode)( ( (x) >> 16 ) & 15 ) )
+#ifndef __cplusplus
+#define FT_LOAD_TARGET_MODE( x )  (FT_Render_Mode)( ( (x) >> 16 ) & 15 )
+#else
+#define FT_LOAD_TARGET_MODE( x ) \
+          static_cast<FT_Render_Mode>( ( (x) >> 16 ) & 15 )
+#endif
 
 
   /**************************************************************************
diff --git a/include/freetype/ftimage.h b/include/freetype/ftimage.h
index 66a8b89..9e2c689 100644
--- a/include/freetype/ftimage.h
+++ b/include/freetype/ftimage.h
@@ -700,11 +700,24 @@ FT_BEGIN_HEADER
    *   to get a simple enumeration without assigning special numbers.
    */
 #ifndef FT_IMAGE_TAG
+
+#ifndef __cplusplus
+
 #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 )  \
           value = ( ( (unsigned long)_x1 << 24 ) | \
                     ( (unsigned long)_x2 << 16 ) | \
                     ( (unsigned long)_x3 << 8  ) | \
                       (unsigned long)_x4         )
+#else
+
+#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 )                 \
+          value = ( ( static_cast<unsigned long>( _x1 ) << 24 ) | \
+                    ( static_cast<unsigned long>( _x2 ) << 16 ) | \
+                    ( static_cast<unsigned long>( _x3 ) << 8  ) | \
+                      static_cast<unsigned long>( _x4 )         )
+
+#endif
+
 #endif /* FT_IMAGE_TAG */
 
 
diff --git a/include/freetype/ftmodapi.h b/include/freetype/ftmodapi.h
index cb15423..c001c18 100644
--- a/include/freetype/ftmodapi.h
+++ b/include/freetype/ftmodapi.h
@@ -347,9 +347,20 @@ FT_BEGIN_HEADER
    *   2.11
    *
    */
-#define FT_FACE_DRIVER_NAME( face ) \
+
+#ifndef __cplusplus
+
+#define FT_FACE_DRIVER_NAME( face )                                     \
           ( ( *(FT_Module_Class**)( ( face )->driver ) )->module_name )
 
+#else
+
+#define FT_FACE_DRIVER_NAME( face )                    \
+          ( ( *reinterpret_cast<FT_Module_Class**>     \
+                 ( ( face )->driver ) )->module_name )
+
+#endif
+
 
   /**************************************************************************
    *
diff --git a/include/freetype/fttypes.h b/include/freetype/fttypes.h
index 37f7353..8165070 100644
--- a/include/freetype/fttypes.h
+++ b/include/freetype/fttypes.h
@@ -485,6 +485,8 @@ FT_BEGIN_HEADER
    *   The produced values **must** be 32-bit integers.  Don't redefine this
    *   macro.
    */
+#ifndef __cplusplus
+
 #define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
           (FT_Tag)                        \
           ( ( (FT_ULong)_x1 << 24 ) |     \
@@ -492,6 +494,17 @@ FT_BEGIN_HEADER
             ( (FT_ULong)_x3 <<  8 ) |     \
               (FT_ULong)_x4         )
 
+#else
+
+#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 )            \
+          static_cast<FT_Tag>                        \
+          ( ( static_cast<FT_ULong>( _x1 ) << 24 ) | \
+            ( static_cast<FT_ULong>( _x2 ) << 16 ) | \
+            ( static_cast<FT_ULong>( _x3 ) <<  8 ) | \
+              static_cast<FT_ULong>( _x4 )         )
+
+#endif
+
 
   /*************************************************************************/
   /*************************************************************************/
@@ -588,7 +601,11 @@ FT_BEGIN_HEADER
 
 
 #define FT_IS_EMPTY( list )  ( (list).head == 0 )
-#define FT_BOOL( x )  ( (FT_Bool)( (x) != 0 ) )
+#ifndef __cplusplus
+#define FT_BOOL( x )  (FT_Bool)( (x) != 0 )
+#else
+#define FT_BOOL( x )  static_cast<FT_Bool>( (x) != 0 )
+#endif
 
   /* concatenate C tokens */
 #define FT_ERR_XCAT( x, y )  x ## y



reply via email to

[Prev in Thread] Current Thread [Next in Thread]