[Openmcl-devel] Three questions

Gary Byers gb at clozure.com
Fri Feb 8 15:24:43 PST 2008

On Fri, 8 Feb 2008, Ron Garret wrote:

> 1.  Is there a way to tell when a window has been closed?  Sometimes
> the window seems to turn into a bogus obj-C object, but sometimes it
> doesn't.  And even when it does, TYPE-OF still returns ns:ns-window:
> ? w
> #<Bogus ObjC Object #x14901E00>
> ? (type-of w)
> ?
> but doing anything else with the window (like asking for its
> contentView) crashes CCL.

? (defvar *o* (make-instance 'ns:ns-object))
? (#/retainCount *o*)
? (#/release *o*)
? *o*
#<Bogus ObjC Object #x12CE7730>

ObjC objects aren't real, first-class lisp objects after all (because
it's possible for them to be "deallocated" when their (ObjC) reference
counts become 0.

My usual argument is that while this is bad (and it'd be good to
integrate the lisp and ObjC GCs so that this kind of thing can't
happen), it' not as bad in practice as it is in theory (because
many of the objects that one deals with from the lisp side of
things are relatively long-lived (windows, views) and it's rare
to hold lisp references to those things.  At least the first
part of that is likely true.)

> 2.  Why doesn't this work:
> (objc:load-framework "Webkit" :webkit)
> (setf w (make-window 500 300))
> (setf v (make-instance 'ns:web-view))
> (#/setContentView: w v)
> (setf f (#/mainFrame v))
> (#/loadRequest: f
>   (#/requestWithURL: ns:ns-url-request
>     (#/URLWithString: ns:ns-url #@"http://www.google.com/")))

In what thread does it not work (e.g., how is this code different
from the webkit example ?

> It doesn't generate any errors, but it also doesn't display anything.

It also doesn't have any opportunity to process the URL request.
That processing ordinarily happens in a thread's "run loop", which
is something like an event loop (although the term "run loop" and
the class NSRunLoop often are used to describe an object that
provides an interface to some code that presumably executes some
kind of loop to detect input from various sources.)

Every thread (including a listener, if this code was just typed
in to a listener) has a "run loop".  A listener thread doesn't usually
have any reason to execute its run loop; the main event thread doesn't
do much else but repeatedly execute its run loop.

If we had typed your example into a listener and then told the
listener to execute its run loop for 25 seconds - via:

? (#/runUntilDate: (#/currentRunLoop ns:ns-run-loop)
                    (#/dateWithTimeIntervalSinceNow: ns:ns-date 25.0d0))

we should see:

a) the Google home page.
b) that 25 seconds was probably way to long.

I'd conclude from this that unless you really want to manage some
other thread's run loop, it's best to do things that require 
a run loop to manage asynchronous input in the main thread.

> 3.  When is openmcl-devel going to change its name to ccl-devel?  :-)
> Thanks,
> rg
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list