星期五, 二月 02, 2007

gcc的语法检查

在编译mod_lua 0.5的过程中,下面的代码出现警告
LuaState *L;
void** data = (void**) &L;
warning: dereferencing type-punned pointer will break strict-aliasing rules

-------------
gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)


somebody say that:

Yes, by implying -fstrict-aliasing, so using -fno-strict-aliasing is a
workaround. The problem is caused by the i386 PCPU_GET/PCPU_SET
implementation:

#define __PCPU_GET(name) ({ \
__pcpu_type(name) __result; \
\
[...]
} else if (sizeof(__result) == 4) { \
u_int __i; \
__asm __volatile("movl %%fs:%1,%0" \
: "=r" (__i) \
: "m" (*(u_int *)(__pcpu_offset(name)))); \
__result = *(__pcpu_type(name) *)&__i; \
[...]

In this case, the PCPU_GET is used to retrieve curthread, causing
sizeof(__result) to be 4, so the cast at the end of the code snippet
is from a u_int * to struct thread *, and __i is accessed through the
casted pointer, which violates the C99 aliasing rules.
An alternative is to type-pun via a union, which is also a bit ugly,
but explicitly allowed by C99. Patch attached (but only superficially
tested).

mod_lua 0.5终于发布了

在mod_lua 0.5上已经花费好大精力了,在经过一番修改与测试之后,在http://mod-lua.sourceforge.net上发布了这个版本,继续其它的工作!