bryan d. o'connor | 1 Oct 2005 20:25
Favicon

cffi-uffi-compat, cl-gd, and openmcl

i'm trying to get cl-gd up and running on openmcl 1.0-rc1
(darwin32) using cffi-uffi-compat (cffi-luis branch).

some of the cl-gd tests crash my lisp, i think i've boiled
it down to this (hopefully valid) test case which does work
in uffi:

(def-struct a (x :int) (y :int))

(let ((array (allocate-foreign-object 'a 3)))
   (loop for i below 3
         do (setf (get-slot-value (deref-array array '(:array a) i)  
'a 'x) 1))
   (get-slot-value (deref-array array '(:array a) 2) 'a 'x))

the (setf ...) SIGSEGVs in %mem-set.

i see similar results with sbcl 0.9.5.2.

thanks,

       ...bryan
Luis Oliveira | 2 Oct 2005 14:50
Picon
Gravatar

Re: cffi-uffi-compat, cl-gd, and openmcl

bryan d.o'connor <bryan-lisp <at> lunch.org> writes:
> i'm trying to get cl-gd up and running on openmcl 1.0-rc1
> (darwin32) using cffi-uffi-compat (cffi-luis branch).
>
> some of the cl-gd tests crash my lisp, i think i've boiled
> it down to this (hopefully valid) test case which does work
> in uffi:

> (def-struct a (x :int) (y :int))
>
> (let ((array (allocate-foreign-object 'a 3)))
>    (loop for i below 3
>          do (setf (get-slot-value (deref-array array '(:array a) i)
>          a 'x) 1))
>    (get-slot-value (deref-array array '(:array a) 2) 'a 'x))
>
> the (setf ...) SIGSEGVs in %mem-set.
>
> i see similar results with sbcl 0.9.5.2.

Thanks for bug report and test case! This should be fixed now. Let me
know if something is still broken though. Changelog follows.

Sun Oct  2 13:24:16 WEST 2005  Luis Oliveira <loliveira <at> common-lisp.net>
  * pointer-eq and bug fixes

  - New CFFI-SYS primitive: POINTER-EQ. Implemented for all Lisps except
    ECL and GCL. Exported it from the CFFI package.
  - Added POINTER-EQ to the user manual.
  - Bug fix: dereferencing an aggregate type should return a pointer to
(Continue reading)

bryan d. o'connor | 3 Oct 2005 05:02
Favicon

Re: Re: cffi-uffi-compat, cl-gd, and openmcl

> Let me know if something is still broken though.

that fixed my problem, but now i have one more for you.

with structures containing arrays, get-slot-value with a
slot after the array seems to reference into the array.
i guess that it thinks that the array is actually a ptr
to an array and the offset is miscalculated.

i attached some test code.  again, this is on mac os x
and happens with both openmcl and sbcl.

you should be able to run it with:
   (require :cffi-uffi-compat)
   (load "test")
   (test-package:run-test)

it should return (values 1 2 <array> 4 5), but instead
(values 1 2 <array elt 0> <array elt 1> <array elt 2>)

thanks,

     ...bryan

Attachment (test.c): application/octet-stream, 461 bytes

Attachment (test.lisp): text/x-lisp-source, 743 bytes
(Continue reading)

Luis Oliveira | 3 Oct 2005 16:33
Picon
Gravatar

Re: cffi-uffi-compat, cl-gd, and openmcl

"bryan d. o'connor" <bryan-lisp <at> lunch.org> writes:

>> Let me know if something is still broken though.
>
> that fixed my problem, but now i have one more for you.
>
> with structures containing arrays, get-slot-value with a
> slot after the array seems to reference into the array.
> i guess that it thinks that the array is actually a ptr
> to an array and the offset is miscalculated.

Yeah, the :array type was not much more than a typedef for a
pointer.

This should be fixed now, but I didn't test other uses of the :array
type much (I just fixed the bug in a lecture, the professor is starting
to complain). Thanks for testing uffi-compat. Changelog follows.

Mon Oct  3 15:20:16 WEST 2005  Luis Oliveira <loliveira <at> common-lisp.net>
  * Fixed bug in uffi-compat, added new type.

  - make the uffi-array-type be aggregate. (hopefully this didn't break
    uses of this type in other situations)
  - add uffi's :struct-pointer type. (not well tested, but passes all
    tests from uffi's regression suite)

--

-- 
Luis Oliveira
luismbo ( <at> ) gmail (.) com
Equipa Portuguesa do Translation Project
(Continue reading)

Bruce Butterfield | 7 Oct 2005 00:14

usage question

Due to my pretty rusty C skills I have what I hope is a naive question.
I'm writing a cffi interface to the tidy lib which among other things 
has the following construct:

// in include file:
struct _TidyBuffer;
typedef struct _TidyBuffer TidyBuffer;
typedef void* TidyDoc;

// example caller:
TidyBuffer output = {0};
TidyDoc tdoc = tidyCreate();
...
tidySaveBuffer(tdoc, &output)
...

so, tidy allocates some memory from a pointer reference supplied by the 
client. How do I declare and pass this reference to the foreign function?
Luis Oliveira | 7 Oct 2005 02:41
Picon
Gravatar

Openmcl changes [was Re: cffi-openmcl.lisp 64-bit patches]

On 6/out/2005, at 19:59, Gary Byers wrote:
> The callback failures are OpenMCL bugs; the other failures should be
> addressed by this patch.<cffi-openmcl.diff>

Thanks! I pushed this patch to my darcs tree. Thanks also to Bryan 
O'Connor for testing OpenMCL and CFFI on a G5. Changelog follows.

Fri Oct  7 01:32:51 WEST 2005  Luis Oliveira <loliveira <at> common-lisp.net>
   * cffi-openmcl 64-bit patches

   - Port to openmcl darwin/ppc64, courtesy Gary Byers.

Thu Oct  6 01:13:47 WEST 2005  Luis Oliveira <loliveira <at> common-lisp.net>
   * 64-bit enhancements for OpenMCL

   - Use the :int instead of :signed-fullword, etc..

--

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
Luis Oliveira | 7 Oct 2005 03:00
Picon
Gravatar

Re: usage question

Bruce Butterfield <bruce <at> open-tek.com> writes:
> // in include file:
> struct _TidyBuffer;
> typedef struct _TidyBuffer TidyBuffer;
> typedef void* TidyDoc;
>
> // example caller:
> TidyBuffer output = {0};
> TidyDoc tdoc = tidyCreate();
> ...
> tidySaveBuffer(tdoc, &output)
> ...

This C code (you don't show the declarations for tidyCreate() and
tidySaveBuffer() though) translates to something like this:

(use-package :cffi)

(defcstruct tidy-buffer
  ...)

(defctype tidy-doc :pointer)  ; if you prefer...

(defcfun ("tidyCreate" tidy-create) :tidy-doc)

(defcfun ("tidySaveBuffer" tidy-save-buffer) :void ;;?
  (doc tidy-doc)
  (out tidy-buffer))

;; caller
(Continue reading)

Luis Oliveira | 7 Oct 2005 03:19
Picon
Gravatar

Re: usage question

Luis Oliveira <luismbo <at> gmail.com> writes:
> (defcfun ("tidyCreate" tidy-create) :tidy-doc)
                                     ^^^
Erm, that should be "tidy-doc".

--

-- 
Luis Oliveira
luismbo ( <at> ) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
Bruce Butterfield | 7 Oct 2005 19:33

Re: Re: usage question

Still having a problem and I think it's related to the allocation of the 
buffer. Here is C code that works fine:

(BTW, I'm running SBCL 0.9.5, cffi-luis-051002-1333, on Ubuntu Hoary/x86)

=================================
typedef struct
{
     unsigned char* bp;
     unsigned int size;
     unsigned int allocated;
     unsigned int next;
} TidyBuffer;

typedef void* TidyDoc;

TidyDoc tidyCreate(void);
int tidyParseString(TidyDoc tdoc, const char* str);
int tidySaveBuffer(TidyDoc tdoc, TidyBuffer* buf);

int main(int argc, char **argv )
{
   const char* input = "<title>Foo</title><p>Foo!";
   TidyBuffer output = {0};

   TidyDoc tdoc = tidyCreate();
   tidyParseString( tdoc, input );           // Parse the input
   tidySaveBuffer( tdoc, &output );          // Pretty Print

   printf( "\n%s\n", output.bp );
(Continue reading)

Andras Simon | 9 Oct 2005 11:54
Picon

minor UI inconsistency

I think it'd be better to have

with-foreign-object (var type &key (count 1)) &body body

or even

with-foreign-object (var type options) &body body

(where options are used as keyword arguments to foreign-alloc) or some
such instead of

with-foreign-object (var type &optional (count 1)) &body body

given that we have

foreign-alloc type &key initial-element initial-contents (count 1)

Unless I'm thoroughly confused and with-foreign-object does not
correspond to foreign-alloc (as with-open-file corresponds to open).

Andras

Gmane