[cffi-devel] CFFI:FOREIGN-ALLOC Problem

Volkan YAZICI yazicivo at ttmail.com
Tue Sep 8 07:07:54 UTC 2009


Hi,

I've attached[1] a small subset of the actual program to reproduce the
problem. You'll need cl-fad, cffi, and binomial-heap packages to compile
and load the node-access-log-parser.lisp file. After loading the file,
just issue below command while in `NALP' package.

  (compare-partitionings
   "/tmp/cffi-foreign-alloc-test/"
   "/tmp/cffi-foreign-alloc-test/sanitized-logs.out"
   "/tmp/cffi-foreign-alloc-test/weights.out"
   40 16 0.2)


Regards.

[1] http://www.students.itu.edu.tr/~yazicivo/tmp/cffi-foreign-alloc-test.tar.bz2

On Mon, 07 Sep 2009, Volkan YAZICI <yazicivo at ttmail.com> writes:
> I use below macro to allocate foreign vectors.
>
>   (defmacro with-foreign-vectors ((&rest bindings) &body body)
>     "Convenient macro to create foreign vector bindings. `BINDIGS' are of `(NAME
>     TYPE INITIAL-CONTENTS)' format."
>     `(let* ,(loop with val = (gensym)
>                   for (name type initial-contents) in bindings
>                   collect `(,name
>                              (let ((,val ,initial-contents))
> ;                               (let ((*print-length* 10))
> ;                                 (format *trace-output* "~S => ~D ~S (~A)~%"
> ;                                         ',name (when ,val (length ,val))
> ;                                         ,val (find nil ,val)))
>                                (foreign-alloc ,type
>                                               :count (length ,val)
>                                               :initial-contents ,val))))
>        (unwind-protect (progn , at body)
>          ,@(mapcar
>             (lambda (name) `(foreign-free ,name))
>             (mapcar #'car bindings)))))
>
> But while running the program, it throws below error message. (I
> experience same situation in both SBCL and CCL.)
>
>   NALP> (compare-partitionings
>          "/home/vy/bilkent/projects/xml/t/xmark-1024-20091006-1314-small/"
>          "/home/vy/bilkent/projects/xml/t/xmark-1024-20091006-1314-small/sanitized-logs.out"
>          "/home/vy/bilkent/projects/xml/t/xmark-1024-20091006-1314-small/weights.out"
>          40 16 0.2)
>   N-PTR => 1 #(7536) (NIL)
>   XADJ-PTR => 7537 #(0 1 3 5 6 8 10 12 14 16 ...) (NIL)
>   ADJNCY-PTR => 8011 #(1 80 2 5666 3 4 2044 5 2292 6 ...) (NIL)
>   ; Evaluation aborted.
>
>   ; The value NIL is not of type (SIGNED-BYTE 32).
>   ;    [Condition of type TYPE-ERROR]
>   ; 
>   ; Restarts:
>   ;  0: [RETRY] Retry SLIME REPL evaluation request.
>   ;  1: [ABORT] Return to SLIME's top level.
>   ;  2: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" RUNNING {AA75079}>)
>   ; 
>   ; Backtrace:
>   ;   0: (CFFI-SYS:%MEM-SET NIL #.(SB-SYS:INT-SAP #X080C8850) :INT 16620)
>   ;       Locals:
>   ;         CFFI-SYS::OFFSET = 16620
>   ;         CFFI-SYS::PTR = #.(SB-SYS:INT-SAP #X080C8850)
>   ;         TYPE = :INT
>   ;         CFFI-SYS::VALUE = NIL
>   ;   1: (FOREIGN-ALLOC :INT)[:EXTERNAL]
>   ;       Locals:
>   ;         SB-DEBUG::ARG-0 = 5
>   ;         SB-DEBUG::ARG-1 = :INT
>   ;   2: (METIS-BIPARTITION-GRAPH-FFI #(0 1 3 5 6 8 ...) #(1 80 2 5666 3 4 ...) #(1 1 1 1 1 1 ...) #(20 7 13 1 19 20 ...) 0.2)
>   ;       Locals:
>   ;         SB-DEBUG::ARG-0 = #(0 1 3 5 6 8 ...)
>   ;         SB-DEBUG::ARG-1 = #(1 80 2 5666 3 4 ...)
>   ;         SB-DEBUG::ARG-2 = #(1 1 1 1 1 1 ...)
>   ;         SB-DEBUG::ARG-3 = #(20 7 13 1 19 20 ...)
>   ;         SB-DEBUG::ARG-4 = 0.2
>
> When I look at the printed results, there doesn't appear any `NIL'
> values in any of the `:INITIAL-CONTENTS' vectors. But error tells that
> one of the `VALUE' arguments passed to `CFFI-SYS:%MEM-SET' is `NIL'.
>
> Below are some of the detailed macroexpansions related to
> `CFFI-SYS:%MEM-SET'.
>
>   (define-mem-accessors
>     (:char sb-sys:signed-sap-ref-8)
>     (:unsigned-char sb-sys:sap-ref-8)
>     (:short sb-sys:signed-sap-ref-16)
>     (:unsigned-short sb-sys:sap-ref-16)
>     (:int sb-sys:signed-sap-ref-32)
>     (:unsigned-int sb-sys:sap-ref-32)
>     (:long sb-sys:signed-sap-ref-word)
>     (:unsigned-long sb-sys:sap-ref-word)
>     (:long-long sb-sys:signed-sap-ref-64)
>     (:unsigned-long-long sb-sys:sap-ref-64)
>     (:float sb-sys:sap-ref-single)
>     (:double sb-sys:sap-ref-double)
>     (:pointer sb-sys:sap-ref-sap))
>
> Which turns into below form if I macroexpand the `DEFINE-MEM-ACCESSORS'.
>
>   ...
>   (DEFUN %MEM-SET (VALUE PTR TYPE &OPTIONAL (OFFSET 0))
>     (ECASE TYPE
>       (:CHAR (SETF (SB-SYS:SIGNED-SAP-REF-8 PTR OFFSET) VALUE))
>       (:UNSIGNED-CHAR (SETF (SB-SYS:SAP-REF-8 PTR OFFSET) VALUE))
>       (:SHORT (SETF (SB-SYS:SIGNED-SAP-REF-16 PTR OFFSET) VALUE))
>       (:UNSIGNED-SHORT (SETF (SB-SYS:SAP-REF-16 PTR OFFSET) VALUE))
>       (:INT (SETF (SB-SYS:SIGNED-SAP-REF-32 PTR OFFSET) VALUE))
>       (:UNSIGNED-INT (SETF (SB-SYS:SAP-REF-32 PTR OFFSET) VALUE))
>       (:LONG (SETF (SB-SYS:SIGNED-SAP-REF-WORD PTR OFFSET) VALUE))
>       (:UNSIGNED-LONG (SETF (SB-SYS:SAP-REF-WORD PTR OFFSET) VALUE))
>       (:LONG-LONG (SETF (SB-SYS:SIGNED-SAP-REF-64 PTR OFFSET) VALUE))
>       (:UNSIGNED-LONG-LONG (SETF (SB-SYS:SAP-REF-64 PTR OFFSET) VALUE))
>       (:FLOAT (SETF (SB-SYS:SAP-REF-SINGLE PTR OFFSET) VALUE))
>       (:DOUBLE (SETF (SB-SYS:SAP-REF-DOUBLE PTR OFFSET) VALUE))
>       (:POINTER (SETF (SB-SYS:SAP-REF-SAP PTR OFFSET) VALUE))))
>   ...
>
> To be honest, I need some urgent assistance. Any helps will be really
> appreciated.




More information about the cffi-devel mailing list