[racket] atexit_closer in an extension

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue Jun 29 11:23:33 EDT 2010


I'm having some difficulty with a Racket extension (again! -- I owe so many folk so much beer!).

I have a script

#lang racket
(require "src/build/librdf-extn.rkt") ; wraps the librdf library
(printf "Hello~%")

Nothing exotic there.  However:

% racket --require try.rkt                       
% racket --require try.rkt >try.out; cat try.out

That is, stdout appears to get eaten when it's redirected to a file.

I've stripped the initialisation function down to:

Scheme_Object *scheme_initialize(Scheme_Env *env) {
    Scheme_Env *menv = scheme_primitive_module(scheme_intern_symbol(MODULE_NAME), env);
    MZ_GC_VAR_IN_REG(0, env);
    MZ_GC_VAR_IN_REG(1, menv);
    if (! initialised) {
        initialised = 1;
    return scheme_void;

If I include the scheme_add_atexit_closer, I get this problem; if I don't, I don't.

mzrdf_exit_closer isn't exotic:

void mzrdf_exit_closer(Scheme_Object* o, Scheme_Close_Custodian_Client* f, void* d) 
    if (f != NULL)
        f(o, d);

Nor are the custodians in question, for example:

    void mzrdf_world_custodian(Scheme_Object *o, void* data) {
        librdf_world *world;
        if (! (is_world_p(o))) { scheme_signal_error("librdf assertion [is_world
_p(o)] failed in %s: world_custodian not given a world object; given %V instead"
, __func__, o); }
        fprintf(stderr, "world custodian for %p (data=%s)\n", world, (data == NULL ? "--NULL--" : (char*)data));
        world = (librdf_world *)SCHEME_CPTR_VAL(o);
        if (world != NULL) librdf_free_world(world);

(they're just there to call the librdf_free_world function and its friends).

Since no librdf functions are called, the custodian isn't ever called (and those fprintfs verify that).  It therefore appears that the mere presence of the atexit_closer is enough.

Which confuses me.

What is it I'm doing that's so terribly wrong?  Googling for "racket atexit closer" or "+plt +atexit +closer" doesn't throw up anything clearly relevant.  It's almost as if I'm stomping on some other atexit closer, though I can't see any hint of that sort of problem in the Custodians chapter, the function name talks about _adding_ a closer rather than installing one, and it has a void return value, so that it's not as if it returns a previous one.

Thanks for any advice.  Best wishes,


Norman Gray  :  http://nxg.me.uk

Posted on the users mailing list.