[racket] Bindings for libgsl (GNU Scientific Library)

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Thu May 24 15:21:50 EDT 2012

Hi All.

I am attempting to get Noels bindings for libgsl working on my machine
(OS X 64 bit).
    https://github.com/noelwelsh/mzgsl

My problem is that it crashes DrRacket and I can't pinpoint where it happens.

I downloaded gsl using port with

    sudo port install gsl

This downloaded and installed version 1.15.

Now racket is able to find and load the libraries.
I can now allocated a gsl_vector with
    (gsl_vector-malloc n).

Allas calling gslvector-fill! aka gsl_vector_set_all will crash Racket.

The vector structure is defined as:

(define-cstruct _gsl_vector
  ([size   _size_t]
   [stride _size_t]
   [data   _pointer]
   [block  _pointer]
   [owner  _int]))

And the actual allocation functions as:

(define (gsl_vector-malloc n)
  (define ptr (malloc _double n 'raw))
  (define v (make-gsl_vector n 1 ptr #f 0))
  (register-finalizer v (lambda (_) (free ptr)))
  v)

Does this look right?

The actual source file is here:
https://github.com/noelwelsh/mzgsl/blob/master/low-level/gsl-vector.ss


The error message after a crash:

Process:         DrRacket [62009]
Path:            /Applications/Racket Full
v5.3.0.6/*/DrRacket.app/Contents/MacOS/DrRacket
Identifier:      org.racket-lang.DrRacket
Version:         5.3.0.6 (5.3.0.6)
Code Type:       X86-64 (Native)
Parent Process:  bash [62005]

Date/Time:       2012-05-24 20:56:26.374 +0200
OS Version:      Mac OS X 10.7.3 (11D50b)
Report Version:  9

Interval Since Last Report:          6884660 sec
Crashes Since Last Report:           77
Per-App Interval Since Last Report:  776847 sec
Per-App Crashes Since Last Report:   3
Anonymous UUID:                      479A6BDE-6BDF-47B6-AB0F-194A795E4C53

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0:
-->
    __TEXT                 0000000100000000-0000000100008000 [   32K]
r-x/rwx SM=COW  /Applications/Racket Full
v5.3.0.6/DrRacket.app/Contents/MacOS/DrRacket

Application Specific Information:
objc[62009]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libgsl.dylib                  	0x000000010d152460 gsl_vector_set_all + 32
1   Racket                        	0x00000001002aee5c ffi_call_unix64 + 76
2   Racket                        	0x00000001002afa74 ffi_call + 644
3   Racket                        	0x00000001002a1c56 ffi_do_call + 1558
4   Racket                        	0x0000000100062282 scheme_do_eval + 9058
5   Racket                        	0x0000000100064fdc
_scheme_apply_multi_from_native + 108
6   ???                           	0x00000001007e4078 0 + 4303241336
7   Racket                        	0x0000000100061f19 scheme_do_eval + 8185
8   Racket                        	0x00000001000640d5 splice_execute + 229
9   Racket                        	0x000000010006111f scheme_do_eval + 4607
10  Racket                        	0x0000000100076754 force_values + 292
11  Racket                        	0x0000000100080452
scheme_force_value_same_mark + 114
12  ???                           	0x00000001007cfdf7 0 + 4303158775
13  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
14  Racket                        	0x00000001000822c9
scheme_finish_apply_for_prompt + 873
15  Racket                        	0x000000010008249c
scheme_apply_for_prompt + 92
16  Racket                        	0x000000010008e062 call_with_prompt + 1282
17  Racket                        	0x00000001000650f9
_scheme_apply_multi_from_native + 393
18  ???                           	0x00000001037e79b0 0 + 4353587632
19  ???                           	0x00000001007d20fb 0 + 4303167739
20  ???                           	0x00000001037e657c 0 + 4353582460
21  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
22  Racket                        	0x00000001000822c9
scheme_finish_apply_for_prompt + 873
23  Racket                        	0x000000010008249c
scheme_apply_for_prompt + 92
24  Racket                        	0x000000010008e062 call_with_prompt + 1282
25  Racket                        	0x00000001000650f9
_scheme_apply_multi_from_native + 393
26  ???                           	0x00000001037e79b0 0 + 4353587632
27  ???                           	0x00000001007c5264 0 + 4303114852
28  Racket                        	0x0000000100064fdc
_scheme_apply_multi_from_native + 108
29  ???                           	0x00000001037e699c 0 + 4353583516
30  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
31  Racket                        	0x0000000100064fdc
_scheme_apply_multi_from_native + 108
32  ???                           	0x00000001007cfee0 0 + 4303159008
33  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
34  Racket                        	0x00000001000822c9
scheme_finish_apply_for_prompt + 873
35  Racket                        	0x000000010008249c
scheme_apply_for_prompt + 92
36  Racket                        	0x000000010008e062 call_with_prompt + 1282
37  ???                           	0x00000001007c51f7 0 + 4303114743
38  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
39  Racket                        	0x00000001000822c9
scheme_finish_apply_for_prompt + 873
40  Racket                        	0x000000010008249c
scheme_apply_for_prompt + 92
41  Racket                        	0x000000010008e062 call_with_prompt + 1282
42  ???                           	0x00000001007d01e5 0 + 4303159781
43  ???                           	0x00000001007c5264 0 + 4303114852
44  Racket                        	0x0000000100076754 force_values + 292
45  Racket                        	0x0000000100080452
scheme_force_value_same_mark + 114
46  ???                           	0x00000001007cfc39 0 + 4303158329
47  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
48  Racket                        	0x00000001000822c9
scheme_finish_apply_for_prompt + 873
49  Racket                        	0x000000010008249c
scheme_apply_for_prompt + 92
50  Racket                        	0x000000010008e062 call_with_prompt + 1282
51  ???                           	0x00000001007d01e5 0 + 4303159781
52  Racket                        	0x0000000100061f19 scheme_do_eval + 8185
53  Racket                        	0x00000001000802d3 apply_k + 179
54  Racket                        	0x0000000100080f86
scheme_top_level_do_worker + 1046
55  Racket                        	0x0000000100280321 start_child + 1153
56  Racket                        	0x000000010028467a make_subprocess + 570
57  Racket                        	0x000000010028495e
scheme_thread_w_details + 446

Posted on the users mailing list.