From BConnoy at morrisonhershfield.com Tue Nov 1 16:17:42 2011 From: BConnoy at morrisonhershfield.com (Brian Connoy) Date: Tue, 1 Nov 2011 16:17:42 +0000 Subject: [rdnzl-devel] Generic Methods Message-ID: Hi list, Unfortunately I know too little about the underlying substrates here, to guarantee an intelligible question(!) Some years back, Iver Kvello developed a RDNZL patch for Generic Types (in the thread titled "Patch for generic types in RDZNL"). However in his offering he notes that Generic Methods are particularly problematic and are not covered by the patch. I seem to be stopped cold on this very point. There is a redistributable for Microsoft SharePoint (http://www.microsoft.com/download/en/details.aspx?id=21786) that I need to work with and RDNZL came to mind. There's just two Assemblies. My first exploration took me to the "ClientContext" class, where RDNZL will successfully call 'normal' properties and methods - excepting methods such as "Load". Iver suggested a workaround, which I'm naively fiddling with at the moment. Any of you experienced RDNZL'ers have sage advice to offer? Thanks in advance, Brian Connoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From iverodin at gmail.com Tue Nov 1 17:33:40 2011 From: iverodin at gmail.com (Iver Odin Kvello) Date: Tue, 1 Nov 2011 18:33:40 +0100 Subject: [rdnzl-devel] Generic Methods In-Reply-To: References: Message-ID: > Some years back, Iver Kvello developed a RDNZL patch for Generic Types (in > the thread titled ?Patch for generic types in RDZNL?). However in his > offering he notes that Generic Methods are particularly problematic and are > not covered by the patch. As I recall, the problem is that you cannot use GetMethod in the general case with overloaded methods and so forth - you actually have to iterate over the methods of the function, grabbing the generic types and try to find your (most specific match) the hard way. You get no help from the runtime here. In particuluar, if you want to find "what C# would have called" this is going to be hard. This is an old reference describing what one must do in the simple case (such as for Load): http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/10/invoking-generic-methods-with-reflection.aspx This even older describes the issue with GetMethod in the general case: http://blogs.msdn.com/b/yirutang/archive/2005/09/14/466280.aspx More of the same: http://stackoverflow.com/questions/5934432/how-to-getmethod-on-multiple-function-definitions-where-match-has-generic-para This last has a 'version' of GetMethod which is supposed to work: http://stackoverflow.com/questions/4035719/getmethod-for-generic-method For the simpler cases, you could use reflection directly from RDNZL to find the methods you need and invoke them; it's possible the last reference could be compiled into an assembly and used directly (I haven't tried.) Unfortunately, I haven't had the opportunity to work with RDNZL for quite some time, so I'm unable to provide further help. Regards, Iver From BConnoy at morrisonhershfield.com Tue Nov 1 18:28:23 2011 From: BConnoy at morrisonhershfield.com (Brian M Connoy) Date: Tue, 1 Nov 2011 18:28:23 +0000 (UTC) Subject: [rdnzl-devel] Generic Methods References: Message-ID: > > Unfortunately, I haven't had the opportunity to work with RDNZL for > quite some time, so I'm unable to provide further help. > > Regards, > Iver > No problem. Thanks very much for shedding more light on the subject. BC From idanman2002 at yahoo.com Thu Nov 10 17:22:18 2011 From: idanman2002 at yahoo.com (idan mandelbaum) Date: Thu, 10 Nov 2011 09:22:18 -0800 (PST) Subject: [rdnzl-devel] rdnzl for clozure cl Message-ID: <1320945738.28869.YahooMailNeo@web110311.mail.gq1.yahoo.com> I am trying to get rdnzl 0.13.3?to work on clozure cl 1.6 on a windows 7 32 bit machine. I am running it from the lisp in a box system. I've tried both with slime and w/o slime and I get the same problem. ? I modified port-sbcl.lisp and?added the appropriate #+:ccl in load.lisp. I included the content of the port-sbcl.lisp?file below (I know this makes it a long post but I hope its ok). I then tried to?run the?first example: ? CL-USER> (load "C:/Users/idan.mandelbaum/Desktop/lispbox-0.7/rdnzl-0.13.3/load.lisp") #P"C:/Users/idan.mandelbaum/Desktop/lispbox-0.7/rdnzl-0.13.3/load.lisp" CL-USER> (in-package rdnzl-user) # RDNZL-USER> (enable-rdnzl-syntax) ; No value RDNZL-USER> (import-types "System.Windows.Forms" "MessageBox" "MessageBoxButtons" "DialogResult") I get the following: ? Trying to call function RDNZL::%INVOKE-STATIC-MEMBER with NULL object #. ?? [Condition of type SIMPLE-ERROR] Restarts: ?0: [RETRY] Retry SLIME REPL evaluation request. ?1: [*ABORT] Return to SLIME's top level. ?2: [ABORT-BREAK] Reset this thread ?3: [ABORT] Kill this thread Backtrace: ? 0: (INVOKE "System.Reflection.Assembly" "LoadWithPartialName" "System.Windows.Forms") ????? Locals: ??????? RDNZL::OBJECT = "System.Reflection.Assembly" ??????? RDNZL::METHOD-NAME = "LoadWithPartialName" ??????? RDNZL::ARGS = ("System.Windows.Forms") ??????? #:OBJECT1390 = # ??????? #:POINTER1391 = # ? 1: (LOAD-ASSEMBLY "System.Windows.Forms") ????? Locals: ??????? RDNZL::NAME = "System.Windows.Forms" ? 2: (IMPORT-TYPES "System.Windows.Forms" "MessageBox" "MessageBoxButtons" "DialogResult") ? 3: (CCL::CALL-CHECK-REGS IMPORT-TYPES "System.Windows.Forms" "MessageBox" "MessageBoxButtons" "DialogResult") ? 4: (CCL::CHEAP-EVAL (IMPORT-TYPES "System.Windows.Forms" "MessageBox" "MessageBoxButtons" "DialogResult")) ? 5: (SWANK::EVAL-REGION "(import-types \"System.Windows.Forms\" \"MessageBox\" \"MessageBoxButtons\" \"DialogResult\")\n") ? 6: ((:INTERNAL SWANK::REPL-EVAL)) ? 7: (SWANK::TRACK-PACKAGE #) ? 8: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request." #) ? 9: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #) ?10: (SWANK::REPL-EVAL "(import-types \"System.Windows.Forms\" \"MessageBox\" \"MessageBoxButtons\" \"DialogResult\")\n") ?11: (CCL::CALL-CHECK-REGS SWANK:LISTENER-EVAL "(import-types \"System.Windows.Forms\" \"MessageBox\" \"MessageBoxButtons\" \"DialogResult\")\n") ?12: (CCL::CHEAP-EVAL (SWANK:LISTENER-EVAL "(import-types \"System.Windows.Forms\" \"MessageBox\" \"MessageBoxButtons\" \"DialogResult\")\n")) ?13: (SWANK:EVAL-FOR-EMACS (SWANK:LISTENER-EVAL "(import-types \"System.Windows.Forms\" \"MessageBox\" \"MessageBoxButtons\" \"DialogResult\")\n") "RDNZL-USER" 11) ?14: (SWANK::PROCESS-REQUESTS NIL) ?15: ((:INTERNAL SWANK::HANDLE-REQUESTS)) ?16: ((:INTERNAL SWANK::HANDLE-REQUESTS)) ?17: (SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK # #) ?18: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-OUTPUT* . #) (*STANDARD-INPUT* . #) ..))) # NIL) ?20: (CCL::RUN-PROCESS-INITIAL-FORM # (#)) ?21: ((:INTERNAL (CCL::%PROCESS-PRESET-INTERNAL (CCL:PROCESS))) # (#)) ?22: ((:INTERNAL CCL::THREAD-MAKE-STARTUP-FUNCTION)) ? ? ? I traced this to?a failure in [System.Reflection.Assembly.LoadWithPartialName name] called within load-addembly in the import.lisp file. Upon further tracing it seems like the error ocures becasue make-type-from-name may have a problem when called with "System.Reflection.Assembly". I think they might be something wrong with the way I am working with strings in the ffi-call-with-foreign-string* function below. Any thoughts/ideas? ? My modified port-sbcl.lisp file (called port-clozurecl.lisp) ;;; Clozure-specific definitions (in-package :rdnzl) ? (defconstant +ffi-pointer-size+ 4 "The size of a pointer in octets.") ? (defmacro ffi-register-module (path &optional (module-name path)) ? "Loads a C library designated by PATH." ? (declare (ignore module-name)) ? `(eval-when (:compile-toplevel :load-toplevel :execute) ???? (ccl:open-shared-library ,path))) ? (defun ffi-pointer-p (object) ? "Tests whether OBJECT is an FFI pointer." ? (typep object 'ccl:macptr)) ? (defun ffi-null-pointer-p (pointer) ? "Returns whether the FFI pointer POINTER is a null pointer." ? (ccl:%null-ptr-p pointer)) ? (defun ffi-pointer-address (pointer) ? "Returns the address of the FFI pointer POINTER." ? (ccl:%ptr-to-int pointer)) ;Defines void pointer to use in this package (ccl:def-foreign-type :voidpointer (:* T)) ? (defun ffi-map-type (type-name) ? "Maps type names like FFI-INTEGER to their corresponding names in the SBCL FFI." ? (ecase type-name ??? (ffi-void ':void) ??? (ffi-void-pointer '(:* T)) ??? (ffi-const-string ':address) ??? (ffi-integer ':signed-halfword) ??? (ffi-boolean ':unsigned-byte) ??? (ffi-wide-char ':unsigned-halfword) ??? (ffi-unsigned-short ':unsigned-halfword) ??? (ffi-float ':single-float) ??? (ffi-double ':double-float))) ? (defun flatten (structure) ? "Flatten only the first level of a list of arguments for use in ccl:ffi macros below" ? (cond ((null structure) nil) ?(t (append (first structure) (flatten (rest structure)))))) ? (defmacro ffi-define-function* ((lisp-name c-name) ??????????????????????????????? arg-list ??????????????????????????????? result-type) ? "Defines a Lisp function LISP-NAME which acts as an interface to the C function C-NAME.? ARG-LIST is a list of \(NAME TYPE) pairs.? All types are supposed to be symbols mappable by FFI-MAP-TYPE above." ? `(defun ,lisp-name ?????? ,(mapcar #'first arg-list) ???? (ccl:external-call ,c-name? ,@(flatten (mapcar (lambda (name-and-type) ????????? (destructuring-bind (name type) name-and-type ??????????? (list (ffi-map-type type) name))) ??????? arg-list)) ???,(when (ffi-map-type result-type) (ffi-map-type result-type))))) ? (defmacro ffi-define-callable ((c-name result-type) ?????????????????????????????? arg-list ?????????????????????????????? &body body) ? "Defines a Lisp function which can be called from C.? ARG-LIST is a list of \(NAME TYPE) pairs.? All types are supposed to be symbols mappable by FFI-MAP-TYPE above." ? `(ccl:defcallback ,c-name ?????? ( ,@(flatten (mapcar (lambda (name-and-type) ???????? (destructuring-bind (name type) name-and-type ????(list (ffi-map-type type) name))) ?????? arg-list)) ??? ,(when (ffi-map-type result-type) (ffi-map-type result-type)) ) , at body)) ? (defun ffi-make-pointer (name) ? "Returns an FFI pointer to the \(callback) address specified by the name NAME." (if (symbolp name) (symbol-value name) name)) ? (defun ffi-make-null-pointer () ? "Returns an FFI NULL pointer." ? (ccl:%null-ptr)) ? (defun ffi-alloc (size) ? "Allocates an `alien' of size SIZE octets and returns a pointer to it.? Must be freed with FFI-FREE afterwards." ? (#_malloc size)) ? (defun ffi-free (pointer) ? "Frees space that was allocated with FFI-ALLOC." ? (#_free pointer)) ? (defun ffi-convert-from-foreign-ucs-2-string (pointer size) ? "Converts the foreign UCS-2 string pointed to by POINTER of size SIZE octets to a Lisp string." ? (with-output-to-string (out) ??? (loop for i from 0 below size by 2 ????????? do (write-char (code-char ????????????????????????? (+ (ccl:%get-unsigned-byte pointer i) ???????????????????????????? (ash (ccl:%get-unsigned-byte pointer (1+ i)) 8))) ???????????????????????? out)))) ? (defmacro ffi-get-call-by-ref-string (function object length-function) ? "Calls the foreign function FUNCTION.? FUNCTION is supposed to call a C function f with the signature void f\(..., __wchar_t *s) where s is a result string which is returned by this macro. OBJECT is the first argument given to f.? Prior to calling f the length of the result string s is obtained by evaluating \(LENGTH-FUNCTION OBJECT)." ? (with-rebinding (object) ??? (with-unique-names (length temp) ????? `(let ((,length (* 2 (,length-function ,object))) ???????????? ,temp) ??????? (unwind-protect ??????????? (progn ????????????? (setq ,temp (ffi-alloc (+ 2 ,length))) ????????????? (,function ,object ,temp) ????????????? (ffi-convert-from-foreign-ucs-2-string ,temp ,length)) ????????? (when ,temp ??????????? (ffi-free ,temp))))))) ? (defmacro with-ucs-2-string ((var lisp-string) &body body) ? "Converts the Lisp string LISP-STRING to a foreign string using UCS-2 encoding and evaluates BODY with VAR bound to this foreign string." ? `(ccl:with-encoded-cstrs :ucs-2 ((,var ,lisp-string)) , at body)) ? (defmacro ffi-call-with-foreign-string* (function string &optional other-args) ? "Applies the foreign function FUNCTION to the string STRING and OTHER-ARGS.? OTHER-ARGS \(a list of CONTAINER structures or `native' Lisp objects) is converted to a foreign array prior to calling FUNCTION.? STRING may be NIL which means that this argument is skipped \(i.e. the macro actually needs a better name)." ? (with-rebinding (other-args) ??? (with-unique-names (length arg-pointers ffi-arg-pointers ??????????????????????? arg i arg-pointer foreign-string) ????? (declare (ignorable foreign-string)) ????? `(let* ((,length (length ,other-args)) ????????????? (,arg-pointers (make-array ,length :initial-element nil))) ???????? (unwind-protect ???????????? (let ((,ffi-arg-pointers ???????????????????? (loop for ,arg in ,other-args ?????????????????????????? for ,i from 0 ?????????????????????????? for ,arg-pointer = (cond ??????????????????????????????????????????????? ((container-p ,arg) (pointer ,arg)) ??????????????????????????????????????????????? (t (setf (aref ,arg-pointers ,i) ?????????????????????????????????????????????????????????? (box* ,arg)))) ?????????????????????????? collect ,arg-pointer))) ?????????????? ,(cond (string ?????????????????????? `(with-ucs-2-string (,foreign-string ,string) ? ???????????????????????? (apply #',function ,foreign-string ,ffi-arg-pointers))) ????????????????????? (t ?????????????????????? `(apply #',function ,ffi-arg-pointers)))) ?????????? ;; all .NET elements that were solely created (by BOX*) ?????????? ;; for this FFI call are immediately freed ?????????? (dotimes (,i ,length) ???????????? (named-when (,arg-pointer (aref ,arg-pointers ,i)) ?????????????? (%free-dot-net-container ,arg-pointer)))))))) ? (defmacro ffi-call-with-args* (function object name args) ? "Applies the foreign function FUNCTION to OBJECT and ARGS.? ARGS \(a list of CONTAINER structures or `native' Lisp objects) is converted to a foreign array prior to calling FUNCTION.? If NAME is not NIL, then it should be a string and the first argument to FUNCTION will be the corresponding foreign string." ? (with-rebinding (args) ??? (with-unique-names (length arg-pointers ffi-arg-pointers arg i j ??????????????????????? arg-pointer foreign-name) ????? (declare (ignorable foreign-name)) ????? `(let* ((,length (length ,args)) ????????????? (,arg-pointers (make-array ,length :initial-element nil)) ????????????? ,ffi-arg-pointers) ???????? (unwind-protect ???????????? (progn ?????????????? (setq ,ffi-arg-pointers ?????????????????????? (ffi-alloc ??????????????????????? (* ,length +ffi-pointer-size+))) ?????????????? (loop for ,arg in ,args ???????????????????? for ,i from 0 ???????????????????? for ,j from 0 by +ffi-pointer-size+ ???????????????????? for ,arg-pointer = (cond ????????????????????????????????????????? ((container-p ,arg) (pointer ,arg)) ????????????????????????????????????????? (t (setf (aref ,arg-pointers ,i) ???????????????????????????????????????????????????? (box* ,arg)))) ???????????????????? do (ccl:%setf-macptr (ccl:%get-ptr ,ffi-arg-pointers ,j) ??????????????????????????????? ,arg-pointer)) ?????????????? ,(cond (name ?????????????????????? `(with-ucs-2-string (,foreign-name ,name) ????????????????????????? (,function ,foreign-name ???????????????????????????????????? ,object ???????????????????????????????????? ,length ???????????????????????????????????? ,ffi-arg-pointers))) ????????????????????? (t `(,function ,object ???????????????????????????????????? ,length ???????????????????????????????????? ,ffi-arg-pointers)))) ?????????? (when ,ffi-arg-pointers ???????????? (ffi-free ,ffi-arg-pointers)) ?????????? ;; all .NET elements that were solely created (by BOX*) ?????????? ;; for this FFI call are immediately freed ?????????? (dotimes (,i ,length) ???????????? (named-when (,arg-pointer (aref ,arg-pointers ,i)) ?????????????? (%free-dot-net-container ,arg-pointer)))))))) ? (defmacro make-fun-for-finalization (object function) "Make function to call function for flag-for finalization since clozure cl only allows function ccl:terminate to be called" `(defmethod ccl:terminate ((x ,(type-of object))) (funcall ,function))) ? (defun flag-for-finalization (object &optional function) ? "Mark OBJECT such that FUNCTION is applied to OBJECT before OBJECT is removed by GC."? ? (ccl:terminate-when-unreachable object) ? (unless (null function) ??? (make-fun-for-finalization object function))) ? (defun register-exit-function (function &optional name) ? "Makes sure the function FUNCTION \(with no arguments) is called before the Lisp images exits." ? ;; don't know how to do that in SBCL ? (declare (ignore function name))) ? (defun full-gc () ? "Invokes a full garbage collection." ? (ccl:gc))?? From rwiker at gmail.com Fri Nov 11 13:24:41 2011 From: rwiker at gmail.com (Raymond Wiker) Date: Fri, 11 Nov 2011 14:24:41 +0100 Subject: [rdnzl-devel] rdnzl for clozure cl In-Reply-To: <1320945738.28869.YahooMailNeo@web110311.mail.gq1.yahoo.com> References: <1320945738.28869.YahooMailNeo@web110311.mail.gq1.yahoo.com> Message-ID: You might want to try a simpler example first: (rdnzl:load-assembly "System.Windows.Forms") --- this should give something like # If that doesn't work, you should try (ccl:open-shared-library "RDNZL.DLL") If that works, you need to look at rdnzl:invoke, and the functions called by rdnzl invoke. From BConnoy at morrisonhershfield.com Fri Nov 11 20:04:50 2011 From: BConnoy at morrisonhershfield.com (Brian Connoy) Date: Fri, 11 Nov 2011 20:04:50 +0000 Subject: [rdnzl-devel] LINQ Expressions? Message-ID: Hi list, I'm curious to know if any of you has had success/experience with constructing and passing LINQ expressions (http://en.wikipedia.org/wiki/LINQ) from RDNZL. I don't frankly know whether this is possible, so any examples would be most appreciated. Thanks, Brian Connoy -------------- next part -------------- An HTML attachment was scrubbed... URL: