Porting, of course the first thing to do is to stub out the obviously
system-specific and take care of the little utility functions until it
compiles: strcat, malloc, that sort of thing. This stuff is, in theory,
handled by the provided Unix compatibility headers, so I went and had a
look.

One quick browse through those headers sent me running screaming. I
found two major bugs just by inspection, which doesn't make me feel
very good about the usability of the rest of the directory. I'm
writing my own substitutions instead, but geez, this is important if
you want to attract developers!

First: In core/system/unix_string.h, the memcpy macro, defined as:
  #define memcpy(x,y,z) (MemMove(x,(void *)y,z) ? x : x)
Evaluates its first argument three times! (In fact, this function
cannot be implemented as a macro; the correct solution is to provide
an inline function.)

Second: the provided implementation of va_arg in
core/system/unix_stdarg.h is outright wrong. The implementation
provided is:
  #define va_arg(ap, type)    (*(((type *) (ap += sizeof(type))) - 1))
It should be plainly obvious that this will always crash if one does
va_arg(L,char); va_arg(L,short); va_arg(L,char); va_arg(L,short);,
since that guarantees an odd-aligned read, which is a fatal error on
68k. The correct implementation for 68k (grabbed from TIGCC and
probably not licensed to copy/paste into the SDK) is:
  #define va_arg(ap,type) \
    (*(type*)((((char*)(ap))+=((sizeof(type)+1)&~1))-(((sizeof(type)+1)&~1))))
That's certainly complicated, but it is indeed necessary to handle
alignment properly while avoiding multiple evaluation.

So, uh, who's responsible for those headers? Does anyone actually use
them?


-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to