+echo //entering foreign.test.sh
+
+# simple way to make sure we're not punting by accident:
+# setting PUNT to anything other than 104 will make non-dlopen
+# and non-linkage-table platforms fail this
+PUNT=104
+
+testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
+
+## Make some shared object files to test with.
+
+build_so() {
+ echo building $1.so
+ if [ "`uname -m`" = x86_64 ]; then
+ CFLAGS="$CFLAGS -fPIC"
+ fi
+ if [ "`uname`" = Darwin ]; then
+ SO_FLAGS="-bundle"
+ else
+ SO_FLAGS="-shared"
+ fi
+ cc -c $1.c -o $1.o $CFLAGS
+ ld $SO_FLAGS -o $1.so $1.o
+}
+
+cat > $testfilestem.c <<EOF
+int summish(int x, int y) { return 1 + x + y; }
+
+int numberish = 42;
+
+int nummish(int x) { return numberish + x; }
+
+short negative_short() { return -1; }
+int negative_int() { return -2; }
+long negative_long() { return -3; }
+
+long long powish(unsigned int x, unsigned int y) {
+ long long acc = 1;
+ long long xx = (long long) x;
+ for(; y != 1; y /= 2) {
+ if (y & 1) {
+ acc *= xx;
+ y -= 1;
+ }
+ xx *= xx;
+ }
+ return xx*acc;
+}
+
+float return9th(float f1, float f2, float f3, float f4, float f5,
+ float f6, float f7, float f8, float f9, float f10,
+ float f11, float f12) {
+ return f9;
+}
+
+double 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) {
+ return f9;
+}
+
+int long_test8(int a1, int a2, int a3, int a4, int a5,
+ int a6, int a7, long long l1) {
+ return (l1 == powish(2,34));
+}
+
+int long_test9(int a1, int a2, int a3, int a4, int a5,
+ int a6, int a7, long long l1, int a8) {
+ return (l1 == powish(2,35));
+}
+
+int long_test2(int i1, int i2, int i3, int i4, int i5, int i6,
+ int i7, int i8, int i9, long long l1, long long l2) {
+ return (l1 == (1 + powish(2,37)));
+}
+
+long long return_long_long() {
+ return powish(2,33);
+}
+EOF
+
+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.base.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))