I have two computers, both Linux/x386. - The desktop is Debian unstable, Darcs pull 2006-03-07 23:11, SBCL 0.9.8.42 - The laptop is Ubuntu 05.10, Darcs pull 2006-03-17 23:59, SBCL 0.9.9 On both I have GSL (libgsl0) installed, which includes two libraries /usr/lib/libgslcblas.so.0 /usr/lib/libgsl.so.0 which I have made links to the corresponding .so names.
On each I do: (require :asdf) (require :cffi) (in-package :cffi) (cffi:load-foreign-library "/usr/lib/libgslcblas.so") (cffi:load-foreign-library "/usr/lib/libgsl.so")
(with-foreign-objects ((retn :double)) (foreign-funcall "gsl_sf_bessel_Jn_array" :int 0 :int 2 :double 0.25d0 :pointer retn :int) (mem-aref retn :double 0))
On the desktop, everything works normally and I get 0.9844359292958527d0
On the laptop, I get an SBCL crash with the following message:
Argh! corrupted error depth, halting fatal error encountered in SBCL pid 29184(tid 3085391552): %PRIMITIVE HALT called; the party is over.
The system is too badly corrupted or confused to continue at the Lisp level. If the system had been compiled with the SB-LDB feature, we'd drop into the LDB low-level debugger now. But there's no LDB in this build, so we can't really do anything but just exit, sorry.
Some other results on the laptop: - All functions I've tried that return a pointer to an array of doubles have this problem. - Sometimes the problem behavior varies. For example, If the third argument is 0.5d0, SBCL simply locks up instead of crashing. Sometimes I get an infinite output of error messages that repeat the line "mprotect: Cannot allocate memory" over and over.
Any debugging advice? Thanks.
Liam
On Sun, 2006-03-19 at 12:53 -0500, Liam M. Healy wrote:
- The desktop is ..., Darcs pull 2006-03-07 23:11, SBCL 0.9.8.42
- The laptop is ..., Darcs pull 2006-03-17 23:59, SBCL 0.9.9
This may or may not be an issue.
(with-foreign-objects ((retn :double)) (foreign-funcall "gsl_sf_bessel_Jn_array" :int 0 :int 2 :double 0.25d0 :pointer retn :int) (mem-aref retn :double 0))
I know nothing about GSL besides what I just read about the function you call above, but don't you need to allocate space for 3 doubles, not just one, for the retn (result_array) argument?
Function: int gsl_sf_bessel_Jn_array (int nmin, int nmax, double x, double result_array[]) This routine computes the values of the regular cylindrical Bessel functions J_n(x) for n from nmin to nmax inclusive, storing the results in the array result_array. The values are computed using recurrence relations for efficiency, and therefore may differ slightly from the exact values.
- All functions I've tried that return a pointer to an array of doubles
have this problem.
- Sometimes the problem behavior varies. For example, If the third
argument is 0.5d0, SBCL simply locks up instead of crashing. Sometimes I get an infinite output of error messages that repeat the line "mprotect: Cannot allocate memory" over and over.
Any debugging advice?
If the above didn't help, try to rewrite the crashing behavior using SB-ALIEN: http://www.sbcl.org/manual/Foreign-Function-Interface.html
If you still get the crash, it may be an issue with misinterpretation, or SB-ALIEN. Otherwise, it may be a problem with how CFFI uses SB-ALIEN.