Merge pull request #129 from vadz/warn-fix

Fix gcc strict aliasing warnings with function pointers too.
This commit is contained in:
VZ 2014-02-01 09:10:02 -08:00
commit 2c87cee65a
3 changed files with 20 additions and 8 deletions

View file

@ -947,11 +947,12 @@ int DohGetmark(DOH *ho) {
DOH *DohCall(DOH *func, DOH *args) { DOH *DohCall(DOH *func, DOH *args) {
DOH *result; DOH *result;
DOH *(*builtin) (DOH *); DohFuncPtr_t builtin;
*(void **)(&builtin) = GetVoid(func, "builtin"); builtin.p = GetVoid(func, "builtin");
if (!builtin)
if (!builtin.p)
return 0; return 0;
result = (*builtin) (args); result = (*builtin.func) (args);
return result; return result;
} }

View file

@ -336,6 +336,12 @@ extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile * input); extern DOHList *DohSplitLines(DOHFile * input);
extern DOH *DohNone; extern DOH *DohNone;
/* Helper union for converting between function and object pointers. */
typedef union DohFuncPtr {
void* p;
DOH *(*func)(DOH *);
} DohFuncPtr_t;
extern void DohMemoryDebug(void); extern void DohMemoryDebug(void);
#ifndef DOH_LONG_NAMES #ifndef DOH_LONG_NAMES

View file

@ -46,15 +46,19 @@ static int Writen(DOH *out, void *buffer, int len) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) { void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) {
DohFuncPtr_t fp;
if (!encodings) if (!encodings)
encodings = NewHash(); encodings = NewHash();
Setattr(encodings, (void *) name, NewVoid(*(void **)&fn, 0));
fp.func = fn;
Setattr(encodings, (void *) name, NewVoid(fp.p, 0));
} }
/* internal function for processing an encoding */ /* internal function for processing an encoding */
static DOH *encode(char *name, DOH *s) { static DOH *encode(char *name, DOH *s) {
DOH *handle, *ns; DOH *handle, *ns;
DOH *(*fn) (DOH *); DohFuncPtr_t fp;
long pos; long pos;
char *cfmt = strchr(name, ':'); char *cfmt = strchr(name, ':');
DOH *tmp = 0; DOH *tmp = 0;
@ -72,8 +76,9 @@ static DOH *encode(char *name, DOH *s) {
s = tmp; s = tmp;
pos = Tell(s); pos = Tell(s);
Seek(s, 0, SEEK_SET); Seek(s, 0, SEEK_SET);
*(void **)(&fn) = Data(handle);
ns = (*fn) (s); fp.p = Data(handle);
ns = (*fp.func) (s);
assert(pos != -1); assert(pos != -1);
(void)Seek(s, pos, SEEK_SET); (void)Seek(s, pos, SEEK_SET);
if (tmp) if (tmp)