+build_so $testfilestem
+
+echo 'int foo = 13;' > $testfilestem-b.c
+echo 'int bar() { return 42; }' >> $testfilestem-b.c
+build_so $testfilestem-b
+
+echo 'int foo = 42;' > $testfilestem-b2.c
+echo 'int bar() { return 13; }' >> $testfilestem-b2.c
+build_so $testfilestem-b2
+
+echo 'int late_foo = 43;' > $testfilestem-c.c
+echo 'int late_bar() { return 14; }' >> $testfilestem-c.c
+build_so $testfilestem-c
+
+## Foreign definitions & load
+
+cat > $testfilestem.def.lisp <<EOF
+ (define-alien-variable environ (* c-string))
+ (defvar *environ* environ)
+ (eval-when (:compile-toplevel :load-toplevel :execute)
+ (handler-case
+ (progn
+ (load-shared-object "$testfilestem.so")
+ (load-shared-object "$testfilestem-b.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))
+ (define-alien-variable "foo" int)
+ (define-alien-routine "bar" int)
+
+ (define-alien-routine "negative_short" short)
+ (define-alien-routine "negative_int" int)
+ (define-alien-routine "negative_long" long)
+
+ (define-alien-routine return9th float (input1 float) (input2 float) (input3 float) (input4 float) (input5 float) (input6 float) (input7 float) (input8 float) (input9 float) (input10 float) (input11 float) (input12 float))
+ (define-alien-routine return9thd double (f1 double) (f2 double) (f3 double) (f4 double) (f5 double) (f6 double) (f7 double) (f8 double) (f9 double) (f10 double) (f11 double) (f12 double))
+
+ (define-alien-routine long-test8 int (int1 int) (int2 int) (int3 int) (int4 int) (int5 int) (int6 int) (int7 int) (long1 (integer 64)))
+ (define-alien-routine long-test9 int (int1 int) (int2 int) (int3 int) (int4 int) (int5 int) (int6 int) (int7 int) (long1 (integer 64)) (int8 int))
+ (define-alien-routine long-test2 int (int1 int) (int2 int) (int3 int) (int4 int) (int5 int) (int6 int) (int7 int) (int8 int) (int9 int) (long1 (integer 64)) (long2 (integer 64)))
+ (define-alien-routine return-long-long (integer 64))
+
+ ;; compiling this gets us the FOP-FOREIGN-DATAREF-FIXUP on
+ ;; linkage-table ports
+ (defvar *extern* (extern-alien "negative_short" short))
+
+ ;; 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))))
+
+ (enable-debugger)
+ ;; automagic restarts
+ (setf *debugger-hook*
+ (lambda (condition hook)
+ (print (list :debugger-hook condition))
+ (let ((cont (find-restart 'continue condition)))
+ (when cont
+ (invoke-restart cont)))
+ (print :fell-through)
+ (invoke-debugger condition)))
+EOF
+
+# Test code
+cat > $testfilestem.test.lisp <<EOF