Logging.h
changeset 16 ce9c83f7ec14
parent 8 5588347dfcbd
child 19 5ade3e09a827
     1.1 --- a/Logging.h	Wed May 07 16:47:44 2008 -0700
     1.2 +++ b/Logging.h	Sun Jul 13 10:45:42 2008 -0700
     1.3 @@ -6,25 +6,32 @@
     1.4  //  Copyright 2008 Jens Alfke. All rights reserved.
     1.5  //
     1.6  
     1.7 -#import <Cocoa/Cocoa.h>
     1.8 +#import <Foundation/Foundation.h>
     1.9  
    1.10  
    1.11  NSString* LOC( NSString *key );     // Localized string lookup
    1.12  
    1.13  
    1.14 -#ifdef __cplusplus
    1.15 -    #define IN_SEGMENT(SEG)
    1.16 -#else
    1.17 +// To enable IN_SEGMENT (which breaks rarely-called logging code out of your main code segment,
    1.18 +// improving locality of reference) you must define MY_USE_NESTED_FNS in your prefix file or
    1.19 +// target settings, and add the GCC flag "-fnested-functions" to your target's C flags.
    1.20 +#if defined(MY_USE_NESTED_FNS) && ! defined(__cplusplus)
    1.21      #define IN_SEGMENT(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) void _outofband_(void);\
    1.22                              _outofband_();\
    1.23                              void _outofband_(void)
    1.24 +    #define IN_SEGMENT_NORETURN(SEG) auto __attribute__ ((section ("__TEXT, "#SEG))) __attribute__ ((noinline)) __attribute__((noreturn)) void _assertfailure_(void);\
    1.25 +                            _assertfailure_();\
    1.26 +                            void _assertfailure_(void)
    1.27 +#else
    1.28 +    #define IN_SEGMENT(SEG)
    1.29 +    #define IN_SEGMENT_NORETURN(SEG)
    1.30  #endif
    1.31  
    1.32  #define Log(FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
    1.33                              IN_SEGMENT(Logging){_Log(FMT,##ARGS);}\
    1.34                           } }while(0)
    1.35  #define LogTo(DOMAIN,FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
    1.36 -                                    IN_SEGMENT(Logging) {_LogTo(@""#DOMAIN,FMT,##ARGS);}\
    1.37 +                                    IN_SEGMENT(Logging) {if(_WillLogTo(@""#DOMAIN)) _LogTo(@""#DOMAIN,FMT,##ARGS);}\
    1.38                                    } }while(0)
    1.39  #define Warn Warn
    1.40