[fpc-devel] Safecall on Linux (and other unices?)
Joost van der Sluis
joost at cnoc.nl
Thu Jul 22 17:57:27 CEST 2010
On Thu, 2010-07-22 at 13:52 +0200, José Mejuto wrote:
> Hello Joost,
>
> Wednesday, July 21, 2010, 12:46:32 PM, you wrote:
> >> It is not 100% cdecl, const records in safecall must be passed as
> >> reference while in cdecl a copy of the record is being passed.
> JvdS> I don't think so. The gecko-port-definitions are wrong in this regard.
> JvdS> They use 'const' but it should be 'var'. That this worked on Windows was
> JvdS> just a coincidence. I've replaced these 'const' parameter definitions to
> JvdS> 'var' and now they work on Linux and Windows. The headers just weren't
> JvdS> translated right in this regard.
>
> Even if declarations in the code are wrong (which I had not checked, I
> assumed they were fine) the "const" behavior with record in Windows
> safecall and linux cdecl is different.
Offcourse the behaviour is different for a different calling convention
and OS. That's perfectly normal. If all calling conventions were the
same, we woudn't have them.
Fact is that the person who wrote these headers thought that 'const'
could be used to pass parameters by reference. Too bad that he/she was
wrong. That it worked (only on windows/32 bit) is fine for him/her, but
not for us. (Probably he/she didn't care as it worked on Delphi only)
> Also parameters not intented to
> be modified should not be var but const (IMHO).
Well, problem is that maybe you defined them as 'const', the underlying
c-library just defined them as *record. So it *can* change. const is
misleading.
> JvdS> That was a good starting point, to find out what the problem was
> JvdS> precisely. Jonas last comment was where I started. But enabling the
> JvdS> exception-handling wasn't enough. Using Safecall on Linut, the caller
> JvdS> has to clean up the stack (on windows the callee does). I don't know yet
> JvdS> how to the latter.
> JvdS> I don't think the parameter-passing should be changed. Just don't use
> JvdS> 'const'.
>
> I think if it is named safecall is must match windows safecall. Maybe
> better use "xpcom" or "unixsafecall" ? Parameter passing mode should
> match at all, callee or caller clean up is transparent to the people
> working with the library or other library, but how parameters are
> passed could bring a lot of confusion.
Being compatible with some windows-thing on Linux is useless.
Joost
More information about the fpc-devel
mailing list