I have the following in a test header:

struct FunkyFrizzle
{
    int integer;
    float submarine;
    char string[64];
};
typedef struct FunkyFrizzle FunkyFrizzle;
double int_exp(double base, int pow);
double square(double v);

The code generated by chicken-bind appears to treat "string" as a plain
pointer rather than an actual array, however:

;;; GENERATED BY CHICKEN-BIND FROM test.h

(begin
  (define FunkyFrizzle-integer
    (foreign-lambda*
      integer
      (((c-pointer (struct "FunkyFrizzle")) s))
      "return(s->integer);"))
  (define FunkyFrizzle-submarine
    (foreign-lambda*
      float
      (((c-pointer (struct "FunkyFrizzle")) s))
      "return(s->submarine);"))
  (define FunkyFrizzle-string
    (foreign-lambda*
      c-string
      (((c-pointer (struct "FunkyFrizzle")) s))
      "return(s->string);"))
  (define make-FunkyFrizzle
    (foreign-lambda*
      (c-pointer (struct "FunkyFrizzle"))
      ((integer integer) (float submarine) (c-string string))
      "struct FunkyFrizzle *tmp_ =  (struct FunkyFrizzle
*)C_malloc(sizeof(struct FunkyFrizzle));\ntmp_->integer =
integer;\ntmp_->submarine = submarine;\ntmp_->string =
string;\nreturn(tmp_);;\n"))
  (begin
    (define int_exp
      (foreign-lambda*
        double
        ((double a0) (integer a1))
        "return(int_exp(a0 , a1));")))
  (begin
    (define square
      (foreign-lambda* double ((double a0)) "return(square(a0));"))))

;;; END OF FILE

As you can see, in make-FunkyFrizzle it attempts to assign into the array
(tmp_->string = string). This of course causes the C compiler to shout
profanities at me.

Is there a "proper" fix for this? I assumed that this would have been
caught already if it's a bug, but Google failed me there (I'm new to both
scheme and chicken.) I know I could just change the code by hand, but that
feels all icky and kludgy.

Also, foreign-lambda* documentation [at
wiki.call-cc.org/man/4/Accessing%20external%20objects] states that one
should use the C_return macro rather than just plain return; is there an
actual reason for using normal return here ir is this indeed an oversight?
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to