[HarfBuzz] Questionable use of DEBUG

John Emmas johne53 at tiscali.co.uk
Mon Apr 29 23:31:38 PDT 2013


On 29/04/2013 10:15, John Emmas wrote:
>
> On 27/04/2013 21:37, Behdad Esfahbod wrote:
>>
>> The debug is fine.  The if gets optimized out by the compiler. That's 
>> by design.
>>
>
> Hi Behdad.  Can I ask how confident you are about this (for example, 
> is there something in the Harfbuzz code to guarantee that there won't 
> be a DEBUG macro when we're building our Release code?)
>
>

FWIW I took a more detailed look into this and I now have a better 
understanding of what you meant by "optimized out".  AFAICT any Harfbuzz 
statements that look something like this:-

         if (DEBUG (BUFFER))

will effectively evaluate to this:-

         if (0)

so yes, the compiler will (hopefully) optimize them away when building 
optimized code - but actually, that's not what I was worried about.  I 
was worrying about whether your custom DEBUG macro could ever get 
exposed to the outside world.  Let's say that one of the Harfbuzz public 
header files could eventually include that DEBUG macro.  If some 
unsuspecting programmer #included the public header, he could 
unwittingly have DEBUG defined without realizing it.  When interacting 
with other libraries, this could lead to some very subtle bugs which 
could be extremely difficult to track down.

The good news though is that after taking a more detailed look at 
Harfbuzz, I can't find any path where that could happen so (for now at 
least) the outside world is safe and I feel a lot more reassured!  ;-)

I just wanted to record it here, in case I need to remind myself in the 
future!

But if I'd written that macro I think I'd have been tempted to play safe 
and call it something else....  ;-)

John



More information about the HarfBuzz mailing list