[vlc-devel] [PATCH] lua: work around 32-bit integers limitation in vlc.var

Filip Roséen filip at atch.se
Mon Nov 28 07:00:41 CET 2016



On 2016-11-28 06:32, Filip Roséen wrote:

> Using `sizeof` is not really what you want, you should compare the
> *max*/*min* value of the two types in order to properly check if the
> value will fit.
> 
> It is far too early in the morning, and I have as usual not slept for
> what seems like days and days.. but the below should reflect what you
> want.
> 
>     #if LUA_MININTEGER > INT64_MIN || LUA_MAXINTEGER < INT64_MAX
>         if( val.i_int < LUA_MININTEGER || val.i_int > LUA_MAXINTEGER )
>             lua_pushnumber( L, (lua_Number)val.i_int );
>         else
>     #else
>         lua_pushinteger( L, val.i_int );
>     #endif

Erhm, the usage of `#else` and `#endif` is of course wrong; the below
is more like it:

    #if LUA_MININTEGER > INT64_MIN || LUA_MAXINTEGER < INT64_MAX
        if( val.i_int < LUA_MININTEGER || val.i_int > LUA_MAXINTEGER )
            lua_pushnumber( L, (lua_Number)val.i_int );
        else
    #endif
        lua_pushinteger( L, val.i_int );

I guess I just proved my own point related to me needing some sleep,
and with that.. `/me goes to bed`.

> Given that we, *afaik*, do not have a `macro` related to the *max* and
> *min* of `vlc_value_t::i_int`, the above uses `INT64_MAX` and
> `INT64_MIN` (which is the valid range for the *data-member* in
> question) directly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20161128/e0258e5f/attachment.html>


More information about the vlc-devel mailing list