discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile for StepTalk


From: Stefan Urbanek
Subject: Re: Guile for StepTalk
Date: Mon, 21 Jan 2002 19:49:50 +0100

Hi,

Thank you for reply.

Richard Frith-Macdonald wrote:
> 
> On Sunday, January 13, 2002, at 12:28 PM, Stefan Urbanek wrote:
> 
> > Hi,
> >
> > I was trying to create Guile language bundle for StepTalk. But I am
> > getting
> > segfaults when initialising gnustep-guile.
> >
> > Backtrace is:
> >

--skip--

> 
> One flaw of guile is that you must call gh_enter(argc, argv,
> my_main_func) from
> main(), and the function 'my_main_func' is where you put all the stuff
> you usually
> have in main().
> 

Actually I cannot call gh_enter from main(). First thing is that mentioned
piece of code is located in bundle that is loaded only when someone wants to
execute script written in guile. Second thing is that it is not very good idea
to force anyone using steptalk to call gh_enter from main. 

Application writers does not have to know about languages used for scripting,
they just provide scriptable objects to scripting engine. 

> This is to do with stuff that guile does to keep track of stack info for
> garbage
> collection - I think the gh_enter() function tags its own stack location
> and the
> garbage collection works with everything beyond that point in the stack,
> so all
> the code using guile has to be executed within functions called from
> gh_enter().
> 
> Looking at the stacktrace, you haven't done this, so when
> gstep_init_id() tries
> to do it's stuff, it's working with an uninitionalised guile environment
> (which
> it has no way to initialise) - I guess this is what causes your crash.
> 

It seems so.

> I haven't kept track of guile development for many months, so the latest
> versions
> of guile may have fixed this problem (it used to be quite a common
> complaint on
> the guile mailing list), but I don't know - from the discussions I
> remember it
> seems this was a fairly basic flaw and would need quite a bit of work to
> fix.

I am trying to use this dirty trick:

- (id) executeScript:(NSString *)sourceCode 
       inEnvironment:(STEnvironment *)env
{
    char *args[3];

    args[0] = "dummy";
    args[1] = (char *)sourceCode;
    args[2] = (char *)env;

    /* FIXME: ugly trick */
    gh_enter(3, args, fake_guile_main);
}

and:

int fake_guile_main(int argc, char **argv)
{
    NSString      *sourceCode = (NSString *)argv[1];
    STEnvironment *env        = (STEnvironment *)argv[2];
    GuileInterpreter *interp;
    GuileScript      *script;
    GuileSCM         *result;
    NSEnumerator     *e;
    id               *obj;
    
    gstep_init();
//    gstep_link_base();

    [GuileInterpreter initializeInterpreter];

    interp = AUTORELEASE([[GuileInterpreter alloc] init]);
    script = AUTORELEASE([[GuileScript alloc] init]);

    e = [[[env defaultObjectPool] allKeys] objectEnumerator];

    /* FIXME: If we do not remove these, we get an exception */
    [env removeObjectWithName:@"NSProxy"];
    [env removeObjectWithName:@"NSDistantObject"];

    [script setUserDictionary:[env defaultObjectPool]];
    [script setDelegate:sourceCode];
    result = [interp executeScript:script];
        
    /* FIXME: ignore result */
    return 0;
}

-- END OF CODE --

It seems to work.

> 
> Of course, is this *is* your problem, the workaround is simply to alter
> your main()
> function to call gh_enter().
> 

See at the beginning.

Thanks for help.


Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]