Sending messages to SC during external run

External developers... This forum's for you!

Sending messages to SC during external run

Postby Dave_Higgins » Sat Aug 28, 2010 3:24 am

So I was poking around through the various IT header files just to see what was in there and came across something that has me wondering:

While an XFcn or XCmd is running, if you utilize any of SendCardMessage, SendHCMessage, or EvalExpr, what is the flow of operation?

Does the external pause, handing processing time back to SC temporarily (I would guess until SC would be ready to idle if not running the external)? It sorta looks this way as I came across the following comments:
Code: Select all
/*
 * —————————————————————————————————————————————————————————————————————————
 *   SetMsgResultStr
 *
 *   Set the text displayed in result area of msg box. Note that this call
 *   does not actually open the msg box, which if required is easily done
 *   using a text callback: SendCardMessage(par, "\pshow msg");
 * —————————————————————————————————————————————————————————————————————————
 */

The impression I get is that the external will pause until SC finishes handling the SendCardMessage, and then resume at that point. Is that right?
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: Sending messages to SC during external run

Postby codegreen » Sat Aug 28, 2010 4:06 am

Yes.

-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: Sending messages to SC during external run

Postby Dave_Higgins » Sat Aug 28, 2010 6:59 pm

mark wrote:Yes.

Ok. Now... While I don't have a specific reason in mind, and it might sound a bit silly to ask, but if one external needs to gather info that can be provided by another external (maybe one I write would like to speak to or drive one that someone else wrote, so I can't just incorporate their code without re-inventing a wheel), is it feasible to call on one this way (send a card message to run another X), or is there a mechanism in place that I just haven't read about yet that allows one external to directly call another, or am I just playing with fire thinking that this even sounds like something that could or should be done?
shoot_me
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: Sending messages to SC during external run

Postby codegreen » Sun Aug 29, 2010 5:56 am

Dave Higgins wrote:While I don't have a specific reason in mind, and it might sound a bit silly to ask, but if one external needs to gather info that can be provided by another external (maybe one I write would like to speak to or drive one that someone else wrote, so I can't just incorporate their code without re-inventing a wheel), is it feasible to call on one this way (send a card message to run another X), or is there a mechanism in place that I just haven't read about yet that allows one external to directly call another, or am I just playing with fire thinking that this even sounds like something that could or should be done?

The XCMD loading code should be re-enterable. It wasn't until SC4, and to be honest I'm not sure I've tested that since the universal binary port, but it's supposed to work. If not, file a bug and I'll fix it.

As for calling one external directly from another, well there's nothing to stop you from doing that either if you're crafty enough; however it's not trivial -- especially since NSCreateObjectFileImageFromMemory is broken in 10.4 and doesn't correctly handle fat Mach-O executables, so you'll have to parse the resource yourself and locate/link the appropriate main symbol for the current architecture, and you have to use vm_allocate (instead of normal application-level allocation APIs) for the memory you load it into because NSDestroyObjectFileImage will use vm_deallocate to dispose of the buffer when it's unloaded. And if you're running under PPC and calling an old CFM external, you'll first have to whuff up an assembly language Mach-O header to wrap around it on-the-fly and call MakeDataExecutable on it.

So assuming I didn't break it in the UB port, using a text callback will be much simpler...

-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: Sending messages to SC during external run

Postby Dave_Higgins » Sun Aug 29, 2010 8:09 am

mark wrote:As for calling one external directly from another, well there's nothing to stop you from doing that either if you're crafty enough; however it's not trivial -- especially since ...... you'll first have to whuff up an assembly language Mach-O header to wrap around it on-the-fly and call MakeDataExecutable on it.

      :o  !!!       :rofl:          Assemble what???   Yeeeeah. Right.

mark wrote:The XCMD loading code should be re-enterable. It wasn't until SC4, and to be honest I'm not sure I've tested that since the universal binary port, but it's supposed to work. If not, file a bug and I'll fix it....
So assuming I didn't break it in the UB port, using a text callback will be much simpler...

Well, a quick test seems to work with calling dir() by way of evaluate, so I guess it survived the transition.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron