[Openmcl-devel] a problem with the callback stack

Gary Byers gb at clozure.com
Sun Jan 16 19:49:08 UTC 2005

Somehow or other, I missed the original message (it does seem to have
been archived.)

A C (or ObjC) function that "returns a structure" (an NSSize in this
case) does so by accepting a first argument that's a pointer to an
instance of that structure type.  The caller has to be aware of this,
and ObjC messages have to be sent using different primitives
(#_objc_msgSend_stret instead of #_objc_msgSend, for instance.)

The extra argument is implicit in C, and a C compiler will turn:

   return NSMakeSize(1.0,2.0);

into something like:

   magic_extra_argument->width = 1.0;
   magic_extra_argument->height = 2.0;

DEFINE-OBJC-METHOD needs a little help to recognize this case, and
the extra first argument needs to be made explicit.  The somewhat
crufty syntax is:

(define-objc-method (((:STRUCT :<NSS>ize magic-arg)
                       :window-will-resize (:id window)
                                :to-size (:<NSS>ize size))
    (let* ((width (compute-width ...))
           (height (compute-height ...)))
      (setf (pref magic-arg :<NSS>ize.width) width
            (pref magic-arg :<NSS>ize.height) height)))

It doesn't really matter what the method "returns" in the lisp sense;
it does matter that it have the side-effect of setting values in the
magic struct-return argument.

DEFINE-OBJC-METHOD should probably complain if the return type is
composite (a structure, union, array ..) and you don't use the
(:struct <type> explicit-name-for-magic-arg) syntax.

On Sun, 16 Jan 2005, alex crain wrote:

> On Jan 16, 2005, at 1:55 AM, alex crain wrote:
> >
> > CALLING -[HemlockWindowController windowWillResize:toSize:]
> > SELF = [:ID] #<A Mac Pointer #xBFFFE550>
> > _CMD = [:<SEL>] #<HEMLOCK-WINDOW-CONTROLLER <HemlockWindowController:
> > 0x853495a0> (#x853495A0)>
> > WINDOW = [:DOUBLE-FLOAT] -5.351074039314703D-229
> > SIZE = [:<NSS>size width=601.0 height=423.0]
> >
> This probably looks a bit confusing because I cut the wrong piece of
> text.  I was playing around with the
> declaration to make sure that I hadn't shifted the argument labels
> myself, and the WINDOW
> argument is incorrectly typed as :DOUBLE-FLOAT. Here's a correct
> tracing of the call
> CALLING -[HemlockWindowController windowWillResize:toSize:]
>    SELF = [:ID] #<A Mac Pointer #xBFFFE550>

There's the magic arg ...

>    _CMD = [:<SEL>] #<HEMLOCK-WINDOW-CONTROLLER <HemlockWindowController:

and there's SELF

> 0x8530f2e0> (#x8530F2E0)>
>    WINDOW = [:ID] #<A Mac Pointer #x9089F61C>

and _CMD (the selector)

>    SIZE = [:<NSS>size width=-8.316439E-36 height=600.0]

and that's the window object, interpreted as a pointer to an NSSize ...

> -[HemlockWindowController windowWillResize:toSize:] returned [:#<A Mac
> Pointer #xBFFFE4B4>] <NSS>IZE
> With the correct argument declarations, the size argument is now
> shifted back 4 bytes (because WINDOW is really 4 bytes, not 8)
> and is now wrong. SELF, _CMD and WINDOW are, of course, sitll bogus as
> well.
> Ideas?

Hope this makes sense.

> :alex
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list