bmx-ng / brl.mod

BlitzMax Runtime Libraries, for BlitzMax NG.
12 stars 12 forks source link

[brl.reflection] 32 bit build issues with LONG-params #205

Open GWRon opened 3 years ago

GWRon commented 3 years ago

I received a bug report by a user ... somehow a lua script which invokes some BlitzMax-exposed method received wrong values.

I am not able to replicate it on my computers (linux, windows7, windows10, AMD and Intel cpus).

If building a 64bit binary for him, the problem is gone. It only happens for 32bit builds. That user had other special "results" when I used "long" in c code rather than "BBLONG" (fixed thanks to @HurryStarfish ).

The method is defined as Method GetDay:Int(useTime:Long = -1) - so the parameter is a LONG. I call the method via reflection. Before invoking the method I print out the "to pass" parameters. Inside the method I print out what is received - and what is returned at the end. After invokation is done I print out what was returned.

Lua -> BlitzMax works. So param is read as it should. The invoked method receives an incorrect value .. .and calculates with it. It returns a value (which it printed out). The value the invocation result contains is different to the printed out one.

I cannot write up a simple example but something like this can help:

    'attention: LUA uses a default param of "0"
    '-> so for this and other functions we have to use "<=0" instead of "<0"
    Method GetDay:Int(useTime:Double = -1) {_exposeToLua}
        print "useTime="+useTime
        Return useTime * 10
    End Method
GWRon commented 3 years ago

Replacing the parameter with other types makes it work (I had it on "double" before rewriting my stuff to use longs for times not doubles).

GWRon commented 2 years ago

As stated in #227 issues arise also for "doubles" - if you do debug builds instead of release builds.