RE: cdecl support

new topic     » goto parent     » topic index » view thread      » older message » newer message

-------Phoenix-Boundary-07081998-

Hi Andy Serpa, you wrote on 2/25/02 6:38:18 PM:

>
>The functions in the .dll are supposed to be called using cdecl
>(Remember the thread a month or so back when I brought this up?  Look up
>thread "Program crash with regex wrapper after translation" from
>January.)
>

Thanks for the reminder - it had completely slipped my mind.

> -- it works only by luck because of the way Watcom compiles
>(apparently) when using the interpreter, but crashes if you translate it
>to C with Borland or LCC.  Specifically, it crashes with any call to
>regex_free, but I noticed later that you get corruption in general with
>any call.
>

The interpreter uses the _stdcall convention.

According to Borland:
_stdcall  -- arguments pushed right-to-left
          -- callee cleans the stack
_cdecl    -- arguments pushed right-to-left
          -- caller cleans the stack

When the Watcom interpreter calls a _cdecl routine (like in
regex.dll) some junk gets left on the stack, but it gets
ignored by Watcom's exit code.

The LCC interpreter attempts to exit by popping saved
registers (which are the junk left by the C call - disaster.).

If the interpreter pops the stack after the C call,
it is using the _cdecl convention and either Watcom or
LCC work fine on regex.dll. (verified)

The interpreter could be easily modified to save the stack
address at the start of its 'call_c' routine and restore it
directly after the C call, thereby handling either _cdecl
or _stdcall, with any compiler. Basically, two assembly
fragments are needed: save_stk() and restore_stk().

Is it really that simple, or am I overlooking something?

I would guess that this approach could also
be applied to the translator.

Can someone supply me with a reasonably small
_stdcall DLL to verify my code on?

Karl Bochert

-------Phoenix-Boundary-07081998---

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu