lua-users home
lua-l archive

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




2010/1/8 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
> * added a rule to Makefile to trigger rebuilds when the Makefile changes

Better use
       $(ALL_O): Makefile

> * added a fix in loadlib.c for pedantic ISO-C rules about pointer casts

But using an union also breaks pedantic ISO-C rules, right?
I think you must use memcpy if you go that way:
       void* p = dlsym(lib, sym);
       lua_CFunction f;
       if (p == NULL) lua_pushstring(L, dlerror());
       memcpy(f,p,sizeof(f));          /* let's hope they're the same size */
       return f;

I see that this is using dlsym which is a Posix function, effectively what this piece of code has done is go from well defined to undefined. Any conforming Posix implementation is required to make a function pointer the same size as a void*, after all dlysm returns a void pointer. To get round the pointer cast warning (which is defined) you have used a Union in not the way it is intended to be used or even defined to be used.

6.5.2.3.5
"One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members."