0.8.7.52:
[sbcl.git] / tests / foreign.test.sh
index 47f4344..89f98d7 100644 (file)
 # absolutely no warranty. See the COPYING and CREDITS files for
 # more information.
 
+echo //entering foreign.test.sh
+
 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
 
+# Make a little shared object file to test with.
 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
-make $testfilestem.o
+cc -c $testfilestem.c -o $testfilestem.o
 ld -shared -o $testfilestem.so $testfilestem.o
 
+# Test interaction with the shared object file.
 ${SBCL:-sbcl} <<EOF
+  (define-alien-variable environ (* c-string))
+  (defvar *environ* environ)
   (handler-case 
       (load-foreign '("$testfilestem.so"))
     (sb-int:unsupported-operator ()
@@ -27,6 +33,11 @@ ${SBCL:-sbcl} <<EOF
      ;; on every OS. In that case, there's nothing to test, and we
      ;; can just fall through to success.
      (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
+  ;; 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.)
+  (assert (= (sb-sys:sap-int (alien-sap *environ*))
+             (sb-sys:sap-int (alien-sap environ))))
   (define-alien-routine summish int (x int) (y int))
   (assert (= (summish 10 20) 31))
   (sb-ext:quit :unix-status 52) ; success convention for Lisp program
@@ -42,7 +53,8 @@ fi
 # rolling over in his grave.:-) It would be good to make a test case
 # for it..
 
+echo //cleanup: removing $testfilestem.*
 rm $testfilestem.*
 
 # success convention for script
-exit 104
+exit 104