Easy way of sending a message

Andreas Raab andreas.raab at gmx.de
Fri Feb 6 18:05:18 UTC 2004


> I seem to have gotten myself into a pickle

Yes, you have.

> and I was hoping someone had
> some bright suggestions for me. I need to send an arbitrary message to
> an arbitrary object in Squeak from within C. I have spent a lot of time
> reading the Interpreter and ObjectMemory code, but can not find a quick
> primitive to do this. Is there some mechanism for looking up method
> objects that does not have side effects on the VM state. Specifically I
> need the mechanism to implement call backs from C, and can not find a
> simple function for doing this lookup without side effects.

If you are really into implementing callbacks, check out the stuff I wrote
in:

http://lists.squeakfoundation.org/pipermail/squeak-dev/2004-February/073231.html

However, I would advise you to very carefully think about whether you really
*have* to have callbacks. In most cases you should be able to "get by" with
a varying number of workarounds. Depending on your concrete constraints
(which I have no idea about - it may be helpful to explain in more detail
what you are working on) you might be able to use one of the following
alternatives:

- if the message sent from C does not have to complete synchronously, you
can simply signal a semaphore. This is precisely what (for example) the
async I/O, network and similar primitives do. Then, a Squeak process can
pick up the request (such as the message name) via a primitive and run the
remaining stuff from within Squeak.

- if the above is not an option because you need the message to be processed
synchronously to return a result, consider running "all of your C code" in a
separate thread. This would allow you to utilize the same mechanism as the
above, except that now the C thread could block until the result has been
computed and is returned from Squeak (via an appropriate primitive which
releases the C thread).

In any case, you will have a hard time if you try to do all of this stuff
directly from C and I would advise strongly against the idea of "sending a
message from C". Try to combine both areas and have Squeak do what it does
best - dealing with messages and sending them.

Cheers,
  - Andreas




More information about the Squeak-dev mailing list