[plt-scheme] Re: FFI error leads to memory corruption

From: Noel Welsh (noelwelsh at gmail.com)
Date: Fri Sep 11 07:50:09 EDT 2009

I'm unable to pin down the source of the problem, and I've run out of
time. Symptoms as follows:

 - All C code runs fine
 - Same code reliably crashes when run using Scheme FFI.  Function
prototype and FFI binding are below, in case I've made some boneheaded

void idc(polar_t ref_pts[], polar_t new_pts[], int n_pts,
         double xt, double yt, double a, double rotation,
         int iterations, double threshold,
         double *xt_out, double *yt_out, double *a_out)

(define-icp (icp-internal
             (ref-pts : (_vector i _polar)) (new-pts : (_vector i _polar))
             (_int = (vector-length ref-pts))
             _double* _double* _double* _double*
             _int _double
             (xt : (_ptr o _double)) (yt : (_ptr o _double)) (a :
(_ptr o _double))
             (values xt yt a)))

where define-icp is

(define-syntax (define-icp stx)
  (syntax-case* stx () free-identifier=?
    [(define-icp (scheme-name c-name type ...))
     #'(define scheme-name
          (_fun type ...)))]))

On the vanishingly small chance that you (yes, you, dear reader) are
interested in experiencing these crashes for yourself, please check
out the scheme+c branch of icp at github.com/noelwelsh


On Fri, Sep 11, 2009 at 11:23 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> On further investigation, this is a false alarm, that goes away when
> valgrind is run with the --vex-iropt-precise-memory-exns=yes option
> Investigating further...
> N.

Posted on the users mailing list.