weird ffi argument handling on some callouts

Bug #307638 reported by Marco Maggi
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

;; ikarus-ffi-01.sps -
;;
;;Bug in Ikarus-1716 FFI on i686-pc-linux-gnu.

(import (ikarus)
  (ikarus foreign))

(define libc (dlopen ""))

(define strlen
  ((make-c-callout 'signed-int '(pointer))
   (dlsym libc "strlen")))

(define gmp (dlopen "libgmp.so"))

(define mpq_init
  ((make-c-callout 'void '(pointer))
   (dlsym gmp "__gmpq_init")))

(define mpq_set_si
  ((make-c-callout 'void
     '(pointer signed-long unsigned-long))
   (dlsym gmp "__gmpq_set_si")))

(define mpq_get_str
  ((make-c-callout 'pointer '(pointer signed-int pointer))
   (dlsym gmp "__gmpq_get_str")))

(define (cstring->string p)
  (let* ((len (strlen p))
  (bv (make-bytevector len)))
    (do ((i 0 (+ 1 i)))
 ((= i len)
  (utf8->string bv))
      (bytevector-s8-set! bv i (pointer-ref-c-signed-char p i)))))

(define mpq (malloc 4096))

(mpq_init mpq)
(mpq_set_si mpq 1 2)

(define cstr (mpq_get_str (integer->pointer 0) 10 mpq))
(display (format "mpq should be '1/2' but prints '1/0': ~s\n"
    (cstring->string cstr)))

;;; end of file

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in 1717. Thanks.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Fix Committed
Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.