This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: dlsym leading underscore fixed


> Cc: guile@cygnus.com
> Content-Type: text/plain; charset=US-ASCII
> From: Marius Vollmer <mvo@zagadka.ping.de>
> Date: 22 Nov 1997 17:33:33 +0100
> 
> Many thanks for fixing the underscore problem!  But of course, I have
> some nits to pick:
> 
> DLSYM_NEEDS_USCORE would be a better name, no?

I thought so, but I was sticking as closely as possible to hag's
original fix in SCSH, to reduce the likelihood of typos or other dumb
goofs.  Remember, DLSYM_NEEDS_USCORE is the opposite of
DLSYM_ADDS_USCORE, so all of the logic would have to be reversed.  The
name of the macro didn't seem to make much difference, so I didn't
change it.

> libguile/ChangeLog talks about DLSYM_ADDS_UNDERSCORE, which is a typo,
> I think.

Yes, it is -- thanks for pointing this out.  (As long as we're talking
about the name of the macro, I'd probably prefer something like
DLSYM_NEEDS_UNDERSCORE, which would even be more accurate.  But I
don't see a major reason for changing it.)

> sysdep_dynl_func now always copies the symbol string into fresh
> storage, even if no changes need to be done to it.  Is this necessary?
> 
> The symbol string memory is not freed when an error is thrown (due to
> unresolvable symbols, for example).

I've always been sloppy about memory leaks, so thanks for pointing
this out!  Here's the new sysdep_dynl_func, committed a few minutes
ago.

static void *
sysdep_dynl_func (symb, handle, subr)
     char *symb;
     void *handle;
     char *subr;
{
    void *fptr;
    char *err;
    char *usymb;

#ifdef DLSYM_ADDS_USCORE
    fptr = dlsym (handle, symb);
#else
    usymb = (char *) malloc (strlen (symb) + 2);
    *usymb = '_';
    strcpy (usymb + 1, symb);
    fptr = dlsym (handle, usymb);
    free (usymb);
#endif

    err = (char *)dlerror ();
    if (!fptr)
      {
	SCM_ALLOW_INTS;
	scm_misc_error (subr, err? err : "symbol has NULL address", SCM_EOL);
      }
    return fptr;
}