guile-user
[Top][All Lists]
Advanced

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

Re: Help needed debugging segfault with Guile 1.8.7


From: Linas Vepstas
Subject: Re: Help needed debugging segfault with Guile 1.8.7
Date: Sun, 28 Nov 2010 11:21:30 -0600

On 28 November 2010 05:38, Neil Jerram <address@hidden> wrote:

> Peter Brett <address@hidden> writes:
>
>> Sure.  libgeda uses direct management of memory, and the structures used
>> in its document object model need to be explicitly deleted when finished
>> with.  I decided to use a Guile smob to represent these structures for
>> access from Scheme code, with the pointer to the actual structure in
>> SCM_SMOB_DATA and with the low nibble of SCM_SMOB_FLAGS indicating which
>> type of DOM structure the smob references.
>>
>> This would have been sufficient if Scheme code had only been working
>> with libgeda DOMs created and managed entirely via Scheme code. [...]
>
> I think your design is similar to what is outlined in the `Extending
> Dia' node of the Guile manual.  Were you aware of that doc before
> working out your design?  If not, I guess we need to make it more
> prominent.  If yes, I'd appreciate any suggestions you have for how it
> may be improved.

Yes, I code almost entirely 'by example', so having a good cookbook is
critical for me. I haven't read 'Extending Dia' before, its probably more
recent than the last time I set up guile bindings, some 2-3 years ago;
I skimmed it briefly just now.

Several comments on example code:
1) its typically not possible to wrap the C main(), so having a well-defined
init() that happens some time later would be best.

2) http://www.gnu.org/software/guile/manual/html_node/Dia-Hook.html
is lame.  What I have to do is this:

   SCM rc = scm_c_catch (SCM_BOOL_T,
                         (scm_t_catch_body) scm_c_eval_string,
                         (void *) expr_str,
                         SchemeEval::catch_handler_wrapper, this,
                         SchemeEval::preunwind_handler_wrapper, this);

and my catch_handler and preunwind_handler are fairly involved.

Basically, if you are going to let users enter arbitrary scheme into
your app, they *will* enter malformed, broken expressions, and you
have to deal with these.  Among other things, you have to give them
a clue as to what the error was -- some sort of trace, error reporting.

For me, this was implementing a REPL loop look-alike in my app.
I can't say "work-alike", I think mine *almost* works-alike, but not sure.

It took me a *long* time to figure out I needed the pre-unwind version
of things, and even then, it took me a fair amount of effort to figure
out what to put in there.

Having a section showing how to implement a repl-work-alike loop
in one's app, with reasonable debugging/stack-printing output,
would be nice to have.  Figuring out how to do this one one's
own requires a lot of tenacity.

For the record, I've attched the code I wrote to do the above (and
to multi-thread, which someone later on disabled :-( Its in C++,
sorry about that, don't blame me.)

--linas

Attachment: SchemeEval.h
Description: Text Data

Attachment: SchemeExec.cc
Description: Text Data


reply via email to

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