FAU | 24 Nov 02:13 2014
Picon

clear foreign memory

Hello,

Lets say I want to keep around blocks of foreign memory but I need to
clear them before I reuse them what would be the best way to do it?

In C we could use memset() is there such an equivalent for CFFI?

Thanks,
Frank
Luís Oliveira | 23 Nov 23:16 2014
Picon

pkg-flags (was: Re: Cannot load cffi-libffi)

OK, so I see two needs for pkg-flags here then.

1. finding headers that aren't in the standard locations and wouldn't
otherwise be found.
2. finding headers for a specific version of a library.

I think the current committed behaviour works nicely for use case #1.
Use case #2, which you've raised, suggests that ignoring a missing
pkg-config is a bad default. What about adding making it an option?

Also, if we're going to cater to use case #2, then perhaps we should
support a list of alternatives à la define-foreign-library. What do
you think?

Finally, how about renaming the directive to pkg-config-cflags? (I can
sort of imagine we might want a pkg-config-lfags for wrappers at some
point in the future.)

--

-- 
Luís Oliveira
http://kerno.org/~luis/

_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Luís Oliveira | 22 Nov 16:02 2014
Picon

Issue tracker (still) lives at Launchpad

Hello,

I'm not sure how, but the issue tracker for CFFI's GitHub repository
was somehow enabled. We still use Launchpad for bug tracking --
https://bugs.launchpad.net/cffi -- so I've closed all the issues on
github and moved the one that still needs fixing to launchpad.

Sorry for the confusion.

Cheers,

--

-- 
Luís Oliveira
http://kerno.org/~luis/

_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Liam Healy | 20 Nov 19:36 2014
Picon

Cannot load cffi-libffi

On Debian/Ubuntu and SBCL, I cannot load the latest cffi-libffi

To load "cffi-libffi":
  Load 1 ASDF system:
    cffi-libffi
; Loading "cffi-libffi"
; pkg-config libffi --cflags
; cc -m64 NIL -I/home/healy/languages/lisp/cffi/ -o /home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix /home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix.c

debugger invoked on a CFFI-GROVEL:GROVEL-ERROR in thread #<THREAD "main thread" RUNNING {1002BEE843}>: External process exited with code 1.
Command was: "cc" "-m64" "NIL" "-I/home/healy/languages/lisp/cffi/" "-o" "/home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix" "/home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix.c"
Output was:
cc: error: NIL: No such file or directory


Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                        ] Retry PROCESS-OP on #<GROVEL-FILE "cffi-libffi" "libffi" "libffi">.
  1: [ACCEPT                       ] Continue, treating PROCESS-OP on #<GROVEL-FILE "cffi-libffi" "libffi" "libffi"> as having been successful.
  2:                                 Retry ASDF operation.
  3: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the configuration.
  4: [ABORT                        ] Give up on "cffi-libffi"
  5:                                 Exit debugger, returning to top level.

(CFFI-GROVEL:GROVEL-ERROR "External process exited with code ~S.~ <at>
                     Command was: ~S~{ ~S~}~ <at>
                     Output was:~%~A" 1 "cc" ("-m64" "NIL" "-I/home/healy/languages/lisp/cffi/" "-o" "/home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix" "/home/healy/.cache/common-lisp/sbcl-1.2.3.29-d15420c-linux-x64/home/healy/languages/lisp/cffi/libffi/libffi-unix.c") "cc: error: NIL: No such file or directory
")
0]

I bisected this down to this commit:
     4d5479d692f07c641d3218c4728fa43287528366 is the first bad commit
     commit 4d5479d692f07c641d3218c4728fa43287528366
     Author: Sumant Oemrawsingh <soemraws <at> xs4all.nl>
     Date:   Fri Oct 31 19:03:54 2014 +0100

         Find cc-flags for libffi using pkg-config on linux.

     :040000 040000 2dec1750de47713e34eb726a561dec296a927a17 2a4da151f69703e60f54c8881a84a6a0dcc9d471 M    libffi
  

Liam
_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
FAU | 5 Nov 08:53 2014
Picon

Callbacks & Lambdas

Hello,

I'm kinda new to CFFI.

Is there a reliable/portable way to have lambdas called as a callback
from a foreign C function?  I assume there's not though.

I could imagine it could be simulated (by a dispatcher callback or
something) so I'm wondering if somebody has done something like that
before and may share insight into her/his design.

Thanks,
Frank
FAU | 1 Nov 22:09 2014
Picon

defcstruct &key size

Hello,

Apparently SIZE is not evaluated at macro expansion time.

I basically want to pass the name of a foreign function as SIZE and have
it evaluated.

What would be the best way to do that?

Currently I'm doing this:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (cffi:define-foreign-library libfoo
    (:unix "libfoo.so"))
  (cffi:load-foreign-library 'libfoo)
  (cffi:defctype size :uint)
  (cffi:defcfun ("foo_size" foo-size) size))

(macrolet
    ((m ()
	`(cffi:defcstruct (foo-struct :size ,(eval-when
(:compile-toplevel :load-toplevel :execute) (foo-size)))
			  (data :pointer))))
  (m))
Liam Healy | 21 Oct 23:47 2014
Picon

Debian depends/recommends

I don't know who packages CFFI for Debian, but whoever that is: it would be good to have a depends/recommends on libffi-dev, so the user can load cffi-libffi.

Liam
_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Scott Turner | 4 Oct 05:58 2014
Picon

Problem With Lapack Libraries from Cygwin

I have been using the Lisp Linear Algebra package (LLA) for about a year.  It provides a Common Lisp interface to the BLAS and LAPACK libraries using CFFI.  I use SBCL on Windows and have been loading the BLAS and LAPACK libraries from Cygwin64.

A couple of days ago I updated my Cygwin installation (because of the Shellshock vulnerability) and now when I load these libraries, my SBCL process crashes after a second or two.

CL-USER> (ql:quickload "cffi")
To load "cffi":
  Load 1 ASDF system:
    cffi
; Loading "cffi"
; Loading system definition for alexandria from C:/Users/Dad/quicklisp/dists/quicklisp/software/alexandria-20140826-git/alexandria.asd
; Registering #<SYSTEM "alexandria">
; Loading system definition for trivial-features from C:/Users/Dad/quicklisp/dists/quicklisp/software/trivial-features-20130312-git/trivial-features.asd
; Registering #<SYSTEM "trivial-features">
; Loading system definition for babel from C:/Users/Dad/quicklisp/dists/quicklisp/software/babel-20140713-git/babel.asd
; Registering #<SYSTEM "babel">
.
("cffi")
CL-USER> (cffi:load-foreign-library "CYGBLAS-0.DLL")
#<CFFI:FOREIGN-LIBRARY CYGBLAS-0.DLL-872 "CYGBLAS-0.DLL">
(crashed)

The two libraries I load (CYGBLAS-0.DLL and CYGLAPACK-0.DLL) have not changed in about a year.  Other libraries (such as the DLLs found in Windows/System32) load without a problem.   The Lapack libraries in the Cygwin32 distribution are not recognized as valid Win32 applications by CFFI.  I've tried older versions of SBCL and CFFI with no success.

I've replicated the problem exactly on a second machine.  It should be easy to test:  Install SBCL, install Cygwin64, install CFFI, and then try (cffi:load-foreign-library "CYGBLAS-0.DLL"). You may have to provide the full path.  Sometimes it takes a short while for the process to crash.

I'm very baffled by the problem, and I hope someone on this list will have a fix or some ideas on how to debug the situation.  I'd also appreciate it if someone would see if the problem replicates on their machine.  Also, if someone has a source for alternate DLLs for BLAS and LAPACK that CFFI can load on Windows, I could try those to see if they have the same problem.

Thanks!

Scott Turner



_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Luís Oliveira | 21 Sep 19:25 2014
Picon

CFFI 0.14.0 released

Hello,

I've just released CFFI 0.14.0.
https://github.com/cffi/cffi/wiki/NEWS#version-0140

Cheers,

--

-- 
Luís Oliveira
http://kerno.org/~luis/

_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Mirko Vukovic | 18 Sep 16:36 2014
Picon

Native GSLL on Windows: Q on osicat and cffi/libffi

Hello,

I have built GSLL (Lieam Healy's Gnu Scientific Library interface) on CCL on Windows 7.  I used Cygwin's version of the MinGW GCC compiler suite.  GSLL runs nicely with vast majority of tests passing (77 failures, 6 execution errors). 

Main point is that this is Windows native: GSL, CCL, MinGW.

However my build procedure includes some hacks.  I am wondering if they are
- correct
- is there a cleaner/better way of doing them.

At one step I am hard-coding some constants that originate in /usr/include/sys/stat.h into one of osicat's files.  (I copied that code from a link that I post in the instructions).

I am wondering if I can avoid this step by teaching cffi and grovel about that file stat.h

I have put the instructions for GSLL+CCL+Win7 on github (http://github.com/mirkov/gsll-ccl-MinGW).  There you will find a section OSICAT JWBM where I list the modifications. 

A few lines below you will find also some modifications I did in cffi/libffi/lilbffi-windows32.lisp.  Same question applies.

Thanks,

Mirko
_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
Joeish W | 12 Jul 10:51 2014
Picon

How do I make the :actual-type of a define-foreign-type a (:pointer (:struct ...))

 I have a define-foreign-type, translate-to-foreign, translate-from-foreign and a defclass at bottom of this page

  These four sections of code make up my types. At the top of the code is a defcstruct that, I am trying to make a part of my types  by changing the :actual-type in the define-foreign-type to:  

   (:actual-type '(:pointer (:struct rect1))).

The :actual-type is normally :pointer and that makes it so the defcfun at the bottom of code section compiles no problem.  When I compile the code here I get an error in my defcun saying that "(:pointer (:struct rect1)) is not a cffi type".  Why is it doing this and how can I make the actual type of my define-foreign-type a (:pointer (:struct rect1))?  The reason I would like to do this is so I can convert the C data to lisp data as soon as possible. If this won't work and you have any other suggestions on how to do this professionally. pls let me know. Thank you.


;;;;Code

(cffi:defcstruct rect1
(x :int)
(y :int)
(width :int)
(height :int))
 
 
(define-foreign-type rect ()
((garbage-collect :reader garbage-collect :initform nil :initarg
:garbage-collect))
(:actual-type '(:pointer (:struct rect1)))
(:simple-parser rect))
 
 
(defclass cv-rect ()
((c-pointer :reader c-pointer :initarg :c-pointer)))
 
 
(defmethod translate-to-foreign ((lisp-value cv-rect) (c-type rect))
(values (c-pointer lisp-value) lisp-value))
 
 
(defmethod translate-from-foreign (c-pointer (c-type rect))
(let ((rectangle (make-instance 'cv-rect :c-pointer c-pointer)))
(when (garbage-collect c-type)
(tg:finalize rectangle (lambda () (del-rect c-pointer))))
rectangle))
 
 
 
(defcfun ("cv_create_Rect4" rect-4) rect
"RECT constructor."
(x :int)
(y :int)
(width :int)
(height :int))

_______________________________________________
Cffi-devel mailing list
Cffi-devel <at> common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Gmane