[mcclim-devel] Re: Question about freetype translation to CFFI

Robert P. Goldman rpgoldman at real-time.com
Thu May 25 15:35:07 UTC 2006


Please disregard this query.  I see that I was clueless and apologize. 
I had forgotten my old C knowledge, and in particular, had forgotten 
that the desire to have multiple values, combined with call-by-value, 
means that one often must pass pointers to pointers as arguments, and 
then to get the pointer, one dereferences....

Never mind!

Cheers,
R


Robert P. Goldman wrote:
> I wonder if anyone who's familiar with SBCL aliens can give me some
> advice in my ongoing translation of the freetype code into CFFI.  IIUC
> (I quite possibly don't), a difference between the two is that SBCL
> has much more "understanding" of the foreign data structures, and that
> it is able to work directly with foreign structures.  CFFI works more
> with pointers, and requires more explicit reference to the foreign
> types when dereferencing.
> 
> I think I have mostly managed to translate the foreign data
> structures, and a good bit of the code.  However, I am still having
> some trouble understanding a bit of the SBCL alien code, particularly
> the use of derefs when returning foreign values.  For example, here's
> one of the original defuns:
> 
> (defun make-concrete-font (vague-font size &key (dpi *dpi*))
>   (with-slots (lib filename) vague-font
>     (let* ((key (cons lib filename))
>            (val (gethash key *concrete-font-hash*)))
>       (unless val
>         (let ((facef (make-alien freetype:face)))
>           (declare (type (alien (* freetype:face)) facef))
>           (if (zerop (freetype:new-face lib filename 0 facef))
>               (setf val (setf (gethash key *concrete-font-hash*)
>                               (deref facef)))
>               (error "Freetype error in make-concrete-font"))))
>       (let ((face val))
>         (declare (type (alien freetype:face) face))
>         (freetype:set-char-size face 0 (round (* size 64)) (round dpi) 
> (round dpi))
>         face))))
> 
> I'm not at all sure, moving to CFFI, how to translate the DEREF
> calls.  CFFI is essentially always working with pointers, IIUC, so I'm
> wondering if I should just eliminate deref calls like this (i.e., just
> set the hash table entry to facef)...
> 
> Any suggestions would be more than welcome.
> 
> 
> Thanks,
> R
> 
> 




More information about the mcclim-devel mailing list