Organization: Enator Functional Systems, Stockholm, Sweden
Date: Fri, 22 Jan 1993 08:06:26 GMT
Lines: 65
In working with the C interface in Smalltalk-80 on a SUN I've stumbled on
a very subtle bug (feature?). This bug applies to Smalltalk on UNIX platforms.
When you create an interface to a C-library you have to supply the name
of the library and a list of paths to where the library should be sought.
This would not work if you ship an image to a site that has its libraries
in a different place. To solve this ObjectMemory sends the update aspect #earlySystemInstallation to the ExternalInterface class on system startup.
The ExternalInterface in turn sends (among other things)
installLibraryDirectoriesOn: to itself. At this point it would be possible
on a UNIX platform to get an environment variable from the CEnvironment class.
On a SUN the environment variable LD_LIBRARY_PATH stores the path names to
a number of library directories.
But this wouldn't work!
The reason is that CEnvironment also updates itself on system startup. It
regenerates its dictionary of environment variables when it receives the
update aspect #returnFromSnapshot. The problem is that ExternalInterface
receives #earlySystemInstallation before CEnvironment receives
#returnFromSnapshot.
The result of this is that ExternalInterface would end up getting an old
value for LD_LIBRARY_PATH from CEnvironment.
The following code fixes this problem. The reason I use Smalltalk at: is
that I don't want a dependancy between ExternalInterface and CEnvironment.
'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992
ENVY/Developer R1.40 of 21 August 1992 on 22 January 1993 at 8:59:54 am'!
!ExternalInterface class methodsFor: 'initialize-release'!
install
"Inform all dependent classes of a return from snapshot."
"ExternalInterface install"
| platformString platformArray platformID cEnv |
"21 January 1993 - Added initialization of CEnvironment since some of the receiver's subclasses need environment variables that might have changed since the last snapshot. Remove CEnvironment from ObjectMemory since we don't want CEnvironment to initialize itself a second time"
cEnv := Smalltalk at: #CEnvironment ifAbsent: [].
cEnv = nil
ifFalse:
[cEnv install.
cEnv checkEnvironment.
(ObjectMemory dependents includes: cEnv)
ifTrue: [ObjectMemory removeDependent: cEnv]].
platformString := OSHandle informVM.
platformID := (platformString copyUpTo: Character space) asSymbol.