fix? : stk dumping core when loading shared objects

From: Moises Lejter <mlm_at_cs.brown.edu>
Date: Mon, 6 Mar 1995 01:10:27 -0500

Several people had reported problems where stk would dump core on
attempting to load a shared object file. It had not happened to me
while using the base stk interpreter. However, as soon as I linked a
version of stk with additional code of my own, it happened to me, too.

It looks to me like Sun Solaris 2.3 does not like programs to invoke
dlopen(NULL,1) more than once. At any rate, that is what I changed in
dynload.c, and my extended interpreter now works as it should. I do
not believe my change will break anything, nor adversely interact with
anything - and it might even speed things up, since dlopen(NULL,1)
will only be invoked once.

My new version of stk's dynload.c's load_and_call function looks like
this (in part):


static void load_and_call(char *path, char *fct_name)
{
  static void *self_handle = NULL;
  void *handle;
  void (*init_fct)();
  SCM str;

  /* Test if fct_name is already defined in the core interpreter */
  if (self_handle == NULL)
      if ((self_handle = dlopen(NULL,1)) == NULL)
          err("Cannot open myself !!!", NIL);
  if ((init_fct = dlsym(self_handle, fct_name)) != NULL) {
    err("Module is already (statically) loaded", STk_makestring(path));
  }


and the patch to apply to the original 2.1.6 sources to get this
should be:


hookipa$ diff dynload.c.orig dynload.c
129a130
> static void *self_handle = NULL;
135,137c136,139
< if ((handle = dlopen(NULL, 1)) == NULL) err("Cannot open myself !!!", NIL);
< if ((init_fct = dlsym(handle, fct_name)) != NULL) {
< dlclose(handle);
---
>   if (self_handle == NULL) 
>       if ((self_handle = dlopen(NULL,1)) == NULL)
>         err("Cannot open myself !!!", NIL);
>   if ((init_fct = dlsym(self_handle, fct_name)) != NULL) {
140d141
<   else dlclose(handle);
No promises, other than the fact that my app is now running
properly... :-)  
Moises
-----------------------------------------------------------------------------
Internet/CSnet:   Moises_Lejter_at_brown.edu	BITNET:  mlm_at_browncs.BITNET
UUCP:    ...!uunet!cs.brown.edu!mlm		Phone:	 (401)863-7671
USmail:  Moises Lejter, Box 1910 Brown University, Providence RI 02912
Received on Mon Mar 06 1995 - 07:11:58 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST