Merge pull request #129 from vadz/warn-fix
Fix gcc strict aliasing warnings with function pointers too.
This commit is contained in:
commit
2c87cee65a
3 changed files with 20 additions and 8 deletions
|
|
@ -947,11 +947,12 @@ int DohGetmark(DOH *ho) {
|
|||
|
||||
DOH *DohCall(DOH *func, DOH *args) {
|
||||
DOH *result;
|
||||
DOH *(*builtin) (DOH *);
|
||||
DohFuncPtr_t builtin;
|
||||
|
||||
*(void **)(&builtin) = GetVoid(func, "builtin");
|
||||
if (!builtin)
|
||||
builtin.p = GetVoid(func, "builtin");
|
||||
|
||||
if (!builtin.p)
|
||||
return 0;
|
||||
result = (*builtin) (args);
|
||||
result = (*builtin.func) (args);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,6 +336,12 @@ extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
|
|||
extern DOHList *DohSplitLines(DOHFile * input);
|
||||
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);
|
||||
|
||||
#ifndef DOH_LONG_NAMES
|
||||
|
|
|
|||
|
|
@ -46,15 +46,19 @@ static int Writen(DOH *out, void *buffer, int len) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) {
|
||||
DohFuncPtr_t fp;
|
||||
|
||||
if (!encodings)
|
||||
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 */
|
||||
static DOH *encode(char *name, DOH *s) {
|
||||
DOH *handle, *ns;
|
||||
DOH *(*fn) (DOH *);
|
||||
DohFuncPtr_t fp;
|
||||
long pos;
|
||||
char *cfmt = strchr(name, ':');
|
||||
DOH *tmp = 0;
|
||||
|
|
@ -72,8 +76,9 @@ static DOH *encode(char *name, DOH *s) {
|
|||
s = tmp;
|
||||
pos = Tell(s);
|
||||
Seek(s, 0, SEEK_SET);
|
||||
*(void **)(&fn) = Data(handle);
|
||||
ns = (*fn) (s);
|
||||
|
||||
fp.p = Data(handle);
|
||||
ns = (*fp.func) (s);
|
||||
assert(pos != -1);
|
||||
(void)Seek(s, pos, SEEK_SET);
|
||||
if (tmp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue