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.
This commit is contained in:
Werner Lemberg 2013-03-13 11:06:39 +01:00
parent dbc6e3f192
commit c58ce3beee
3 changed files with 59 additions and 2 deletions

View File

@ -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'.

View File

@ -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 */

View File

@ -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 */