Possbile Bug in chibi-ffi?

38 views
Skip to first unread message

Michael Gorlick

unread,
Nov 24, 2021, 3:58:12 PM11/24/21
to chibi-scheme
My apologies in advance as I may be misusing chibi-ffi, in which case, guidance is appreciated. A simple test case follows. I'm using chibi-ffi in chibi-scheme 0.10.0

First a trivial C header file "bug.h":
struct X;
struct X** example(int);

Then a FFI stub,  "bug.stub":
(c-include "bug.h")
(define-c-struct X)
(define-c (array X null) example (int))


Running gcc I get:

$ gcc -fPIC -shared bug.c bug.h -lchibi-scheme -o bug.so
bug.c: In function ‘sexp_example_stub’:
bug.c:21:117: error: expected ‘;’ before ‘)’ token
   21 |     sexp_car(res) = sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_return_type(self)), tmp[i], SEXP_FALSE, 0));
      |                                                                                                                     ^
      |                                                                                                                     ;
bug.c:21:117: error: expected statement before ‘)’ token

For completeness the critical generated C code follows with the failing code in boldface:
/* Automatically generated by chibi-ffi; version: 0.4 */

#include <chibi/eval.h>

#include "bug.h"
/*
types: (X)
enums: ()
*/

sexp sexp_example_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0) {
  int i = 0;
  struct X* *tmp;
  sexp res;
  if (! sexp_exact_integerp(arg0))
    return sexp_type_exception(ctx, self, SEXP_FIXNUM, arg0);
  tmp = example(sexp_sint_value(arg0));
  res = SEXP_NULL;
  for (i=0; tmp[i]; i++) {
    sexp_push(ctx, res, SEXP_VOID);
    sexp_car(res) = sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_return_type(self)), tmp[i], SEXP_FALSE, 0));
  }
  res = sexp_nreverse(ctx, res);
  return res;


Reply all
Reply to author
Forward
0 new messages