loading multiple modules in MacOS X

Robby Griffin rmg@terc.edu
Tue, 29 Oct 2002 14:50:08 -0500


--Apple-Mail-4--368249615
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

The dlsym() replacement for MacOS X doesn't use its "handle" parameter, 
so it has no hope of always finding the proper initModule function from 
among multiple modules. I noticed this when trying the graphics 
library, which loads two modules; the second one fails with unknown 
primitive references. The attached patch works on my MacOS X 10.2 
system, but I'm not sure how compatible this is with other dyld 
implementations.


--Apple-Mail-4--368249615
Content-Disposition: attachment;
	filename=dyld_patch.txt
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	x-unix-mode=0644;
	name="dyld_patch.txt"

diff -ur hugs98-Dec2001/src/machdep.c hugs98-Dec2001-patched/src/machdep.c
--- hugs98-Dec2001/src/machdep.c	Fri Dec 14 13:00:49 2001
+++ hugs98-Dec2001-patched/src/machdep.c	Tue Oct 29 12:17:35 2002
@@ -1751,10 +1751,9 @@
 void* dlsym( void* handle, char* symbol ) {
   void* addr;
 
-  if( NSIsSymbolNameDefined( symbol ) )
-    addr = NSAddressOfSymbol( NSLookupAndBindSymbol( symbol ) );
-  else
-    addr = NULL;
+  addr = NSLookupSymbolInModule( handle, symbol );
+  if( addr )
+    addr = NSAddressOfSymbol( addr );
   
   return addr;
 }

--Apple-Mail-4--368249615
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



	--Robby

--Apple-Mail-4--368249615--