From: Kevin M. Rosenberg Date: Tue, 11 Nov 2003 14:58:32 +0000 (+0000) Subject: r8151: changes for asdf-install X-Git-Tag: v1.6.1~155 X-Git-Url: http://git.kpe.io/?a=commitdiff_plain;h=7c6a7667f14741d85625f4091e931f1d5ed42159;p=uffi.git r8151: changes for asdf-install --- diff --git a/doc/uffi.pdf b/doc/uffi.pdf index b2b9b2c..ae6e424 100644 Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ diff --git a/tests/Makefile b/tests/Makefile index 09e6e39..cd1a5c5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -13,42 +13,22 @@ # as governed by the terms of the Lisp Lesser GNU Public License # (http://opensource.franz.com/preamble.html), also known as the LLGPL. -SUBDIRS:= +SUBDIRS= include ../Makefile.common -.PHONY: distclean -distclean: clean - rm -f $(base).dylib $(base).dylib $(base).so $(base).o - -base=uffi-c-test-lib +base=uffi-c-test source=$(base).c object=$(base).o shared_lib=$(base).so .PHONY: all -all: - echo "you need to specify a platform" +all: $(shared_lib) -linux: $(source) Makefile - gcc -fPIC -DPIC -c $(source) -o $(object) - gcc -shared $(object) -o $(shared_lib) - #gcc -shared -Wl,-soname,uffi-c-test-lib $(object) -o $(shared_lib) +$(shared_lib): $(source) Makefile + BASE=$(base) OBJECT=$(object) SOURCE=$(source) SHARED_LIB=$(shared_lib) sh make.sh rm $(object) -mac: - cc -dynamic -c $(source) -o $(object) - ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress -o $(base).dylib $(object) - ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.dylib - -mac-alt: - gcc -bundle -c $(source) -o $(base).bundle - ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.bundle - -solaris: - cc -KPIC -c $(source) -o $(object) - cc -G $(object) -o $(shared_lib) - -aix-acl: - gcc -c -D_BSD -D_NO_PROTO -D_NONSTD_TYPES -D_MBI=void $(source) - make_shared -o $(shared_lib) $(object) +.PHONY: distclean +distclean: clean + rm -f $(base).dylib $(base).dylib $(base).so $(base).o diff --git a/tests/foreign-loader.lisp b/tests/foreign-loader.lisp index a611f88..1030732 100644 --- a/tests/foreign-loader.lisp +++ b/tests/foreign-loader.lisp @@ -32,10 +32,10 @@ (unless (uffi:load-foreign-library (uffi:find-foreign-library - "uffi-c-test-lib" + "uffi-c-test" (list (pathname-directory *load-truename*) "/usr/lib/uffi/")) :supporting-libraries '("c") :module "uffi_tests") - (warn "Unable to load uffi-c-test-lib library")) + (warn "Unable to load uffi-c-test library")) diff --git a/tests/make.sh b/tests/make.sh new file mode 100644 index 0000000..f239372 --- /dev/null +++ b/tests/make.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +UNAME=`uname -a` +LINUX=`expr "$UNAME" : '.*Linux.*'` +DARWIN=`expr "$UNAME" : '.*Darwin.*'` +SOLARIS=`expr "$UNAME" : '.*sun4u.*'` +AIX=`expr "$UNAME" : '.*aix.*'` + + +if [ $LINUX -ne 0 ]; then + gcc -fPIC -DPIC -c $SOURCE -o $OBJECT + gcc -shared $OBJECT -o $SHARED_LIB + #gcc -shared -Wl,-soname,uffi-c-test-lib $OBJECT -o $SHARED_LIB +elif [ $DARWIN -ne 0 ]; then + cc -dynamic -c $SOURCE -o $OBJECT + ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress -o $BASE.dylib $OBJECT + ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.dylib +elif [ $SOLARIS -ne 0 ]; then + cc -KPIC -c $SOURCE -o $OBJECT + cc -G $OBJECT -o $SHARED_LIB +elif [ $AIX -ne 0 ]; then + gcc -c -D_BSD -D_NO_PROTO -D_NONSTD_TYPES -D_MBI=void $SOURCE + make_shared -o $SHARED_LIB $OBJECT +fi + + diff --git a/tests/uffi-c-test-lib.c b/tests/uffi-c-test-lib.c deleted file mode 100644 index ee1ab3a..0000000 --- a/tests/uffi-c-test-lib.c +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * FILE IDENTIFICATION - * - * Name: c-test-fns.c - * Purpose: Test functions in C for UFFI library - * Programer: Kevin M. Rosenberg - * Date Started: Mar 2002 - * - * CVS Id: $Id$ - * - * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg - * - * UFFI users are granted the rights to distribute and use this software - * as governed by the terms of the Lisp Lesser GNU Public License - * (http://opensource.franz.com/preamble.html), also known as the LLGPL. - - * These variables are correct for GCC - * you'll need to modify these for other compilers - ***************************************************************************/ - -#ifdef WIN32 -#include - -BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, - DWORD fdwReason, - LPVOID lpvReserved) -{ - return 1; -} - -#define DLLEXPORT __declspec(dllexport) - -#else -#define DLLEXPORT -#endif - -#include -#include -#include - - -DLLEXPORT unsigned char uchar_13 = 13; -DLLEXPORT signed char schar_neg_120 = -120; -DLLEXPORT unsigned short uword_257 = 257; -DLLEXPORT signed short sword_neg_321 = -321; -DLLEXPORT unsigned int uint_1234567 = 1234567; -DLLEXPORT signed int sint_neg_123456 = -123456; -DLLEXPORT double double_3_1 = 3.1; -DLLEXPORT float float_neg_4_5 = -4.5; - -/* Test of constant input string */ -DLLEXPORT -int -cs_count_upper (char* psz) -{ - int count = 0; - - if (psz) { - while (*psz) { - if (isupper (*psz)) - ++count; - ++psz; - } - return count; - } else - return -1; -} - -/* Test of input and output of a string */ -DLLEXPORT -void -cs_to_upper (char* psz) -{ - if (psz) { - while (*psz) { - *psz = toupper (*psz); - ++psz; - } - } -} - -/* Test of an output only string */ -DLLEXPORT -void -cs_make_random (int size, char* buffer) -{ - int i; - for (i = 0; i < size; i++) - buffer[i] = 'A' + (rand() % 26); -} - - -/* Test of input/output vector */ -DLLEXPORT -void -half_double_vector (int size, double* vec) -{ - int i; - for (i = 0; i < size; i++) - vec[i] /= 2.; -} - - - -DLLEXPORT -void * -cast_test_int () { - int *x = (int *) malloc(sizeof(int)); - *x = 23; - return x; -} - -DLLEXPORT -void * -cast_test_float () -{ - double *y = (double *) malloc(sizeof(double)); - *y = 3.21; - return y; -} - -DLLEXPORT int fvar_addend = 3; - -typedef struct { - int i; - double d; -} fvar_struct_type; - -fvar_struct_type fvar_struct = {42, 3.2}; - -DLLEXPORT -int fvar_struct_int () { - return (fvar_addend + fvar_struct.i); -} - -DLLEXPORT -double fvar_struct_double () { - return fvar_struct.d; -} - - diff --git a/tests/uffi-c-test.c b/tests/uffi-c-test.c new file mode 100644 index 0000000..ee1ab3a --- /dev/null +++ b/tests/uffi-c-test.c @@ -0,0 +1,141 @@ +/*************************************************************************** + * FILE IDENTIFICATION + * + * Name: c-test-fns.c + * Purpose: Test functions in C for UFFI library + * Programer: Kevin M. Rosenberg + * Date Started: Mar 2002 + * + * CVS Id: $Id$ + * + * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg + * + * UFFI users are granted the rights to distribute and use this software + * as governed by the terms of the Lisp Lesser GNU Public License + * (http://opensource.franz.com/preamble.html), also known as the LLGPL. + + * These variables are correct for GCC + * you'll need to modify these for other compilers + ***************************************************************************/ + +#ifdef WIN32 +#include + +BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, + DWORD fdwReason, + LPVOID lpvReserved) +{ + return 1; +} + +#define DLLEXPORT __declspec(dllexport) + +#else +#define DLLEXPORT +#endif + +#include +#include +#include + + +DLLEXPORT unsigned char uchar_13 = 13; +DLLEXPORT signed char schar_neg_120 = -120; +DLLEXPORT unsigned short uword_257 = 257; +DLLEXPORT signed short sword_neg_321 = -321; +DLLEXPORT unsigned int uint_1234567 = 1234567; +DLLEXPORT signed int sint_neg_123456 = -123456; +DLLEXPORT double double_3_1 = 3.1; +DLLEXPORT float float_neg_4_5 = -4.5; + +/* Test of constant input string */ +DLLEXPORT +int +cs_count_upper (char* psz) +{ + int count = 0; + + if (psz) { + while (*psz) { + if (isupper (*psz)) + ++count; + ++psz; + } + return count; + } else + return -1; +} + +/* Test of input and output of a string */ +DLLEXPORT +void +cs_to_upper (char* psz) +{ + if (psz) { + while (*psz) { + *psz = toupper (*psz); + ++psz; + } + } +} + +/* Test of an output only string */ +DLLEXPORT +void +cs_make_random (int size, char* buffer) +{ + int i; + for (i = 0; i < size; i++) + buffer[i] = 'A' + (rand() % 26); +} + + +/* Test of input/output vector */ +DLLEXPORT +void +half_double_vector (int size, double* vec) +{ + int i; + for (i = 0; i < size; i++) + vec[i] /= 2.; +} + + + +DLLEXPORT +void * +cast_test_int () { + int *x = (int *) malloc(sizeof(int)); + *x = 23; + return x; +} + +DLLEXPORT +void * +cast_test_float () +{ + double *y = (double *) malloc(sizeof(double)); + *y = 3.21; + return y; +} + +DLLEXPORT int fvar_addend = 3; + +typedef struct { + int i; + double d; +} fvar_struct_type; + +fvar_struct_type fvar_struct = {42, 3.2}; + +DLLEXPORT +int fvar_struct_int () { + return (fvar_addend + fvar_struct.i); +} + +DLLEXPORT +double fvar_struct_double () { + return fvar_struct.d; +} + + diff --git a/uffi-tests.asd b/uffi-tests.asd index 4b8417b..6f2c4bf 100644 --- a/uffi-tests.asd +++ b/uffi-tests.asd @@ -14,12 +14,51 @@ (:use #:asdf #:cl)) (in-package #:uffi-tests-system) +(defvar *asd-file-dir* (pathname-directory *load-truename*)) + +(defclass uffi-test-source-file (c-source-file) + ()) + +(defmethod output-files ((o compile-op) (c uffi-test-source-file)) + (let ((searched (or + (probe-file #p"/usr/lib/uffi/uffi-c-test.so") + (probe-file (make-pathname + :directory *asd-file-dir* + :name "uffi-c-test" + :type "so"))))) + (if searched + (list searched) + (list (merge-pathnames + (make-pathname :name (component-name c) + :type "so" + :directory '(:relative "tests")) + (make-pathname :directory *asd-file-dir*)))))) + +(defmethod perform ((o load-op) (c uffi-test-source-file)) + (dolist (f (asdf::input-files o c)) + (funcall (intern (symbol-name '#:load-foreign-library) + (symbol-name '#:uffi)) + f :module "uffi_tests"))) + +(defmethod perform ((o compile-op) (c uffi-test-source-file)) + (unless (zerop (run-shell-command "cd ~A; make" + (namestring (merge-pathnames + (make-pathname + :name nil + :type nil + :directory '(:relative "tests")) + (make-pathname + :directory *asd-file-dir*))))) + (error 'operation-error :component c :operation o))) + + (defsystem uffi-tests :depends-on (:uffi) :components ((:module tests :components ((:file "rt") + (:uffi-test-source-file "uffi-c-test") (:file "package" :depends-on ("rt")) (:file "strtol" :depends-on ("package")) (:file "atoifl" :depends-on ("package")) @@ -30,7 +69,7 @@ (:file "structs" :depends-on ("package")) (:file "pointers" :depends-on ("package")) (:file "time" :depends-on ("package")) - (:file "foreign-loader" :depends-on ("package")) + (:file "foreign-loader" :depends-on ("package" "uffi-c-test")) (:file "uffi-c-test-lib" :depends-on ("foreign-loader")) (:file "compress" :depends-on ("foreign-loader")) (:file "casts" :depends-on ("foreign-loader"))