Hi,

as the subject states I encountered some problems while
trying to get a backtrace for a exception. I'm trying to embedd
guile into a C programm which should catch exceptions at
global scope and print usable error messages and backtraces.

After some searching I got to the code below which works fine
except for backtrace display.. (crashes with wrong-type-arg)

Any help on this is much appreciated, all samples and
documentation I found was targeted at guile 1.6.

======================================================================
#include <stdio.h>
#include <libguile.h>

void continue_init (void *data, int argc, char **argv);
SCM guile_catch_exception (SCM key, SCM args);

int
main (int argc, char **argv)
{
        if (argc < 2)
        {
                fprintf(stderr, "%s 'scheme expression'\n", argv[0]);
                return 1;
        }

        scm_boot_guile(argc, argv, 0);
        return 0;
}

void
continue_init (void *data, int argc, char **argv)
{
        /* NOTE: this is from a guile 1.6 solution but seems not to work */

        /* enable backtraces */
        SCM_DEVAL_P     = 1;
        SCM_BACKTRACE_P = 1;
        SCM_RECORD_POSITONS_P = 1;
        SCM_RESET_DEBUG_MODE;

        /* eval and exit */
        scm_internal_stack_catch(SCM_BOOL_T,
                                 (scm_t_catch_body)scm_c_eval_string,
                                 (void*)argv[1],
                                 (scm_t_catch_handler)guile_catch_exception,
                                 NULL);
}

SCM
guile_catch_exception (SCM key, SCM args)
{
        if (scm_ilength(args) >= 3)
        {
                SCM stack = scm_fluid_ref(
                            SCM_VARIABLE_REF(scm_the_last_stack_fluid_var));
                SCM subr  = SCM_CAR(args);
                SCM mesg  = SCM_CADR(args);
                SCM cargs = SCM_CADDR(args);
#if 1
                /* FIXME: still wrong-type-arg error.. */
                scm_display_backtrace(stack, scm_current_error_port(),
                                      SCM_UNDEFINED, SCM_UNDEFINED);
#endif
                scm_newline(scm_current_error_port());
                scm_display_error(stack, scm_current_error_port(),
                                  subr, mesg, cargs, SCM_EOL);

                return SCM_BOOL_F;
        }
        else
        {
                scm_puts("E991: uncaught throw.",scm_current_error_port());
        }
        return SCM_BOOL_T;

}

======================================================================

----------------------------------------------------------------------
BitSpinn.org  - Don't get twisted up!
----------------------------------------------------------------------