chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] "Dynamically Loading" non-entry-point code


From: felix
Subject: Re: [Chicken-users] "Dynamically Loading" non-entry-point code
Date: Tue, 22 Jun 2004 00:47:07 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Daniel B. Faken wrote:

I need to call it from C (because I want the library to basically load some of its own bindings), so I defined this in my "scmif" interface
layer (see below)

Do you see any problem with this? (I wasn't too sure what you meant by "it gets complicated") Will this work with arbitrarily nested layers of callback?

#>
static void *scmif_tmp_toplevel_fn = NULL;
static void _scmif_run_toplevel(C_word c, C_word self, C_word k)
{
  void (*fn)(C_word, C_word, C_word) = scmif_tmp_toplevel_fn;
  assert(fn);
  fn(2, C_SCHEME_UNDEFINED, k);
}
#<
(define (scmif-run-that-toplevel uname)
  (when debug-scmif?
    (mpi-print "Running toplevel for unit '" uname "'..") )
  ((##core#primitive "_scmif_run_toplevel")) )

#>
int scmif_run_this_toplevel(char *name, void (*fn)(C_word, C_word, C_word))
{
  char *err = NULL;

  assert(fn);

  scmif_init(0, NULL);

  scmif_tmp_toplevel_fn = fn;
  // this uses CHICKEN_is_running() & so is valid whether or not you're
  // in a callback..
  scmif_eval_stringf(&err, "(scmif-run-that-toplevel \"%s\")", name);
  scmif_tmp_toplevel_fn = NULL;

  if(err) {
fprintf(stderr, "WARNING: scmif_run_this_toplevel: executing toplevel for unit '%s': %s\n", name, err);
    fflush(stderr);
    return 0;
  }

  return 1;
}
<#


This could actually work, but I'm not totally sure.
Does it crash? ;-)


cheers,
felix




reply via email to

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