Commit 52339dc2742dfd2a1e91aeb1067506e4a7311d35

Werner Lemberg 2013-03-14T15:49:49

New error management macros. * include/freetype/fterrors.h (FT_ERR_XCAT, FT_ERR_CAT): Move to... * include/freetype/fttypes.h: ... this file. (FT_ERR, FT_ERR_EQ, FT_ERR_NEQ, FT_MODERR_EQ, FT_MODERR_NEQ): New macros. * include/freetype/freetype.h: Updated.

diff --git a/ChangeLog b/ChangeLog
index 7319357..a43f198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2013-03-14  Werner Lemberg  <wl@gnu.org>
 
+	New error management macros.
+
+	* include/freetype/fterrors.h (FT_ERR_XCAT, FT_ERR_CAT): Move to...
+	* include/freetype/fttypes.h: ... this file.
+	(FT_ERR, FT_ERR_EQ, FT_ERR_NEQ, FT_MODERR_EQ, FT_MODERR_NEQ): New
+	macros.
+
+	* include/freetype/freetype.h: Updated.
+
+2013-03-14  Werner Lemberg  <wl@gnu.org>
+
 	*/*: Use FT_Err_Ok only.
 
 	This is a purely mechanical conversion.
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index d35a3e4..39c3d0d 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType high-level API and common types (specification only).       */
 /*                                                                         */
-/*  Copyright 1996-2012 by                                                 */
+/*  Copyright 1996-2013 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -31,8 +31,8 @@
 
 #include <ft2build.h>
 #include FT_CONFIG_CONFIG_H
-#include FT_ERRORS_H
 #include FT_TYPES_H
+#include FT_ERRORS_H
 
 
 FT_BEGIN_HEADER
diff --git a/include/freetype/fterrors.h b/include/freetype/fterrors.h
index bf705da..0fa3e4d 100644
--- a/include/freetype/fterrors.h
+++ b/include/freetype/fterrors.h
@@ -28,9 +28,8 @@
   /*   The configuration macro FT_CONFIG_OPTION_USE_MODULE_ERRORS can be   */
   /*   defined in ftoption.h in order to make the higher byte indicate     */
   /*   the module where the error has happened (this is not compatible     */
-  /*   with standard builds of FreeType 2).  You can then use the macro    */
-  /*   FT_ERROR_BASE macro to extract the generic error code from an       */
-  /*   FT_Error value.                                                     */
+  /*   with standard builds of FreeType 2).  See the file `ftmoderr.h' for */
+  /*   more details.                                                       */
   /*                                                                       */
   /*                                                                       */
   /* II - Error Message strings                                            */
@@ -101,12 +100,6 @@
 
 #undef  FT_NEED_EXTERN_C
 
-#undef  FT_ERR_XCAT
-#undef  FT_ERR_CAT
-
-#define FT_ERR_XCAT( x, y )  x ## y
-#define FT_ERR_CAT( x, y )   FT_ERR_XCAT( x, y )
-
 
   /* FT_ERR_PREFIX is used as a prefix for error identifiers. */
   /* By default, we use `FT_Err_'.                            */
@@ -150,11 +143,11 @@
 
 
   /* this macro is used to define an error */
-#define FT_ERRORDEF_( e, v, s )   \
+#define FT_ERRORDEF_( e, v, s )                                             \
           FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v + FT_ERR_BASE, s )
 
   /* this is only used for <module>_Err_Ok, which must be 0! */
-#define FT_NOERRORDEF_( e, v, s ) \
+#define FT_NOERRORDEF_( e, v, s )                             \
           FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v, s )
 
 
diff --git a/include/freetype/ftmoderr.h b/include/freetype/ftmoderr.h
index 83beb0b..d5b9393 100644
--- a/include/freetype/ftmoderr.h
+++ b/include/freetype/ftmoderr.h
@@ -18,17 +18,57 @@
 
   /*************************************************************************/
   /*                                                                       */
-  /* This file is used to define the FreeType module error offsets.        */
+  /* This file is used to define the FreeType module error codes.          */
   /*                                                                       */
-  /* The lower byte gives the error code, the higher byte gives the        */
-  /* module.  The base module has error offset 0.  For example, the error  */
-  /* `FT_Err_Invalid_File_Format' has value 0x003, the error               */
-  /* `TT_Err_Invalid_File_Format' has value 0x1103, the error              */
-  /* `T1_Err_Invalid_File_Format' has value 0x1203, etc.                   */
+  /* If the macro FT_CONFIG_OPTION_USE_MODULE_ERRORS in `ftoption.h' is    */
+  /* set, the lower byte of an error value identifies the error code as    */
+  /* usual.  In addition, the higher byte identifies the module.  For      */
+  /* example, the error `FT_Err_Invalid_File_Format' has value 0x0003, the */
+  /* error `TT_Err_Invalid_File_Format' has value 0x1303, the error        */
+  /* `T1_Err_Invalid_File_Format' has value 0x1403, etc.                   */
+  /*                                                                       */
+  /* Note that `FT_Err_Ok', `TT_Err_Ok', etc. are always equal to zero,    */
+  /* including the high byte.                                              */
+  /*                                                                       */
+  /* If FT_CONFIG_OPTION_USE_MODULE_ERRORS isn't set, the higher byte of   */
+  /* an error value is set to zero.                                        */
+  /*                                                                       */
+  /* To hide the various `XXX_Err_' prefixes in the source code, FreeType  */
+  /* provides some macros in `fttypes.h'.                                  */
+  /*                                                                       */
+  /*   FT_ERR( err )                                                       */
+  /*     Add current error module prefix (as defined with the              */
+  /*     `FT_ERR_PREFIX' macro) to `err'.  For example, in the BDF module  */
+  /*     the line                                                          */
+  /*                                                                       */
+  /*       error = FT_ERR( Invalid_Outline );                              */
+  /*                                                                       */
+  /*     expands to                                                        */
+  /*                                                                       */
+  /*       error = BDF_Err_Invalid_Outline;                                */
+  /*                                                                       */
+  /*     For simplicity, you can always use `FT_Err_Ok' directly instead   */
+  /*     of `FT_ERR( Ok )'.                                                */
+  /*                                                                       */
+  /*   FT_ERR_EQ( errcode, err )                                           */
+  /*   FT_ERR_NEQ( errcode, err )                                          */
+  /*     Compare error code `errcode' with the error `err' for equality    */
+  /*     and inequality, respectively.  Example:                           */
+  /*                                                                       */
+  /*       if ( FT_ERR_EQ( error, Invalid_Outline ) )                      */
+  /*         ...                                                           */
+  /*                                                                       */
+  /*     Using this macro you don't have to think about error prefixes.    */
+  /*     Of course, if module errors are not active, the above example is  */
+  /*     the same as                                                       */
+  /*                                                                       */
+  /*       if ( error == FT_Err_Invalid_Outline )                          */
+  /*         ...                                                           */
+  /*                                                                       */
+  /*   FT_ERROR_BASE( errcode )                                            */
+  /*   FT_ERROR_MODULE( errcode )                                          */
+  /*     Get base error and module error code, respectively.               */
   /*                                                                       */
-  /* Undefine the macro FT_CONFIG_OPTION_USE_MODULE_ERRORS in ftoption.h   */
-  /* to make the higher byte always zero (disabling the module error       */
-  /* mechanism).                                                           */
   /*                                                                       */
   /* It can also be used to create a module error message table easily     */
   /* with something like                                                   */
@@ -48,9 +88,6 @@
   /*     #include FT_MODULE_ERRORS_H                                       */
   /*   }                                                                   */
   /*                                                                       */
-  /* To use such a table, all errors must be ANDed with 0xFF00 to remove   */
-  /* the error code.                                                       */
-  /*                                                                       */
   /*************************************************************************/
 
 
diff --git a/include/freetype/fttypes.h b/include/freetype/fttypes.h
index 1ad7fa1..027e59c 100644
--- a/include/freetype/fttypes.h
+++ b/include/freetype/fttypes.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType simple types definitions (specification only).              */
 /*                                                                         */
-/*  Copyright 1996-2002, 2004, 2006-2009, 2012 by                          */
+/*  Copyright 1996-2002, 2004, 2006-2009, 2012, 2013 by                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -571,14 +571,24 @@ FT_BEGIN_HEADER
   /* */
 
 #define FT_IS_EMPTY( list )  ( (list).head == 0 )
+#define FT_BOOL( x )  ( (FT_Bool)( x ) )
 
-  /* return base error code (without module-specific prefix) */
-#define FT_ERROR_BASE( x )    ( (x) & 0xFF )
+  /* concatenate C tokens */
+#define FT_ERR_XCAT( x, y )  x ## y
+#define FT_ERR_CAT( x, y )   FT_ERR_XCAT( x, y )
+
+  /* see `ftmoderr.h' for descriptions of the following macros */
+
+#define FT_ERR( e )  FT_ERR_CAT( FT_ERR_PREFIX, e )
 
-  /* return module error code */
+#define FT_ERROR_BASE( x )    ( (x) & 0xFF )
 #define FT_ERROR_MODULE( x )  ( (x) & 0xFF00U )
 
-#define FT_BOOL( x )  ( (FT_Bool)( x ) )
+#define FT_ERR_EQ( x, e )                                        \
+          ( FT_ERROR_BASE( x ) == FT_ERROR_BASE( FT_ERR( e ) ) )
+#define FT_ERR_NEQ( x, e )                                       \
+          ( FT_ERROR_BASE( x ) != FT_ERROR_BASE( FT_ERR( e ) ) )
+
 
 FT_END_HEADER