[cffi-devel] Performance of CFFI:PARSE-TYPE

Luís Oliveira luismbo at gmail.com
Fri May 30 20:55:16 UTC 2008


On Fri, May 30, 2008 at 8:08 PM, Hans Hübner <hans at huebner.org> wrote:
> On Fri, May 30, 2008 at 7:27 PM, Luís Oliveira <luismbo at gmail.com> wrote:
>> Thanks to the optimization mentioned above (a compiler macro for
>> foreign-alloc), foreign-string-alloc calls PARSE-TYPE only at
>> compile-time.

Actually, PARSE-TYPE is only called when FOREIGN-STRING-ALLOC itself
is compiled. No type parsing occurs when FOREIGN-STRING-ALLOC is
called, either at compile-time or runtime. Assuming the FOREIGN-ALLOC
compiler macro kicks in, of course.


> This seems not to work on Clozure CL the way that it is expected.  I
> see a call to PARSE-TYPE for every invocation of FOREIGN-STRING-ALLOC.
> I will try to understand how the compiler macro is supposed to work in
> order to find out if what I see is a CCL bug and can be fixed by
> Clozure.  Any pointers helping with that would be appreciated.

CFFI> (trace parse-type)
NIL
CFFI> (ccl:compiler-macroexpand-1 '(foreign-alloc :char :count length))
0> Calling (PARSE-TYPE :CHAR)
<0 PARSE-TYPE returned #<FOREIGN-BUILT-IN-TYPE :CHAR>
(%FOREIGN-ALLOC (* LENGTH 1))
T

That is how the FOREIGN-ALLOC compiler macro gets rid of the
PARSE-TYPE call in FOREIGN-STRING-ALLOC. And it seems to work here.

CFFI> (foreign-string-alloc "foo")
#<A Foreign Pointer #x65BE80>
4
;; no call to PARSE-TYPE there

FWIW, I'm using "Version 1.2-r9017-trunk  (LinuxX8664)".

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/



More information about the cffi-devel mailing list