On OSX, load-shared-object does not reload if the dylib contains an @implementation block
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
Docs state:
> On non-Windows platforms calling load-shared-object again with a pathname equal to the designated pathname of a previous call will replace the old definitions
This usually works as expected, but under some circumstances the reload behaviour doesn't happen. I tracked this down to the presence of an Objective-C @implementation block in the .dylib being loaded.
Here is a test case demonstrating this (also attached). You'll need the developer tools installed. Run “./test.lisp” to see the unexpected behaviour:
-- test.lisp: -------
#!/usr/bin/env sbcl --script
(sb-ext:run-program
"/usr/bin/gcc"
'("-o" "lib.dylib" "-dynamiclib" "1.m" "-framework" "Foundation")
:output t
:error t
)
(load-shared-object "lib.dylib")
(define-
(format t "Should be 1: ~A~%" (test))
(sb-ext:run-program
"/usr/bin/gcc"
'("-o" "lib.dylib" "-dynamiclib" "2.m" "-framework" "Foundation")
:output t
:error t
)
(load-shared-object "lib.dylib")
(format t "Should be 2: ~A~%" (test))
-- 1.m: -------
#import <Foundation/
@interface Test : NSObject
@end
@implementation Test
@end
const char *test()
{
return "1";
}
-- 2.m: -------
#import <Foundation/
@interface Test : NSObject
@end
@implementation Test
@end
const char *test()
{
return "2";
}
-- System info -------
$ sbcl --version
SBCL 1.3.6
$ uname -a
Darwin MBP 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-
*FEAUTRES*
(:QUICKLISP :ASDF-PACKAGE-
:OS-UNIX :NON-BASE-
:ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-
:COMMON-LISP :COMPARE-
:DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :FP-AND-
:IEEE-
:LINKAGE-TABLE :LITTLE-ENDIAN :MACH-EXCEPTION
:MEMORY-
:OS-PROVIDES-
:OS-PROVIDES-
:RAW-INSTANCE-
:SB-PACKAGE-LOCKS :SB-SIMD-PACK :SB-SOURCE-
:SB-UNICODE :SBCL :STACK-
:STACK-
:STACK-
:UNWIND-
It looks like this is an OSX limitation: http:// stackoverflow. com/questions/ 8793099/ unload- dynamic- library- needs-two- dlclose- calls
I think a good resolution for this would just be to put a note in the docs and close the issue.