From edi at agharta.de Fri Jan 13 07:37:30 2006 From: edi at agharta.de (Edi Weitz) Date: Fri, 13 Jan 2006 08:37:30 +0100 Subject: [rdnzl-announce] New versions 0.8.0/0.5.0 (was: bug in delegate adapter release mechanism) In-Reply-To: <1137112148.7503.251742658@webmail.messagingengine.com> (lisp@spikeisland.com's message of "Fri, 13 Jan 2006 00:29:08 +0000") References: <1137112148.7503.251742658@webmail.messagingengine.com> Message-ID: Hi Dominic! On Fri, 13 Jan 2006 00:29:08 +0000, "lisp" wrote: > I've tracked down what looks to be a bug in the mechanism for > releasing delegate adapters. > > The foreign callable ReleaseDelegateAdapter is declared with a > return type of ffi-void-pointer but tries to return the result of > remhash - a boolean. On LWW (at least) this results in: > > Condition: T cannot be converted to foreign type :POINTER. Call to > SYSTEM::FOREIGN-CALLABLE-ENTRY-POINT-NEW-PROCESS-AUX (offset 21) > SYSTEM::FUNC : RDNZL::%FOREIGN-CALLABLE/RELEASEDELEGATEADAPTER > > I would suggest changing it (and the corresponding initialisation > and DLL code) to have a void return type: > > (ffi-define-callable (ReleaseDelegateAdapter ffi-void) > ((index ffi-integer)) ;; remove entry from hash table if CLR is done with it > (remhash index *callback-hash*)) > > Also, in DelegateAdapter.cpp you have a comment on the destructor > that it doesn't appear to be working: > > // the destructor notifies Lisp that this instance is no longer used - > // at least in theory, this doesn't seem to work right now > DelegateAdapter::~DelegateAdapter() { release(indexIntoLisp); } > > This may have beeen the caused by the callback/threading issues > discussed recently. At least it has certainly worked for me here > (hence this bug report) when using a DLL based LWW image (many > thanks for your recent example of this). Perhaps the .NET GC is > running in a different thread, so the callback was failing in a > normal .EXE image? Makes perfect sense to me. I've updated both the Lisp and the C++ code according to your recommendations - see ChangeLogs below. However, I'm a bit in a hurry and I couldn't figure out an easy example which shows that ReleaseDelegateAdapter is actually called - at least not from a DLL-based LWW image. Could you please check if it works and report back to the list if possible? Thanks a lot, Edi. Lisp code: ---------- Version 0.8.0 2006-01-13 Fix mechanism which releases delegate adapters (thanks to Dominic Robinson) Updated to DLL version 0.5.0 C++ code (optional): -------------------- Version 0.5.0 2006-01-13 Fix mechanism which releases delegate adapters (thanks to Dominic Robinson) From edi at agharta.de Mon Jan 16 01:50:16 2006 From: edi at agharta.de (Edi Weitz) Date: Mon, 16 Jan 2006 02:50:16 +0100 Subject: [rdnzl-announce] Re: New versions 0.8.0/0.5.0 In-Reply-To: <1137373139.2451.251914884@webmail.messagingengine.com> (lisp@spikeisland.com's message of "Mon, 16 Jan 2006 00:58:59 +0000") References: <1137112148.7503.251742658@webmail.messagingengine.com> <1137373139.2451.251914884@webmail.messagingengine.com> Message-ID: On Mon, 16 Jan 2006 00:58:59 +0000, "lisp" wrote: > I am happy to report that this works! Great! > If you run the function gc-test below in a LWW DLL image, you can > see the delegate adapter for the Click event being reclaimed and > releasing the closure from the callback hash table. > > If you open a process browser window *before* running this, you will > see the process created by LWW to handle the callback from .NET's gc > thread. Inspecting this process's arguments reveals > (rdnzl:%foreign-callable/releasedelegateadapter). This process is > used for all subsequent callbacks from the gc thread. If you kill > it, a new one will be created for the next gc callback. > > If you run this code in a conventional .exe LWW image you do not get > the callback from .NET's gc thread. Thanks for the detailed info. I'll try this tomorrow. > I have run into a further problem - with LWW this time I think. As > far as I can tell, LWW will occasionally run a foreign callback on > the wrong thread resulting in a stack overflow exception condition > being raised. With a form running in a new process and generating > event callbacks, the listener process occasionally reports a stack > overflow and shows the callback happening in *its* backtrace - > presumably confusing the stack check. I've not yet been able to > verify this or reproduce it reliably. > > Any thoughts or suggestions would be welcome... No idea. But it would be /very/ helpful if you could reproduce this and submit a bug report to LispWorks support. As you'll know they're currently working on the 5.0 release which will have some changes in the threading code as well. It'd be nice if they could fix that before they release the new version. Thanks again, Edi.