lua-users home
lua-l archive

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


On 15.04.2010 01:35, Tom N Harris wrote:
> Anyone using struct[1] or pack[2] modules should be aware that neither
> of them check for stack overflow before unpacking. This is a problem if
> you will be unpacking more than 20 values (or whatever LUA_MINSTACK is)
> or especially if the unpack string can come from someplace else.
> 
>     s = string.rep('b',10240)
>     unpack(s,s)
>     -- core dumped
> 
> The obvious fix is to pre-scan the format string and call lua_checkstack
> appropriately. Of course I've done this in the struct module I'm using
> for Larc[3].
> 
> And as I write this, I'm getting an idea for a different way to access
> packed data using tables. You compile a description of the data, which
> looks something like a C struct definition but with slightly more logic
> (a Pascal string could be "uint8_t len; char[len] name;") When attached
> to a string it can act like a table to unpack fields individually. But
> at the moment I don't want to be distracted from Larc. Maybe some other
> time or if anyone else wants to use the idea.

Another idea would be to use ltn12 sinks/sources, so you could read
"infinite" streams of data without memory problems:

http://lua-users.org/wiki/FiltersSourcesAndSinks

But this, of course, would require serious applications' modification.

Regards,
miko