Commit c58ce3beee198cff82269a482cd3f6d4c7d43511

Werner Lemberg 2013-03-13T11:06:39

Introduce `FT_THROW' macro. The idea is to replace code like return FT_Err_Foo_Bar; or return CFF_Err_Foo_Bar; with return FT_THROW( Foo_Bar ); The FT_THROW macro has two functions: . It hides the module specific prefix. . In debug mode, it calls the empty function `FT_Throw' which can be thus used to set a breakpoint. * include/freetype/internal/ftdebug.h (FT_THROW): New macro. (FT_Throw): New prototype. * src/base/ftdebug.c (FT_Throw): New function.

diff --git a/ChangeLog b/ChangeLog
index 3a1f98b..d7dd3a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2013-03-13  Werner Lemberg  <wl@gnu.org>
+
+	Introduce `FT_THROW' macro.
+
+	The idea is to replace code like
+
+	  return FT_Err_Foo_Bar;
+
+	or
+
+	  return CFF_Err_Foo_Bar;
+
+	with
+
+	  return FT_THROW( Foo_Bar );
+
+	The FT_THROW macro has two functions:
+
+	  . It hides the module specific prefix.
+
+	  . In debug mode, it calls the empty function `FT_Throw' which can
+	    be thus used to set a breakpoint.
+
+	* include/freetype/internal/ftdebug.h (FT_THROW): New macro.
+	(FT_Throw): New prototype.
+	* src/base/ftdebug.c (FT_Throw): New function.
+
 2013-03-12  Werner Lemberg  <wl@gnu.org>
 
 	Remove `FT_KEEP_ERR_PREFIX'.
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 7baae35..095da1d 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Debugging and logging component (specification).                     */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2004, 2006, 2007, 2008, 2009 by             */
+/*  Copyright 1996-2002, 2004, 2006-2009, 2013 by                          */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -185,7 +185,8 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
-  /* Define the FT_ASSERT macro.                                           */
+  /* Define the FT_ASSERT and FT_THROW macros.  The call to `FT_Throw'     */
+  /* makes it possible to easily set a breakpoint at this function.        */
   /*                                                                       */
   /*************************************************************************/
 
@@ -199,10 +200,18 @@ FT_BEGIN_HEADER
                         __LINE__, __FILE__ );                       \
           } while ( 0 )
 
+#define FT_THROW( e )                                   \
+          ( FT_Throw( FT_ERR_CAT( FT_ERR_PREFIX, e ),   \
+                      __LINE__,                         \
+                      __FILE__ )                      | \
+            FT_ERR_CAT( FT_ERR_PREFIX, e )            )
+
 #else /* !FT_DEBUG_LEVEL_ERROR */
 
 #define FT_ASSERT( condition )  do { } while ( 0 )
 
+#define FT_THROW( e )  FT_ERR_CAT( FT_ERR_PREFIX, e )
+
 #endif /* !FT_DEBUG_LEVEL_ERROR */
 
 
@@ -226,6 +235,12 @@ FT_BEGIN_HEADER
   FT_Panic( const char*  fmt,
             ... );
 
+  /* report file name and line number of an error */
+  FT_BASE( int )
+  FT_Throw( FT_Error     error,
+            int          line,
+            const char*  file );
+
 #endif /* FT_DEBUG_LEVEL_ERROR */
 
 
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 2adbeab..cada8d0 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -77,6 +77,21 @@
     exit( EXIT_FAILURE );
   }
 
+
+  /* documentation is in ftdebug.h */
+
+  FT_BASE_DEF( int )
+  FT_Throw( FT_Error     error,
+            int          line,
+            const char*  file )
+  {
+    FT_UNUSED( error );
+    FT_UNUSED( line );
+    FT_UNUSED( file );
+
+    return 0;
+  }
+
 #endif /* FT_DEBUG_LEVEL_ERROR */