[cffi-devel] %mem-{set,ref} can be inlined?

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun Apr 25 12:55:59 UTC 2010


I had a look at the definitions of these two functions. Right now in
cffi-ecl.lisp it seems that they are only called with basic types, for they
call cffi-type->ecl-type which only deals with things like integers,
doubles, etc.

Could I just produce a compiler macro that relies on this? The result would
be much much simpler than this as it could be inlined and make use of ECL's
embedded C statements.

Actually it would be nice if instead of a compiler macro I could define them
to be just plain macros. Anything that prevents it?

Juanjo

(defun %mem-ref (ptr type &optional (offset 0))
  "Dereference an object of TYPE at OFFSET bytes from PTR."
  (let* ((type (cffi-type->ecl-type type))
         (type-size (ffi:size-of-foreign-type type)))
    (si:foreign-data-ref-elt
     (si:foreign-data-recast ptr (+ offset type-size) :void) offset type)))

-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://tream.dreamhosters.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20100425/f3db6cd8/attachment.html>


More information about the cffi-devel mailing list