Revert Linas' broken changes to qof.
Derek Atkins
warlord at MIT.EDU
Sun Apr 18 23:38:52 EDT 2004
linas at linas.org (Linas Vepstas) writes:
>> Even worse, you were illegally calling functions of one argument with
>> TWO arguments, and the compiler wasn't catching it due to the casting.
>> This is BAD, and can lead to LOTS of problems down the road.
>
> Its no worse than the function signature casting that is
> already being done. The second argument is not clobbered
> for the caller, because the callee linkage saves all clobbered
> registers, and the callee couldn't care less, because it
> saves and restores all registers that it clobbers. It's
> perfectly safe; I've read the assembly umpteen times over
> the years. Take a look at GTK signals, where this is done
> all over the place; the added extra argument is usually
> a gpointer to 'user-data'.
It's ok so long as the _actual_ caller and _actual_ callee have the
same number of arguments. What I'm doing NOW is perfectly safe in all
cases because the calling argument is always a pointer (just pointers
of different types), and the return value is just a register. Moreover,
the function is cast'ed to the proper return type before being called.
It's NOT SAFE to call otherwise, in particular when you call with more
(or less) arguments than the called function is expective.. It's
extremely compiler and ABI dependent. It may work in some cases, but
it's not portable nor guaranteed to work.
You are effectively running this code:
void* foo (void *) { ... }
typedef void* (*FooFcn)(void*, Foo*);
FooFcn fcn = (FooFcn)foo;
res = fcn(x, y);
Which is black voodoo and NOT guaranteed to work. On some platforms
foo() will see x, on some it will see y, and on some it may see total
garbage. It is NOT guaranteed to see X in all cases. Definitely not
when using different compilers on different calling conventions.
Sure, this may work with GCC on x86, but it's not guaranteed on other
systems with other compilers.
We're trying to write portable code, aren't we?
>> Uh, no, it wont. It broke in both src/engine (Transaction.h)
>> and gnome-utils (gnc-query-list.c).
>
> I uhh, guess I needed to check some other things in too ....
Uhh, yea! That would've been nice. In fact I wouldn't have even
noticed this if the code had actually compiled. At least until it
started failing in weird ways on strange platforms, but that would
probably not be reported for half a year when someone tries to port it
to s/390 or something.
> --linas
-derek
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-devel
mailing list