>>>>> "Luís" == Luís Oliveira <[EMAIL PROTECTED]> writes: Luís> [Hello Jan. Sorry for the late reply!] Jan Rychter Luís> <[EMAIL PROTECTED]> writes: >> As for me, a working callback-lambda under SBCL (and later ECL) >> would be a MAJOR win. Even more so if I could avoid memory leaks by >> being able to delete callbacks when they're no longer needed.
Luís> I can't seem to find the lambda-callback patch but, IIRC, we Luís> reached the conclusion that we could support this feature in a Luís> similar fashion to the way we support foreign-funcall and Luís> long-long on some Lisps. Luís> The first step to integrate this feature into CFFI is to have Luís> someone actually use it, maybe write some tests. I doubt the Luís> patch (wherever it is) bitrotted much; can you apply it and/or Luís> let me know where it is? Let us know if it works for you or if Luís> you need any help. Luis, Here's the patch as originally sent by James Bielman. It used to work for me, but I've had problems recently. I haven't had time to debug them extensively, but it seems that the lambda list for inverse-translate-objects has changed over time. I would be really interested in a working callback-lambda, at least on SBCL. Unfortunately, I'd also need a way to somehow free/delete unused callbacks later on, so as not to leak memory. --J.
New patches: [First cut at an implementation of CALLBACK-LAMBDA. James Bielman <[EMAIL PROTECTED]>**20060205220941 - Only supported so far on SBCL and CLISP. - There is no way yet to free the callback functions if this is needed. - Add the feature CFFI-FEATURES:NO-CALLBACK-LAMBDA if not supported. ] { hunk ./src/cffi-allegro.lisp 66 + cffi-features:no-callback-lambda hunk ./src/cffi-clisp.lisp 54 - #:%callback)) + #:%callback + #:%callback-lambda)) hunk ./src/cffi-clisp.lisp 304 +;;; Define an anonymous callback which may close over the lexical +;;; environment. Returns a pointer that may be passed to a foreign +;;; function. +(defmacro %callback-lambda (rettype arg-names arg-types &body body) + (let ((type (callback-type rettype arg-names arg-types))) + `(ffi:with-foreign-object (ptr 'ffi:c-pointer) + (setf (ffi:memory-as ptr ,type) + (lambda ,arg-names ,@body)) + (ffi:foreign-value ptr)))) + hunk ./src/cffi-cmucl.lisp 63 - '(;; OS/CPU features. + '(;; Backend mis-features. + cffi-features:no-callback-lambda + ;; OS/CPU features. hunk ./src/cffi-corman.lisp 65 + cffi-features:no-callback-lambda hunk ./src/cffi-ecl.lisp 63 + cffi-features:no-callback-lambda hunk ./src/cffi-lispworks.lisp 66 + cffi-features:no-callback-lambda hunk ./src/cffi-openmcl.lisp 63 - '(;; OS/CPU features. + '(;; Backend mis-features. + cffi-features:no-callback-lambda + ;; OS/CPU features. hunk ./src/cffi-sbcl.lisp 55 - #:%callback)) + #:%callback + #:%callback-lambda)) hunk ./src/cffi-sbcl.lisp 289 +;;; Define an anonymous callback which may close over the lexical +;;; environment. Returns a pointer that may be passed to a foreign +;;; function. +(defmacro %callback-lambda (rettype arg-names arg-types &body body) + `(alien-sap + (sb-alien::alien-lambda ,(convert-foreign-type rettype) + ,(mapcar (lambda (sym type) + (list sym (convert-foreign-type type))) + arg-names arg-types) + ,@body))) + hunk ./src/features.lisp 41 + #:no-callback-lambda hunk ./src/functions.lisp 214 + +;;; Define an anonymous callback which may close over its lexical +;;; environment. Returns a pointer which may be passed as a function +;;; pointer to foreign functions. There is currently no way to free +;;; the returned function (if necessary). +#-cffi-features:no-callback-lambda +(defmacro callback-lambda (return-type args &body body) + (let ((arg-names (mapcar #'car args)) + (arg-types (mapcar #'cadr args))) + `(%callback-lambda ,(canonicalize-foreign-type return-type) + ,arg-names ,(mapcar #'canonicalize-foreign-type arg-types) + (inverse-translate-objects ,arg-names ,arg-types ,return-type + ,@body)))) } Context: [TAG 0.9.0 James Bielman <[EMAIL PROTECTED]>**20060204082912] Patch bundle hash: 41e14a50446f547a9f3d2bd1f18c4cdebb9f20d3
_______________________________________________ cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel