From: Hoehle, Joerg-C. <Joe...@t-...> - 2005-06-27 16:34:15
|
Hi, Roger Corman said on the topic of name mangling (back in 2003), aka. = "decoration": >You could try to make it easier by doing his automatically, but you = don't >in general know what name mangling scheme was used (if any was used). = DLLs >may have been generated by different compilers. In Corman Lisp FFI I = ignore >it and let the user worry about it. If they call a mangled name, they = have >to explicitly specify that name. Nobody has complained, probably = because >most exported functions do not have mangled names (if they support a C >interface anyway). >The Microsoft C++ compiler automatically does the name mangling unless = you tell it otherwise. >This is to catch problems (incorrect declarations) at link time rather = than run time. >However, you can disable it when you build (link) a DLL by including a = .def file, >with the names explicitly listed.=20 >Microsoft does this for all their system DLLs. The names are not = mangled. Uhoh, it means there are libraries around with mangled names and others = without ... I bet this kills portable-among-implementations packages like cl-gd, = unless it uses some macros like (with-name-mangling-of-type foo do...) Roger also writes: >Sometimes if you use the wrong linkage you won't notice, because (a) = if >there are no parameters it makes no difference (b) even if there are >parameters, usually exiting a function cleans up the stack properly. = If >something is linked with __cdecl (C conventions) and you call it with >__stdcall, nobody cleans the stack. This might work, as long as you >don't do it in a big loop, and you don't embed the call in another = call=20 >i.e. foo(bar(x, y), z). I think it means that one should not see problems with it in CLISP -- = except when callbacks are involved, where the foreign land will be = responsible for cleaning the stack. For direct calls, stack clean up at = exit of clisp' invoke-foreign-function() function will prevent both the = loop accumulation or embeded scenarios, since clisp does not compile to = native code. So what's left: - stdcall is the correct declaration for bgd.dll, according to = Boutell'd docs. - for FFI purposes, that library would have been more useful as cdecl. - remove the "@" check code from def-call-out. @ is acceptable in the = C names, at least on MS-Windows. - let users handle name mangling or - still try to provide some generic rule, so that packages like cl-gd = can be written with some hope for portability?? - ??? Regards, J=F6rg H=F6hle. |