[BUG][FIX][VM] Internal FFI calls

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Thu Jul 6 22:18:18 UTC 2000


On Wed, 5 Jul 2000, Jecel Assumpcao Jr wrote:

> My impression is that FFI is for calling functions in external
> libraries. Can it also be used for stuff like this that is in that
> standard library?

Yes. If you don't supply a module name the function gets looked up in the
executable itself, which includes the standard lib. For the system() call,
that would be:

system: aString
	<cdecl: long 'system' (char *)>
	^ExternalFunction externalCallFailed

Now, the recent external primitive rework has broken this. To look up an
internal function, the program module itself must be loaded via
dlopen(NULL,...) - something that has vanished from the sources.

I've attached a diff for both sqUnixExternalPrims.c and the 
omni-platform sqNamedPrims.c.

	THIS AFFECTS OTHER PLATFORMS!

Now, ioLoadModule() is called once with an empty module name to load the
intrinsics. The resulting handle is stored in squeakModule->handle.
Someone should make this work for other platforms ;^)

-- Bert
-------------- next part --------------
diff -c -x sqX ../2.8a/src/sqNamedPrims.c src/sqNamedPrims.c
*** ../2.8a/src/sqNamedPrims.c	Wed Jun 28 03:35:00 2000
--- src/sqNamedPrims.c	Thu Jul  6 23:33:22 2000
***************
*** 220,226 ****
  	void *handle;
  	ModuleEntry *module;
  
! 	dprintf(("Looking for plugin %s\n", (pluginName ? pluginName : "<intrinsic>")));
  	/* Try to load the module externally */
  	handle = (void*) ioLoadModule(pluginName);
  	if(ffiLoad) {
--- 220,226 ----
  	void *handle;
  	ModuleEntry *module;
  
! 	dprintf(("Looking for plugin %s\n", (pluginName && pluginName[0] ? pluginName : "<intrinsic>")));
  	/* Try to load the module externally */
  	handle = (void*) ioLoadModule(pluginName);
  	if(ffiLoad) {
***************
*** 260,266 ****
  
  	if(!squeakModule) {
  		/* Load intrinsics (if possible) */
! 		squeakModule = addToModuleList("", NULL, 1);
  		firstModule = NULL; /* drop off module list - will never be unloaded */
  	}
  
--- 260,266 ----
  
  	if(!squeakModule) {
  		/* Load intrinsics (if possible) */
! 		squeakModule = findAndLoadModule("", 1); 
  		firstModule = NULL; /* drop off module list - will never be unloaded */
  	}
  
***************
*** 330,339 ****
  	for(i=0; i< functionNameLength; i++)
  		functionName[i] = ((char*)functionNameIndex)[i];
  	functionName[functionNameLength] = 0;
! 	if(moduleHandle)
! 		return ioFindExternalFunctionIn(functionName, moduleHandle);
! 	else
! 		return 0;
  }
  
  /* ioLoadModuleOfLength
--- 330,336 ----
  	for(i=0; i< functionNameLength; i++)
  		functionName[i] = ((char*)functionNameIndex)[i];
  	functionName[functionNameLength] = 0;
! 	return ioFindExternalFunctionIn(functionName, moduleHandle ? moduleHandle : (int)squeakModule->handle);
  }
  
  /* ioLoadModuleOfLength
diff -c -x sqX ../2.8a/src/sqUnixExternalPrims.c src/sqUnixExternalPrims.c
*** ../2.8a/src/sqUnixExternalPrims.c	Sat May 20 00:24:25 2000
--- src/sqUnixExternalPrims.c	Thu Jul  6 23:35:11 2000
***************
*** 90,96 ****
  {
    void *handle= 0;
  
!   (void)(/* these are ordered so as to permit a knowledgeable user
  	    to override a "system" library with one in the CWD */
  	 (   handle= tryLoading(   "./", pluginName, ".so"))
  	 || (handle= tryLoading("./lib", pluginName, ".so"))
--- 90,103 ----
  {
    void *handle= 0;
  
!   if (!pluginName || !pluginName[0]) {
!     handle = dlopen(NULL, RTLD_NOW);
!     if (!handle)
! 	fprintf(stderr, "ioLoadModule(<intrinsic>): %s\n", dlerror());
!     else
! 	dprintf((stderr, "loaded:  <intrinsic>\n"));
!   } else {
!     (void)(/* these are ordered so as to permit a knowledgeable user
  	    to override a "system" library with one in the CWD */
  	 (   handle= tryLoading(   "./", pluginName, ".so"))
  	 || (handle= tryLoading("./lib", pluginName, ".so"))
***************
*** 100,105 ****
--- 107,113 ----
  	 || (handle= tryLoading(     "", pluginName, ".so"))
  	 || (handle= tryLoading(  "lib", pluginName, ".so"))
  	 || (handle= tryLoading(     "", pluginName,    "")));
+   }
    return (int)handle;
  }
  


More information about the Squeak-dev mailing list