Subject: [clisp-list] Please test stdcall calling convention

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Mon Apr 22 09:27:18 2002

Hi,

> Bruno said that stdcall is not used anymore and may be removed.
> I decided against removing.

Could somebody please report whether the code for :language stdc-stdcall actually works?

What are libraries that require the STDCALL convention?

I tried the following, after seeing in one of Reini Urban's files:
> (ffi-defun-dll "sleep" "Sleep" "(L)" "kernel32.dll")

The following example requires my dynload facility.

[5]> (setq *k32* (user::foreign-library "kernel32.dll"))
#<FOREIGN-POINTER #x77E70000>

[7]> (setq sleep-address (resolve-foreign-name "Sleep" *k32* 'ffi:foreign-function))
#<FOREIGN-ADDRESS #x77E76779>

[10]> (setq sleepf (foreign-address-function "Sleep" sleep-address
  (ffi::parse-c-type '(ffi:c-function (:arguments (delay ffi:ulong)) (:return-type nil) (:language :stdc-stdcall))) ))
#<FOREIGN-FUNCTION "Sleep" #x77E76779>

[14]> (funcall sleepf 100)
; seems to wait 1 second

[16]> (setq sleepweirdf (foreign-address-function "Sleep" sleep-address
  (ffi::parse-c-type '(ffi:c-function (:arguments (delay ffi:ulong)) (:return-type nil) (:language :stdc))) ))
[18]> (funcall sleepweirdf 1000)
; seems to wait for 1 second as well

I.e., both :language :stdc and :stdc-stdcall seem to work!?!
-- At least with this trivial testcase OF WHICH I DON'T EVEN
KNOW WHAT LINKAGE it requires! I know next to nothing about the
MS-Windoze API). Both cases should *not* work (at least, the
C stack may be corrupt with one of them, even if it doesn't
show immediately).

[21]> (describe sleepf)
#<FOREIGN-FUNCTION "Sleep" #x77E76779> is a foreign function of foreign type 
(FFI:C-FUNCTION (:ARGUMENTS ((:|arg1| FFI:ULONG :IN :NONE)))
 (:RETURN-TYPE NIL :NONE) (:LANGUAGE :STDC-STDCALL)).

[22]> (describe sleepweirdf)
#<FOREIGN-FUNCTION "Sleep" #x77E76779> is a foreign function of foreign type 
(FFI:C-FUNCTION (:ARGUMENTS ((:|arg1| FFI:ULONG :IN :NONE)))
 (:RETURN-TYPE NIL :NONE) (:LANGUAGE :STDC)).

Help welcome,
	Jorg Hohle.