lua-users home
lua-l archive

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


On 31 August 2011 17:06, Robert Raschke <rtrlists@googlemail.com> wrote:
> Umm, this thread is starting to look like a bit of trolling now.
>
> It's a stack, treat it like one.
>
> Robby
>
>

Thanks for the comment which actually looks like you are trolling.

> It's a stack, treat it like one.
The "stack" is really not a stack as per normal convention[1] yet I
would say a list, but this is besides the point.

Both myself and Oliver provide wrapper/binding libraries for Lua and
C++ and we are trying to detect invalid (non acceptable) use of Lua
indicies. The first post in this thread queried acceptable indicies[1]
and the manual makes many many references to this mythical stack space
for which there is no method of determining it using the public API.
How can every function which accepts an index have a precondition that
can not be checked?



> The stack is always going to be at least 20 entries.
You are missing the point. If you used the function you gave then it
would give a false positive for an invalid index which is acceptable,
when we are trying to detect non acceptable indicies.

>This time, going by what Lua 5.1.4 *does* ... can we expect this behavior, or is this a detail of the
>implementaion?

You would do well by looking at the source and the docs. The docs
state that it is a precondition the index is an acceptable index and
the source backs this up unless I have misunderstood the details of
the stack, I have previously said that it would be undefined behaviour
[3] [4] and therefore could result in anything[5].

So in short there is no method as Oliver has been stating to ensure
that your program is not ill defined and be able detect an non
acceptable index without recompiling Lua and using in debug mode or
recompiling and changing what lua_assert does. Some may say this is
the duty of the user to determine the stack has the correct number of
entries and I would not argue with that, just that it would be nice to
know the value of the stacksize to catch such errors and report them
or even drop them on the floor depending on the situation.


[1] In computer science, a stack is a last in, first out (LIFO)
abstract data type and data structure. A stack can have any abstract
data type as an element, but is characterized by only three
fundamental operations: push, pop and stack top.
[2]  Would it be correct to say, "all functions which take a stack
index require that it is inside the available stack space"
[3] For example using index 30
when stackspace is 20 and extraspace is 5* then the following is UB in
C.
if (o >= L->top)
[4]
C99 6.8.5.5
When two pointers are compared, the result depends on the relative
locations in the address space of the objects pointed to. If two
pointers to object or incomplete types both point to the same object,
or both point one past the last element of the same array object, they
compare equal. If the objects pointed to are members of the same
aggregate object, pointers to structure members declared later compare
greater than pointers to members declared earlier in the structure,
and pointers to array elements with larger subscript values compare
greater than pointers to elements of the same array with lower
subscript values. All pointers to members of the same union object
compare equal. If the expression P points to an element of an array
object and the expression Q points to the last element of the same
array object, the pointer expression Q+1 compares greater than P. In
all other cases, the behavior is undefined.
[5] this could maybe could be fixed by taking the pointer values and
comparing via a size_t, intptr_t et al