[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Issues with check_exp implementation
- From: Paige DePol <lual@...>
- Date: Tue, 12 Nov 2013 15:10:34 -0600
I have been hacking away at Lua for the past few weeks and have enabled asserts with the following code at the top of luaconf.h:
#include <assert.h>
#define lua_assert(x) assert(x)
#define LUA_USE_APICHECK
This enables all lua_assert() commands and also extra API asserts so I can double-check I don't break anything, which is very useful to have if you are tinkering with Lua internals.
~pmd~
On Nov 12, 2013, at 2:20 PM, JAVIER SETOAIN RODRIGO <jsetoain@pdi.ucm.es> wrote:
> Hello,
>
> I'm experiencing some trouble with the current check_exp implementation. When Lua asserts are enabled it's defined as follows:
>
> llimits.h:
>
> #define check_exp(c,e) (lua_assert(c), (e))
>
> Then you use it in the this definition:
>
> lobject.h
>
> #define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
>
> Which in turn is used this way:
>
> lapi.c@75:
>
> CClosure *func = clCvalue(ci->func);
>
> In the end, that line (and some others in that file) is replaced by something like this:
>
> CClosure *func = (lua_assert(ttisCclosure(o)), &val_(ci->func).gc->cl.c)
>
> The idea is that you force an assertion but only make an assignment of the right side of the parenthesis expression. The problem is "lua_assert", AFAIK, it's supposed to be replaced by an OS dependent version (Lua defines it void), which in many cases is a macro that looks like this:
>
> #define OS_ASSERT do { /*STUFF*/ } while(0)
>
> This way, when the OS specific assert is put in there you're left with something like this:
>
> CClosure *func = (do { /*STUFF*/ } while(0), &val_(ci->func).gc->cl.c)
>
> And that's not valid C. The left side must be an expression but "do {}while()" is an statement, it rises an error and the code fails to compile.
>
> I guess this should be managed another way?
>
> Regards,
> Javier
>