Subject: dlopen patch [was Re: dlopen]
From: [email-masked] (Gary V. Vaughan)

11 Nov 1998 18:39:04 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------3CCD973B6A887E0AB8B4B2DB"
To: Geoffrey Noer <[email-masked]>
Cc: Jorrit Tyberghein <[email-masked]>,
        [email-masked], Christian Jullien <[email-masked]>

This is a multi-part message in MIME format.
--------------3CCD973B6A887E0AB8B4B2DB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Geoffrey Noer wrote:
>
> On Fri, Oct 30, 1998 at 12:19:55PM +0000, Gary V. Vaughan wrote:
> >
> > Geoffrey, I notice that the dlopen emulation doesn't handle a NULL
> > argument as per the POSIX spec (i.e. return an introspective handle
> > to the current process), yet the win32 GetModuleHandle does... will
> > this be fixed for b20?  Too late for a patch?
>
> Yep, much too late.  I will gladly take a patch after b20 is out
> however...

Better late than never?  Diffs attached.  Interestingly, this doesn't
seem to fix my particular problem -- but unless there is funkiness with
casting from HMODULE (dlopen) to void* (dlsym) to HINSTANCE
(GetProcAddress), then by inspection it really ought to work, according
to the Borland Win32 API docs.

I guess my implementation is awry somehow.

Cheers,
	Gary V. Vaughan
--------------3CCD973B6A887E0AB8B4B2DB
Content-Type: text/plain; charset=us-ascii;
 name="dlopen-gvv-19981110"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="dlopen-gvv-19981110"

--- dlfcn.cc.orig	Tue Nov 10 11:58:45 1998
+++ dlfcn.cc	Tue Nov 10 12:07:11 1998
@@ -127,9 +127,21 @@ get_full_path_of_dll (const char* str)
 void *
 dlopen (const char *name, int)
 {
-  const char *fullpath = get_full_path_of_dll (name);
-  DllList::the().currentDlOpenedLib (fullpath);
-  void *ret = (void *) LoadLibrary (fullpath);
+  void *ret = 0;
+
+  if (!name)
+    {
+      // handle for the current module
+      ret = (void *) GetModuleHandle (0);
+    }
+  else
+    {
+      // handle for the named library
+      const char *fullpath = get_full_path_of_dll (name);
+      DllList::the().currentDlOpenedLib (fullpath);
+      ret = (void *) LoadLibrary (fullpath);
+    }
+
   if (!ret)
     set_dl_error ("dlopen");
   debug_printf ("ret %p", ret);

--------------3CCD973B6A887E0AB8B4B2DB--

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".