Re: [AD] al_assert

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-03-02, Peter Hull <peterhull90@xxxxxxxxxx> wrote:
> On Tue, Feb 23, 2010 at 11:56 PM, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> >> Can we do this?
> >>
> >> #define AL_ASSERT assert
> >
> > IMO, yes.  (well, add some brackets around it)
> I tried to do this - #included <assert.h> in debug.h then #define
> AL_ASSERT assert and also the #define ASSERT which happens when
> Allegro itself is being built. However I got warnings that 'assert'
> was being used implicitly in (for example) aintern_vector.h line 28
> where the AL_INLINE macro was being used. So it seemed to have
> expanded the 'ASSERT' to 'assert' but not then expanded 'assert'
> (which is itself a macro)
> 
> As far as I understand the C preprocessor it should have carried on
> expanding, is there some macro magic I'm missing?

This worked for me.  You can finish it if you like.

Peter


diff --git a/include/allegro5/debug.h b/include/allegro5/debug.h
index 6def489..c1dc989 100644
--- a/include/allegro5/debug.h
+++ b/include/allegro5/debug.h
@@ -19,6 +19,7 @@
 #ifndef ALLEGRO_DEBUG_H
 #define ALLEGRO_DEBUG_H
 
+#include <assert.h>
 #include "allegro5/base.h"
 
 #ifdef __cplusplus
@@ -41,13 +42,8 @@ AL_FUNC(void, al_register_trace_handler, (AL_METHOD(int, handler, (const char *m
    #define ALLEGRO_TRACE_CHANNEL_LEVEL(channel, level)                        \
       !_al_trace_prefix(channel, level, __FILE__, __LINE__, __func__)         \
       ? (void)0 : al_trace
-   #define ALLEGRO_ASSERT(condition) do {                                     \
-                                    if (!(condition))                         \
-                                       al_assert(__FILE__, __LINE__);         \
-                                 } while (0)
    #define TRACE                 al_trace
 #else
-   #define ALLEGRO_ASSERT(condition)
    #define TRACE                                    1 ? (void) 0 : al_trace
    #define ALLEGRO_TRACE_CHANNEL_LEVEL(channel, x)  1 ? (void) 0 : al_trace
    #define ALLEGRO_DEBUG_CHANNEL(x)
@@ -59,6 +55,8 @@ AL_FUNC(void, al_register_trace_handler, (AL_METHOD(int, handler, (const char *m
 #define ALLEGRO_WARN             ALLEGRO_TRACE_LEVEL(2)
 #define ALLEGRO_ERROR            ALLEGRO_TRACE_LEVEL(3)
 
+#define ALLEGRO_ASSERT(condition) assert(condition)
+
 /* Compile time assertions. */
 #define ALLEGRO_ASSERT_CONCAT_(a, b)   a##b
 #define ALLEGRO_ASSERT_CONCAT(a, b)    ALLEGRO_ASSERT_CONCAT_(a, b)




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/