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

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

Hi Pierre,

On 2016-11-28 05:22, Pierre wrote:

> > See next comment regarding preprocessor evaluation rather than runtime
> > checks.
> > The above, and what follows, makes more sense as a preprocessor
> > condition, given that `sizeof` will not change during runtime (and I
> > fear unwanted compiler diagnostics related to "always true" vs "always
> > false").
> It is not quite a runtime check: it is optimized away at compile time.

Yes, of course, but I was referring to the semantics of the check, not
that the branch condition would actually evaluated.

> I would still prefer to do it in preprocessor, yes; but I don't know how
> to. I don't know how to access sizeof(val.i_int) from the preprocessor,
> and I don't know how to test sizeof(lua_Integer). I suppose it would be
> possible to add autoconf macros testing lua types, but that seems very
> heavy to me. Better ideas are welcome.

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

        if( val.i_int < LUA_MININTEGER || val.i_int > LUA_MAXINTEGER )
            lua_pushnumber( L, (lua_Number)val.i_int );
        lua_pushinteger( L, val.i_int );

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.

> > `roundf` is in `<math.h>` starting with `C99`.
> Okay, yes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20161128/2ac00cc1/attachment.html>

More information about the vlc-devel mailing list