-sbcl --noinform --noprint --sysinit /dev/null --userinit /dev/null <<EOF
- (load-foreign '("$testfilestem.so"))
- (def-alien-routine summish int (x int) (y int))
+# Foreign definitions & load
+cat > $testfilestem.deflisp <<EOF
+ (define-alien-variable environ (* c-string))
+ (defvar *environ* environ)
+ (handler-case
+ (load-shared-object "$testfilestem.so")
+ (sb-int:unsupported-operator ()
+ ;; At least as of sbcl-0.7.0.5, LOAD-SHARED-OBJECT isn't
+ ;; supported on every OS. In that case, there's nothing to test,
+ ;; and we can just fall through to success.
+ (sb-ext:quit :unix-status 22))) ; catch that
+ (define-alien-routine summish int (x int) (y int))
+ (define-alien-variable numberish int)
+ (define-alien-routine nummish int (x int))
+
+ ;; Test that loading an object file didn't screw up our records
+ ;; of variables visible in runtime. (This was a bug until
+ ;; Nikodemus Siivola's patch in sbcl-0.8.5.50.)
+ ;;
+ ;; This cannot be tested in a saved core, as there is no guarantee
+ ;; that the location will be the same.
+ (assert (= (sb-sys:sap-int (alien-sap *environ*))
+ (sb-sys:sap-int (alien-sap environ))))
+EOF
+
+# Test code
+cat > $testfilestem.testlisp <<EOF