[CM] Examples of printing out errors in S7?

Iain Duncan iainduncanlists at gmail.com
Tue Apr 14 08:39:44 PDT 2020


Thanks Bill, that seems to be all working so far. Thanks for the
explanation. I am having a weird occasional issue though, which has me
worried that I could have a nasty bug in how I've set things up. In max,
I've got it so that multiple s7 interpreters can be running, one in each
s4m.scm object. So far no issues on this approach. I've pasted my eval
helper below, adapted from the grepl.c example.

So yesterday, I had this weird thing happen where one instance of the
interpreter started logging a bizarre error message from this function,
that didn't seem to have any relevance to what it was doing, and it was
also still managing to execute code at the same time. It looked from the
outside like s7_eval_string was getting called twice, once with something
totally unexpected, and once with what I expect. I just wondered if there
are ever cases you've seen where s7_get_output_string  and
s7_current_error_port could be returning the wrong errors, or stale data of
some kind. I know this is all rather vague, but the behaviour has me
completely flumoxed. No worries if it's too vague to even comment on.

thanks
iain

// eval string  with error logging
void scm4max_s7_eval_string(t_scm4max *x, char *string_to_eval){
    //post("scm4max_s7_eval_string() %s", string_to_eval);
    int gc_loc;
    s7_pointer old_port, result;
    const char *errmsg = NULL;
    char *msg = NULL;
    old_port = s7_set_current_error_port(x->s7,
s7_open_output_string(x->s7));
    gc_loc = s7_gc_protect(x->s7, old_port);
    s7_pointer res = s7_eval_c_string(x->s7, string_to_eval);
    errmsg = s7_get_output_string(x->s7, s7_current_error_port(x->s7));
    if ((errmsg) && (*errmsg)){
        msg = (char *)calloc(strlen(errmsg) + 1, sizeof(char));
        strcpy(msg, errmsg);
    }
    s7_close_output_port(x->s7, s7_current_error_port(x->s7));
    s7_set_current_error_port(x->s7, old_port);
    s7_gc_unprotect_at(x->s7, gc_loc);
    if (msg){
        object_error(x, "s4m Error: %s", msg);
        free(msg);
    }else{
        scm4max_post_s7_res(x, res);
    }
}


On Sat, Apr 11, 2020 at 5:35 AM <bil at ccrma.stanford.edu> wrote:

> > What is the reason we need to do the gc_protect and later unprotect of
> > the old port?
>
> It looks like I never addressed that in s7.html.  There is a short
> explanation in s7.h under s7_gc_protect.  In s7, the GC can run
> at any time.  If you have stored a reference to an s7 object,
> and the GC might run during its lifetime, and its lifetime
> is not really short (there's a lag between the making of an object
> and its first possible GC), you need to protect it.  It will remain
> protected until you unprotect it, so to avoid an ever-growing heap,
> you need to unprotect it.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20200414/f1b447b9/attachment.html>


More information about the Cmdist mailing list