[gambit-list] Practices in FFI development, previously Re: Tracking Down a Segfault

Joel J. Adamson <adamsonj@email.unc.edu> adamsonj at email.unc.edu
Fri Sep 5 09:06:55 EDT 2008


>>>>> "Mikael" == Mikael More <mikael.more at gmail.com> writes:
,----
| 
| /*  C function for transferring vectors */
| int f64vector_length (___SCMOBJ);
| double f64vector_ref (___SCMOBJ, int);
| double * scm_vector_to_C (___SCMOBJ f64vec)
| {
|   /* initialize the length of the vector */
|   int len = f64vector_length (f64vec);
|   /* initializes the new vector */
|   double * newCvec = malloc (len*sizeof (double));
|   /* declare a counter */
|   int i;
|   /* iterate over the length of the vector copying each object into
|      the new vector */
|   for (i = 0; i<len; i++)
|     {
|       /* could be re-written using pointer arithmetic */
|       newCvec[i] = f64vector_ref (f64vec, i);
|     }
|   return newCvec;
| }
| 
`----


    Mikael> Can you please provide the complete c-lambda for this one?

Sorry I was unclear: this is part of a C header that I include.  An
example function invoking it would be:

,----
| (define make-gsl-matrix
|   (c-lambda (int int scheme-object)
| 	    gsl-matrix*
| 	    "gsl_matrix * ___matrix = gsl_matrix_alloc (___arg1, ___arg2);
=====>        ___matrix->data = scm_vector_to_C (___arg3);
|             ___matrix->size1 = ___arg1;
|             ___matrix->size2 = ___arg2;
|             ___result_voidstar = ___matrix;"))
| 
`----

I'm still digesting the rest of your message (and breakfast).

Joel
-- 
Joel J. Adamson
University of North Carolina at Chapel Hill
CB #3280, Coker Hall
Chapel Hill, NC 27599-3280

Before you reply to this email, please read
http://www.unc.edu/~adamsonj/email-howto.html



More information about the Gambit-list mailing list