lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!
It's Wednesday again. 
It's time for nitpicking  :-)
 
1)  Funny name
 
The name of the symbol MYINT in "lundump.h" looks strange.
   #define MYINT(s)    (s[0]-'0')
Probably, something like DIGIT2INT would be a more appropriate name?
 
 
 
2)  A small step towards cross-platform compatibility of Lua bytecode
 
It seems that Lua 5.4 (Lua@Github Jan 30 2019) bytecode
doesn't depend on platform word size and pointer size anymore
due to another implementation of LoadStringN() and LoadInt().
So, why bytecode header contains sizeof(int) and sizeof(size_t) ?
Why Lua refuses to load bytecode if these values don't correspond
to the current platform?
 
Yes, there might be a hypothetical risk of loading, for example,
very long function prototype (100K instructions)
on a platform having 16-bit C int.
IMO, the preferred workaround would be to remove sizeof(int) and sizeof(size_t)
from bytecode header and insert additional check inside LoadSize():
before calculating (x<<7), make sure x is not greater than (MAX_INT>>7).
This way Lua bytecodes for Android, x86 and x64 platforms would be identical.
 
But I don't know why do we need cross-platform compatibility of Lua bytecode? :-)
 
 
 
3)  Mixed-endianness
 
"Mixed-endian" means that endianness is neither little-endian nor big-endian.
According to Wikipedia, such CPUs do exist.
I'm trying to determine whether Lua 5.3 support mixed-endian platforms or not?
 
My first guess was "yes", because of bytecode header layout:
Lua 5.2 has "LE/BE" boolean field in bytecode file header.
Lua 5.3 doesn't have this boolean field. Instead, two new fields were added,
these fields contain dumped numeric constants (0x5678 and 370.5).
This might mean that mixed-endian platforms are supported since Lua 5.3
(otherwise why boolean flag "LE/BE" was replaced with dumped integer value?).
 
My second guess was "no", because of string.pack() and string.unpack()
rely on assumption that native endianness is either LE or BE.
I don't have a mixed-endian device to test, but I guess that these functions
would work incorrectly on mixed-endian platforms.
 
Lua is claimed to be extremely portable, hence the questions:
  Does Lua support mixed-endian platforms?
  Should Lua support them?