chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Fwd: libffi


From: Zbigniew
Subject: Re: [Chicken-users] Fwd: libffi
Date: Mon, 28 Nov 2005 03:15:39 -0600

I got libffi to work, and ran some tests on the objc egg.  In my
opinion, if lazy-ffi is the way you choose to go, it will need some
modifications to arg and return value conversion, because the current
state acts unexpectedly as compared to the native FFI.  I appended
some test results below (I sent Felix the simple TypeTest class
earlier, in type-test.m).  To summarize:

-- Unsigned/signed short/int/long cannot be distinguished.
-- Floats/doubles cannot be distinguished, not too critical.
-- Unsigned char arg does not accept characters nor does return value
return a char.  This is actually in objc-base.scm, not lazy-ffi, and
can easily be altered.
-- Cannot pass or return integers outside of fixnum range as
C_fix/C_unfix is used instead of C_int_to_num / C_num_to_int.
-- Boolean values are always returned as false [#\nul].  Still
tracking this down.
-- False booleans could be returned as #f as described in a previous
message.  One way is a special type (say objc-char: or objc-bool:) in
lazy-ffi.

I wanted to add instance variable ref and set to the objc egg.  The
type conversion in my original code is done by a simple switch
statement, which I set up to mimic the native FFI.  In this case, it
seems wise to piggyback off the conversion method used by the objc
egg, which means using lazy-ffi to perform the conversion.  (Even
though it is a bit heavyweight for a simple variable access.)

My question is, should I bother looking into using and modifying the
lazy-ffi type conversion for this?  Or are you going to move to a
NSInvocation model, and write a simple separate type converter?  Or
should I just wait until the egg stabilizes?

Test output follows.

#;5> @[TypeTest isGreaterThanThree: 1]
#\nul

;; True value not returned correctly

#;6> @[TypeTest isGreaterThanThree: 4]
#\nul

;; Inexact not accepted for int (contradicts C FFI, where flonum
within integer range is truncated)

#;7> @[TypeTest printInt: 1.1 Double: 2.2 Float: 3.3]
Error: (inexact->exact) inexact number can not be represented as an
exact number: 1.1

;; Floats passed as doubles -- too much precision here

#;7> @[TypeTest printInt: 1 Double: 2.2 Float: 3.3]
printInt: 1 2.2000000000000001776 3.29999999999999982236
#\nul

;; Uchar return does not return a character

#;2> @[TypeTest convertIntToUChar: 2]
2

@[TypeTest returnDoublePlusOneHalf: 2.1]
2.6 ;; correct

@[TypeTest convertIntToUShort: -1]
65535  ;; ok because short cast performed in C

;; UChar type doesn't accept a character

@[TypeTest nextChar: #\a]
Error: (inexact->exact) bad argument type: #\a

;; UChar type expects and returns an int, should be char

@[TypeTest nextChar: 3]
4

;; No true values appear to be returned.

@[TypeTest isTrue: #t]
#\nul
#;9> @[TypeTest isTrue: #\x1]
#\nul
#;10> @[TypeTest isTrue: #f]
#\nul

;; UInt (and short and ushort and long and ulong) are treated as int)

@[TypeTest convertIntToUInt: -1]
-1

;; Integers outside of machine range not allowed (C_fix is used
;; instead of C_int_to_num)

#;14> @[TypeTest convertIntToUInt: (expt 2 30)]
Error: (inexact->exact) inexact number can not be represented as an
exact number: 1073741824.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]