[fpc-pascal] Mozilla XPCOM
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon Jun 7 10:34:26 CEST 2010
On 06 Jun 2010, at 19:28, José Mejuto wrote:
> I had found the problem, after a lot of debuging and trying to
> understand the underlayed COM interface the bug is in the mozilla
> XPCOM or in the fpc undertanding of COM interfaces in Linux. Aside the
> fact that under safecall in linux fpc does not call
> "fpc_safecallcheck" which I think it should be done to test the EAX
> register for errors,
safecall is not supported (= ignored) on non-Windows platforms,
because it is completely Windows-specific. Afaik, GCC does not support
any safecall calling convention on Linux either.
> fpc uses the same exact code under Windows and
> Linux but mozilla's XPCOM and I think that finally GCC uses a hybird
> calling convention, it is the same as in Linux but the stack must be
> cleaned by the caller, not the callee.
That's actually the standard C calling convention, not a hybrid
calling convention (= cdecl, as you mention below).
> So the same code to work in
> Linux (XPCOM) and in Windows:
>
> asm
> mov eax, [TheCOMInterface];
> mov eax,[eax]
> push Intf;
> push IID;
> push ContractID;
> push TheCOMInterface;
> Call [eax]+16;
> {$IFDEF LINUX}
> add esp,16;
> {$ENDIF}
> call fpc_safecallcheck;
> end;
Are you certain when using XPCOM with GCC, it automatically transforms
every function so that
a) the result is passed as a hidden parameter by reference
b) the actual function results becomes an error code
c) a check is inserted after every call that checks this error code
?
> cdecl that fails (Linux):
> -----------------
>
> procedure GetServiceByContractID(const aContractID: PAnsiChar;
> const aIID: TGUID;
> out _result); cdecl;
>
> cdecl that works as expected (Linux):
> -------------------------------------
>
> procedure GetServiceByContractID(const aContractID: PAnsiChar;
> const aIID: PGUID;
> out _result); cdecl;
>
> Changing the TGUID to PGUID and in the call changing the IID by @IID
> it works fine.
>
> Could this be considered a bug in fpc interfaces ?
Yes, it is always wrong to assume that "const" enforces passing by
reference (except when using the mwpascal calling convention).
Jonas
More information about the fpc-pascal
mailing list