lua-users home
lua-l archive

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


Em qua, 6 de nov de 2019 16:56, Roberto Ierusalimschy <roberto@inf.puc-rio.br> escreveu:
According to the manual, Viacheslav is right. The "law" says that you
should not use a string pointer after you popped it from the stack.

The rationale for this is that an hypothetical garbage collector
could move strings around while collecting garbage [1]. Lua never
used a moving (or copying) collector, so everthing always worked
"as expected". Theoretically, that could change in the future.

There are some problems for a copying collector in Lua:

- Strings in a stack cannot be moved. (More specifically, strings
in stack regions corresponding to C calls cannot be moved.)

- Userdata already assumes fixed pointers to their blocks of memory.

- A copying collector works on top of raw memory, while Lua does
GC on top of an allocation function.

For all these reasons, it seems very unlikely that Lua will ever
change to a copying collector. Maybe it is time to change the manual
and make official this behavior?

+1

In fact, all 'implementation-dependent', as well as 'undefined', behaviors could be rethought, aiming a 'well-defined' language.