From iok at selvaag.no Wed Apr 25 07:33:39 2007 From: iok at selvaag.no (Iver Odin Kvello) Date: Wed, 25 Apr 2007 09:33:39 +0200 Subject: [rdnzl-devel] A question about CAST Message-ID: <554B9CBD8BD19349B0AB0361B42527A8356CC2@SELVAAGXCH01.selvaag.no> Hello, We've recently started using RDNZL for integration between an internal application written in ACL 7.0 and a CAD system using a .Net-based extension-layer in the latter; using .Net Remoting for communicating between the two systems. We've found that RDNZL works robustly, reliably and is very easy to use. Thank you very much for creating it. I have a question with regards to the action of the CAST operator: Currently, when CAST'ing from one .Net class to another, the type of the container is destructively updated; and there doesn't seem to be any way of copying a container so that a reference to the same object but with another type can be created. That is, I'd like to do something like (cast foo "SomeType")) (setq bar (copy-container foo)) (cast bar "SomeOtherType")) without the last operating also setting the type of FOO to SomeOtherType [1] Is there some idiom that would work like this that I've missed? If not, I guess the functionality would have to be added at the C++ level, which I haven't really looked at yet. Any pointers would be appreciated. Iver Odin Kvello iok at selvaag.no [1] The actual situation that came up was this: We have a remote object - actually a transparent proxy - of an interface-type WALL, and we need to get a reference to its lease. However, to to this we must cast the object to MarshalByRefObject, and if we use CAST to get this, it is impossible to CAST back to the original interface type. We did find a workaround: using System.Runtime.Remoting.RemotingServices.GetRealProxy, another copy of the transparent proxy is easily obtained, and that can be cast to a MBRO instead. But a copy/cast-operator would have been nicer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From edi at agharta.de Thu Apr 26 08:31:29 2007 From: edi at agharta.de (Edi Weitz) Date: Thu, 26 Apr 2007 10:31:29 +0200 Subject: [rdnzl-devel] A question about CAST In-Reply-To: <554B9CBD8BD19349B0AB0361B42527A8356CC2@SELVAAGXCH01.selvaag.no> (Iver Odin Kvello's message of "Wed, 25 Apr 2007 09:33:39 +0200") References: <554B9CBD8BD19349B0AB0361B42527A8356CC2@SELVAAGXCH01.selvaag.no> Message-ID: Hi, On Wed, 25 Apr 2007 09:33:39 +0200, "Iver Odin Kvello" wrote: > We've recently started using RDNZL for integration between an > internal application written in ACL 7.0 and a CAD system using a > .Net-based extension-layer in the latter; using .Net Remoting for > communicating between the two systems. We've found that RDNZL works > robustly, reliably and is very easy to use. Thank you very much for > creating it. Thanks, that's good to hear. > I have a question with regards to the action of the CAST operator: > Currently, when CAST'ing from one .Net class to another, the type of > the container is destructively updated; and there doesn't seem to be > any way of copying a container so that a reference to the same > object but with another type can be created. That is, I'd like to > do something like > > (cast foo "SomeType")) > (setq bar (copy-container foo)) > (cast bar "SomeOtherType")) > > without the last operating also setting the type of FOO to > SomeOtherType [1] > > Is there some idiom that would work like this that I've missed? I first have to admit that I myself am pretty busy with other stuff at the moment and that I haven't used RDNZL in earnest for quite some time, so bear with me if I'm talking nonsense... :) The answer IIRC is that what you want is currently not supported. > If not, I guess the functionality would have to be added at the C++ > level, which I haven't really looked at yet. Any pointers would be > appreciated. Yes, you'd have to do that at in the C++ code, i.e. create a "copy" operation in the DotNetContainer class which copies an existing container and returns (a pointer to) the copy. And export that operation so that you can use it from Lisp. And then make it available to Lisp via the FFI. I /think/ that shouldn't be too hard and shouldn't result in any GC problems. Of course, if you do that it'd be nice if you could send your modifications back to the list so I can include it in a future release: http://weitz.de/patches.html > The actual situation that came up was this: We have a remote object > - actually a transparent proxy - of an interface-type WALL, and we > need to get a reference to its lease. However, to to this we must > cast the object to MarshalByRefObject, and if we use CAST to get > this, it is impossible to CAST back to the original interface type. I'm probably too dense at the moment, but /why/ can't you just cast back? Cheers, Edi. From iok at selvaag.no Thu Apr 26 15:11:32 2007 From: iok at selvaag.no (Iver Odin Kvello) Date: Thu, 26 Apr 2007 17:11:32 +0200 Subject: [rdnzl-devel] A question about CAST In-Reply-To: References: <554B9CBD8BD19349B0AB0361B42527A8356CC2@SELVAAGXCH01.selvaag.no> Message-ID: > Yes, you'd have to do that at in the C++ code, i.e. create a "copy" > operation in the DotNetContainer class which copies an existing > container and returns (a pointer to) the copy. And export that > operation so that you can use it from Lisp. And then make it > available to Lisp via the FFI. I /think/ that shouldn't be too hard > and shouldn't result in any GC problems. Thank you, I'll have a look. Also: I just realised that there is a very simple additional workaround: One could just load in an assembly with a class with a static method public static Object Copy(Object o) { return o; } That worked too; but I've installed a C++ setup anyway to try to understand things better. > Of course, if you do that it'd be nice if you could send your > modifications back to the list so I can include it in a future > release We will. >> and if we use CAST to get this, it is impossible to CAST back to the >> original interface type. > I'm probably too dense at the moment, but /why/ can't you just cast > back? I don't really know why exactly, but the error given is Error: .NET error (System.InvalidCastException): Object must implement IConvertible. Regards, Iver Odin Kvello iok at selvaag.no From edi at agharta.de Thu Apr 26 15:24:32 2007 From: edi at agharta.de (Edi Weitz) Date: Thu, 26 Apr 2007 17:24:32 +0200 Subject: [rdnzl-devel] A question about CAST In-Reply-To: (Iver Odin Kvello's message of "Thu, 26 Apr 2007 17:11:32 +0200") References: <554B9CBD8BD19349B0AB0361B42527A8356CC2@SELVAAGXCH01.selvaag.no> Message-ID: On Thu, 26 Apr 2007 17:11:32 +0200, "Iver Odin Kvello" wrote: > I don't really know why exactly, but the error given is > > Error: .NET error (System.InvalidCastException): Object must > implement IConvertible. Strange. Does that only happen for certain objects or always if you try to cast something back and forth? Thanks, Edi. From iok at selvaag.no Thu Apr 26 15:43:29 2007 From: iok at selvaag.no (Iver Odin Kvello) Date: Thu, 26 Apr 2007 17:43:29 +0200 Subject: [rdnzl-devel] A question about CAST In-Reply-To: Message-ID: <554B9CBD8BD19349B0AB0361B42527A8356CC3@SELVAAGXCH01.selvaag.no> > Strange. Does that only happen for certain objects or always if you try to cast something back and forth? Only for certain objects, but I can reproduce it fairly easily: RDNZL-USER(5): (import-types "System" "Net.WebClient") NIL RDNZL-USER(6): (setf w (new "System.Net.WebClient")) # RDNZL-USER(7): (cast w "System.Object") Error: .NET error (System.InvalidCastException): Object must implement IConvertible. [condition type: RDNZL-ERROR] I didn't think of it as an issue; I just assumed it was some sort of .Net restriction. Iver Odin Kvello iok at selvaag.no From iok at selvaag.no Thu Apr 26 15:59:55 2007 From: iok at selvaag.no (Iver Odin Kvello) Date: Thu, 26 Apr 2007 17:59:55 +0200 Subject: [rdnzl-devel] A possible bugfix for a possible bug in IMPORT-ASSEMBLY Message-ID: <554B9CBD8BD19349B0AB0361B42527A8356CC4@SELVAAGXCH01.selvaag.no> I think there is a bug in IMPORT-ASSEMBLY, in that the documentation says "Imports all public types of the assembly ASSEMBLY \(a string or a CONTAINER). If ASSEMBLY is a string then the assembly is first loaded with LOAD-ASSEMBLY. Returns ASSEMBLY as a CONTAINER." However, it doesn't seem to actually import the public types when the ASSEMBLY argument isn't passed to IMPORT-TYPE. Passing the assembly fixes this. Iver Odin Kvello iok at selvaag.no -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: rdnzl-import.patch Type: application/octet-stream Size: 737 bytes Desc: rdnzl-import.patch URL: From edi at agharta.de Fri Apr 27 07:37:38 2007 From: edi at agharta.de (Edi Weitz) Date: Fri, 27 Apr 2007 09:37:38 +0200 Subject: [rdnzl-devel] A question about CAST In-Reply-To: <554B9CBD8BD19349B0AB0361B42527A8356CC3@SELVAAGXCH01.selvaag.no> (Iver Odin Kvello's message of "Thu, 26 Apr 2007 17:43:29 +0200") References: <554B9CBD8BD19349B0AB0361B42527A8356CC3@SELVAAGXCH01.selvaag.no> Message-ID: On Thu, 26 Apr 2007 17:43:29 +0200, "Iver Odin Kvello" wrote: > Only for certain objects, but I can reproduce it fairly easily: > > RDNZL-USER(5): (import-types "System" "Net.WebClient") > NIL > RDNZL-USER(6): (setf w (new "System.Net.WebClient")) > # > RDNZL-USER(7): (cast w "System.Object") > Error: .NET error (System.InvalidCastException): Object must implement > IConvertible. > [condition type: RDNZL-ERROR] > > I didn't think of it as an issue; I just assumed it was some sort of > .Net restriction. Yes, it is - I checked the .NET documentation. Thanks for the info. From edi at agharta.de Fri Apr 27 07:46:53 2007 From: edi at agharta.de (Edi Weitz) Date: Fri, 27 Apr 2007 09:46:53 +0200 Subject: New release 0.10.9 (Was: [rdnzl-devel] A possible bugfix for a possible bug in IMPORT-ASSEMBLY) In-Reply-To: <554B9CBD8BD19349B0AB0361B42527A8356CC4@SELVAAGXCH01.selvaag.no> (Iver Odin Kvello's message of "Thu, 26 Apr 2007 17:59:55 +0200") References: <554B9CBD8BD19349B0AB0361B42527A8356CC4@SELVAAGXCH01.selvaag.no> Message-ID: On Thu, 26 Apr 2007 17:59:55 +0200, "Iver Odin Kvello" wrote: > I think there is a bug in IMPORT-ASSEMBLY Yes, you're right, thanks. I've released a new version with your patch incorporated.