bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 13 forks source link

DebugLog() not ignored in release builds #584

Open GWRon opened 2 years ago

GWRon commented 2 years ago

When compiling code containing this here:

SuperStrict
Framework Brl.StandardIO

Type TTest
    Field name:String
End Type

Local t:TTest = Null
DebugLog("name: "  + t.name)  '<-- t.*** is a null access

You will catch it properly in debug builds - in release builds it will simply segfault

Function DebugLog( message$ )
--
Description | Write a string to debug log
Information | If there is no debugger present, this command is ignored.

is a bit ... unclear here. it states "is ignored" which is ... kinda correct as in release builds the debuglog function just becomes an empty stub. Yet the passed parameter is evaluated before -- so not ignored.

I am aware that one could also write

Local t:TTest = Null
Local s:String = "name: "  + t.name
DebugLog(s)

but this is not the same then. I assumed using debuglog is similar to

?debug
print("name: " + t.name)
?

yet it is not similar - but you should write it that way:

?debug
debuglog("name: " + t.name)
?

So ... I wondered if it had side-effects if we simply do not "emit" converted "debuglog"-portions in release builds ?

GWRon commented 1 year ago

Anyone having thoughts on this? Thought it would be a simple change to not emit "debuglog" in non debug builds yet it is defined as a regular function in blitz.mod/blitz.bmx and not an inbuilt function the bcc could "adjust" during compilation. So currently the parameter passed to debuglog() is evaluated.

Kerntrick commented 1 year ago
SuperStrict
Framework Brl.StandardIO

?Not debug
'! #define brl_blitz_DebugLog(x)
?

Type TTest
    Field name:String
End Type

Local t:TTest = Null
DebugLog("name: "  + t.name)

Fixed :-)