Re: Ball of string -> g_return_* macros in static functions - lots of them :(



2005/10/17, John Rice <John Rice sun com>:
> So with this situation we will always pay the performance penalty AND we
> don't have the benefit of assert's blowing up in the internal library
> static functions to warn us during development that something is
> screwed. The g_return_* macros will allow us to fail gracefully,
> essentially masking many pathological conditions that we really ought to
> catch.

For developement, you can turn those warnings into fatal (aborting the program).

For performance, you can do -DG_DISABLE_CHECKS because:

http://cvs.gnome.org/viewcvs/glib/glib/gmessages.h?view=markup
---8<-----

#ifdef G_DISABLE_CHECKS

#define g_return_if_fail(expr)                  G_STMT_START{ (void)0;
}G_STMT_END
#define g_return_val_if_fail(expr,val)          G_STMT_START{ (void)0;
}G_STMT_END
#define g_return_if_reached()                   G_STMT_START{ return;
}G_STMT_END
#define g_return_val_if_reached(val)            G_STMT_START{ return
(val); }G_STMT_END

#else /* !G_DISABLE_CHECKS */

---8>----

You shouldn't use g_return_* as a validator of data anyway, they are
more debugging tools then a failsafe mechanism. If you pass crappy
data to functions, there is only so much the functions can do about
it...

If there is something special in using these macros in static
functions, please correct me, but as such I don't see benefits from
turning them into assertions.

--
Kalle Vahlman, zuh iki fi
Powered by http://movial.fi



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