[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] define-foreign-enum-type
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-users] define-foreign-enum-type |
Date: |
Thu, 26 Apr 2012 22:55:54 -0500 |
define-foreign-enum-type also defines a bunch of other stuff that you are
skipping over
in your version that compiles, such as garmonbozia->int conversions.
Specifically
if you expand the macro you will find it expands to something like
(define-foreign-type garmonbozia "garmonbozia")
(define-foreign-variable pain "garmonbozia" "pain")
(define (int->garmonbozia x)
(cond ((= x pain) 'pain) ;; this line fails to compile
... etc. ...)
The reason is Chicken cannot convert the reference to the C
foreign variable pain to a Scheme value, because "garmonbozia"
is not a valid Scheme foreign type.
It works fine in the pointer case because you can pass
around pointers to any foreign type (as it's just a
C pointer, and Chicken doesn't have to do any conversion).
Jim
On Apr 26, 2012, at 9:40 PM, John J Foerch wrote:
> Hello,
>
> I am using chicken 4.7.0, and in the course of writing some library
> bindings, I came upon a difference between define-foreign-type and
> define-foreign-enum-type that puzzles me. Here is a minimal program
> that shows it:
>
> (import chicken scheme foreign foreigners)
>
> #>
> typedef enum {
> pain,
> suffering,
> fear
> } garmonbozia;
>
> void creepy_dream (garmonbozia *x) {
> printf("give me back my garmonbozia!\n");
> *x = fear;
> }
> <#
>
> ;;; this compiles:
> (define-foreign-type garmonbozia "garmonbozia")
>
> ;;; this does not:
> ;; (define-foreign-enum-type (garmonbozia "garmonbozia")
> ;; (garmonbozia->int int->garmonbozia)
> ;; pain suffering fear)
>
> (define (creepy-dream)
> (let-location ((a int))
> ((foreign-lambda void creepy_dream (c-pointer garmonbozia))
> (location a))
> a))
>
> (print (creepy-dream))
>
> It compiles and works fine with the 'define-foreign-type' form, but if I
> comment that one out, and uncomment the 'define-foreign-enum-type' form,
> I get the following error:
>
> Error: illegal foreign return type `garmonbozia'
>
> Error: shell command terminated with non-zero exit status 256:
> /usr/bin/chicken enumpointer6.scm -output-file enumpointer6.c
>
> Can somebody explain the difference?
>
> Thank you,
>
> --
> John Foerch
>
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users