[cffi-devel] Validate auto-generated wrappers

Surendra Singhi efuzzyone at netscape.net
Wed Dec 14 09:49:54 UTC 2005


Hi,
  I wrote a quick swig hack to parse c files and generate cffi headers. I will
appreciate if you can verify them, and suggest me how can I improve the
auto-generated headers, or if you can give me some test cases.

Disclaimer: I am not very familiar with cffi, so if I am making any obvious
mistakes please point out.

The C input file:

-----------------------------------------------------------
  char *s; };

struct cfunr * cfun (int i,char *s,struct cfunr * r,int a[10]) {
  int j;
  struct cfunr * r2;
  printf("i = %d\n", i);
  printf("s = %s\n", s);
  printf("r->x = %d\n", r->x);
  printf("r->s = %s\n", r->s);
  for (j = 0; j < 10; j++) printf("a[%d] = %d.\n", j, a[j]);
  r2 = (struct cfunr *) malloc (sizeof (struct cfunr));
  r2->x = i+5;
  r2->s = "A C string";
  return r2;
}

void* lispsort_function(int);


void lispsort_double (int n, double * array) {
    double * sorted_array;
    int i;
    lispsort_begin(n); /* store #'sort2 in lispsort_function */
    sorted_array = ((double * (*) (double *)) lispsort_function) (array);
    for (i = 0; i < n; i++) array[i] = sorted_array[i];
    free(sorted_array);
}
void test(float x , double y);
}
---------------------------------------------------------------------

_The auto-generated lisp file (indentation and spacing fixed)_


---------------------------------------------------------------------------

;; This is an automatically generated file. 
;;Make changes as you feel are necessary (but remember if you try to
regenerate this file, your changes will be lost).  

(defpackage :test
    (:use :common-lisp :cffi)
  (:export
	:max
	:acbdsqr_
	:make-bar
	:bar-x
	:bar-y
	:bar-a
	:bar-b
	:bar-z
	:bar-n
	:my_struct
	:make-foo
	:foo-a
	:foo-b
	:pointer_func
	:make-div_t
	:div_t-quot
	:div_t-rem
	:func123
	:func1234
	:make-cfunr
	:cfunr-x
	:cfunr-s
	:cfun
	:lispsort_function
	:lispsort_double
	:test))

(in-package :test)

(defconstant max 1000)

(defcfun ("acbdsqr_" acbdsqr_)	 :void
  (xyz :pointer))

(defcstruct bar
    (x :short)
  (y :short)
  (a :char)
  (b :char)
  (z :pointer)
  (n :pointer))

(def-c-var ("my_struct" my_struct)
    :pointer)

(defcstruct foo
    (a :int)
  (b :pointer))

(defcfun ("pointer_func" pointer_func)	 :int
  (ClosureFun :pointer)
  (y :int))

(defcstruct div_t
    (quot :int)
  (rem :int))

(defcfun ("func123" func123)	 :int
  (x :pointer)
  (z :pointer)
  (y :pointer))

(defcfun ("func1234" func1234)	 :void
  (x :pointer))

(defcstruct cfunr
    (x :int)
  (s :string))

(defcfun ("cfun" cfun)	 :pointer
  (i :int)
  (s :string)
  (r :pointer)
  (a :pointer))

(defcfun ("lispsort_function" lispsort_function)	 :pointer
  (arg0 :int))

(defcfun ("lispsort_double" lispsort_double)	 :void
  (n :int)
  (array :pointer))

(defcfun ("test" test)	 :void
  (x :float)
  (y :double))
----------------------------------------------------------------

 
-- 
Surendra Singhi
http://www.public.asu.edu/~sksinghi/index.html

The best-laid plans of mice and men go oft astray.




More information about the cffi-devel mailing list