chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] some questions about easyffi and foreign code


From: Kristian Lein-Mathisen
Subject: Re: [Chicken-users] some questions about easyffi and foreign code
Date: Sun, 3 Feb 2013 10:48:57 +0100


Hey Hugo,

Yeah, that example wasn't working for me either. If you put "(use easyffi)" at the top of the file though, it should work. Note that easyffi is deprecated, use bind instead:

(use bind)
(bind* "double modf(double x, ___out double *iptr);")
(let-values ([(frac int) (modf 33.44)])
    (print frac " " int))

I'm afraid I don't understand what Kon means either...

If 64-bit integers are all you need, perhaps you can use the foreign type unsigned-integer64? I'm guessing the C compiler will handle that even if you're on a 32bit system. I'm not sure how Chicken will handle integer64's if you're on a 32bit system though.

If you want to continue using your multiword version, you could look into the u32vector foreign type. It will give you a nice array on the C-side, and a nice vector on the Chicken side:

(use srfi-4)
(define double->uint64
  (foreign-lambda* void ((double d) (u32vector _o))
    "
    uint32_t* ptr = (uint32_t*)&d;
    _o[0] = ptr[0];
    _o[1] = ptr[1];
   "))

(define (double->byte-blob value)
  (let ((out (make-u32vector 2)))
    (double->uint64 value out)
    out))
 
(print (double->byte-blob 1.3) "\n"
       (double->byte-blob 0) "\n"
       (double->byte-blob 1) "\n"
       (double->byte-blob 100))

I don't know if this is a good approach, though. Maybe someone knows how uint64_t foreign-types are handled on 32bit systems?

K.


On Sun, Feb 3, 2013 at 1:52 AM, Hugo Arregui <address@hidden> wrote:
Hi again,

> 1) ..
> $ csc -X easyffi test.scm -c++; ./test
>
> Error: unbound variable: foreign-parse
>         Call history:
>         foreign-parse
>
> I have no idea of what's going on.

Could this be a problem in my installation?

The example in the wiki is not working either:

#>!
#ifndef CHICKEN
#include <math.h>
#endif

double modf(double x, ___out double *iptr);
<#

(let-values ([(frac int) (modf 33.44)])
    (print frac " " int))

//with the same error: "unbound variable: foreign-parse"

> 2) Then I tried another approach:
>..
> Error: bad argument type - not a pointer: 0

I found a way to do this[1]. But, I found another problem: big int32
are promoted to flonums, I know that this is an expected behaviour,
but I have a doubt:

In a message[2] Kon Lovett writes:

"Means you want to compile w/ generic-arithmetic & usual-integrations
when using a foreign call."

I suposse this is a compiler setting, but I don't now how to enable
it. Also, I don't know what  "usual-integrations" means, could you
provide more details please?

Thanks again, and sorry for bothering you.
Regards,
Hugo

[1] http://pastebin.com/XH5n3V72
[2] http://lists.nongnu.org/archive/html/chicken-users/2007-05/msg00227.html

_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users


reply via email to

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