diff --git a/Rakefile b/Rakefile index 33f6730e6..5703c3322 100644 --- a/Rakefile +++ b/Rakefile @@ -3,82 +3,16 @@ require 'rbconfig' require 'rake/clean' require File.expand_path("./lib/ffi/version") -USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true -if USE_RAKE_COMPILER - require 'rake/extensiontask' -end - require 'date' require 'fileutils' require 'rbconfig' require 'rspec/core/rake_task' require 'rubygems/package_task' -LIBEXT = case RbConfig::CONFIG['host_os'].downcase - when /darwin/ - "dylib" - when /mswin|mingw/ - "dll" - else - RbConfig::CONFIG['DLEXT'] - end - -CPU = case RbConfig::CONFIG['host_cpu'].downcase - when /i[3456]86/ - # Darwin always reports i686, even when running in 64bit mode - if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum) - "x86_64" - else - "i386" - end - - when /amd64|x86_64/ - "x86_64" - - when /ppc64|powerpc64/ - "powerpc64" - - when /ppc|powerpc/ - "powerpc" - - when /^arm/ - "arm" - - else - RbConfig::CONFIG['host_cpu'] - end - -OS = case RbConfig::CONFIG['host_os'].downcase - when /linux/ - "linux" - when /darwin/ - "darwin" - when /freebsd/ - "freebsd" - when /openbsd/ - "openbsd" - when /sunos|solaris/ - "solaris" - when /mswin|mingw/ - "win32" - else - RbConfig::CONFIG['host_os'].downcase - end - -def which(name) - exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] - ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| - exts.each do |ext| - app = File.join(path, name+ext) - return app if File.executable? app - end - end - nil +def java? + /java/ === RUBY_PLATFORM end -GMAKE = which('gmake').nil? ? 'make' : 'gmake' - -LIBTEST = "build/libtest.#{LIBEXT}" BUILD_DIR = "build" BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION) @@ -86,7 +20,7 @@ def gem_spec @gem_spec ||= Gem::Specification.load('ffi.gemspec') end -TEST_DEPS = [ LIBTEST ] +TEST_DEPS = [] if RUBY_PLATFORM == "java" RSpec::Core::RakeTask.new(:spec) do |config| config.rspec_opts = YAML.load_file 'spec/spec.opts' @@ -117,15 +51,6 @@ CLEAN.include 'bin' task :distclean => :clobber -desc "Build the native test lib" -file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do - sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} } -end - - -desc "Build test helper lib" -task :libtest => "build/libtest.#{LIBEXT}" - desc "Test the extension" task :test => [ :spec ] @@ -175,8 +100,8 @@ end task 'gem:java' => 'java:gem' - -if USE_RAKE_COMPILER +unless java? + require 'rake/extensiontask' Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext| ext.name = 'ffi_c' # indicate the name of the extension. # ext.lib_dir = BUILD_DIR # put binaries into this folder. diff --git a/ext/ffi_c/Platform.c b/ext/ffi_c/Platform.c index de114a88b..31139cbd6 100644 --- a/ext/ffi_c/Platform.c +++ b/ext/ffi_c/Platform.c @@ -49,51 +49,6 @@ static VALUE PlatformModule = Qnil; -/* - * Determine the cpu type at compile time - useful for MacOSX where the the - * system installed ruby incorrectly reports 'host_cpu' as 'powerpc' when running - * on intel. - */ -#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64) || defined(_M_X64) || defined(_M_AMD64) -# define CPU "x86_64" - -#elif defined(__i386__) || defined(__i386) || defined(_M_IX86) -# define CPU "i386" - -#elif defined(__ppc64__) || defined(__powerpc64__) || defined(_M_PPC) -# define CPU "ppc64" - -#elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc) -# define CPU "ppc" - -/* - * Need to check for __sparcv9 first, because __sparc will be defined either way. - * Note that __sparcv9 seems to only be set for Solaris. On Linux, __sparc will - * be set, along with __arch64__ if a 64-bit platform. - */ -#elif defined(__sparcv9__) || defined(__sparcv9) -# define CPU "sparcv9" - -#elif defined(__sparc__) || defined(__sparc) -# if defined(__arch64__) -# define CPU "sparcv9" -# else -# define CPU "sparc" -# endif - -#elif defined(__arm__) || defined(__arm) -# define CPU "arm" - -#elif defined(__mips__) || defined(__mips) -# define CPU "mips" - -#elif defined(__s390__) -# define CPU "s390" - -#else -# define CPU "unknown" -#endif - static void export_primitive_types(VALUE module) { @@ -120,10 +75,8 @@ rbffi_Platform_Init(VALUE moduleFFI) rb_define_const(PlatformModule, "BYTE_ORDER", INT2FIX(BYTE_ORDER)); rb_define_const(PlatformModule, "LITTLE_ENDIAN", INT2FIX(LITTLE_ENDIAN)); rb_define_const(PlatformModule, "BIG_ENDIAN", INT2FIX(BIG_ENDIAN)); - rb_define_const(PlatformModule, "CPU", rb_str_new2(CPU)); #if defined(__GNU__) || defined(__GLIBC__) rb_define_const(PlatformModule, "GNU_LIBC", rb_str_new2(LIBC_SO)); #endif export_primitive_types(PlatformModule); } - diff --git a/lib/ffi/platform.rb b/lib/ffi/platform.rb index 0ec3e1472..ff9cdf84e 100644 --- a/lib/ffi/platform.rb +++ b/lib/ffi/platform.rb @@ -56,6 +56,8 @@ module Platform OSVERSION = RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i + CPU = RbConfig::CONFIG['host_cpu'] + ARCH = case CPU.downcase when /amd64|x86_64/ "x86_64" diff --git a/libtest/Benchmark.c b/libtest/Benchmark.c deleted file mode 100644 index 55a73806a..000000000 --- a/libtest/Benchmark.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ -#include -#include - -void returnVoid() { - -} - -void returnVoidI(int arg) { - -} -int returnInt() { - return 0; -} - -int returnIntI(int arg) { - return arg; -} - -typedef int8_t s8; -typedef uint8_t u8; -typedef int16_t s16; -typedef uint16_t u16; -typedef int32_t s32; -typedef uint32_t u32; -typedef int64_t s64; -typedef uint64_t u64; -typedef float f32; -typedef double f64; -typedef void v; -typedef char* S; -typedef void* P; - -#define B6(R, T1, T2, T3, T4, T5, T6) R bench_##T1##T2##T3##T4##T5##T6##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) {} -#define B5(R, T1, T2, T3, T4, T5) R bench_##T1##T2##T3##T4##T5##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {} -#define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {} -#define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {} -#define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {} -#define B1(R, T1) R bench_##T1##_##R(T1 a1) {} -#define BrV(T) B1(v, T); B2(v, T, T); B3(v, T, T, T); B4(v, T, T, T, T); B5(v, T, T, T, T, T); B6(v, T, T, T, T, T, T); -BrV(u32); -BrV(s32); -BrV(s64); -BrV(u64); -BrV(f32); -BrV(f64); -BrV(S); -BrV(P); diff --git a/libtest/BoolTest.c b/libtest/BoolTest.c deleted file mode 100644 index 04cb6c689..000000000 --- a/libtest/BoolTest.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. - * Copyright (c) 2009 Aman Gupta. - * - * All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include - -bool -bool_return_true() -{ - return true; -} - -bool -bool_return_false() -{ - return false; -} - -bool -bool_return_val(bool value) -{ - return value; -} - -bool -bool_reverse_val(bool value) -{ - return value ? false : true; -} diff --git a/libtest/BufferTest.c b/libtest/BufferTest.c deleted file mode 100644 index 3e95ebcf2..000000000 --- a/libtest/BufferTest.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - - -#define MEMSET(buf, value, size) do { \ - int i; for (i = 0; i < size; ++i) buf[i] = value; \ -} while(0) -#define MEMCPY(dst, src, size) do { \ - int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \ -} while(0) - -#define FILL(JTYPE, CTYPE) \ -void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); } - -#define COPY(JTYPE, CTYPE) \ -void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); } - -#define FUNC(JTYPE, CTYPE) \ - FILL(JTYPE, CTYPE); \ - COPY(JTYPE, CTYPE) - -FUNC(Byte, char); -FUNC(Short, short); -FUNC(Int, int); -FUNC(Long, long long); -FUNC(Float, float); -FUNC(Double, double); - diff --git a/libtest/ClosureTest.c b/libtest/ClosureTest.c deleted file mode 100644 index dfeabde66..000000000 --- a/libtest/ClosureTest.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#ifndef _WIN32 -# include -#else -# include -# include -#endif - -#define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \ - return closure != NULL ? (*closure)() : (rtype) 0; \ -} - -#define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \ - if (closure != NULL) (*closure)(a1); \ -} - -void testClosureVrV(void (*closure)(void)) -{ - (*closure)(); -} - -R(Z, bool); -R(B, char); -R(S, short); -R(I, int); -R(L, long); -R(J, long long); -R(LL, long long); -R(F, float); -R(D, double); -R(P, const void*); - - -P(Z, bool); -P(B, char); -P(S, short); -P(I, int); -P(L, long); -P(J, long long); -P(LL, long long); -P(F, float); -P(D, double); -P(P, const void*); -P(UL, unsigned long); - -#if defined(_WIN32) && !defined(_WIN64) -bool __stdcall testClosureStdcall(long *a1, void __stdcall(*closure)(void *, long), long a2) { \ - void* sp_pre; - void* sp_post; - - asm volatile (" movl %%esp,%0" : "=g" (sp_pre)); - (*closure)(a1, a2); - asm volatile (" movl %%esp,%0" : "=g" (sp_post)); - - /* %esp before pushing parameters on the stack and after the call returns - * should be equal, if both sides respects the stdcall convention */ - return sp_pre == sp_post; -} -#endif - -void testOptionalClosureBrV(void (*closure)(char), char a1) -{ - if (closure) { - (*closure)(a1); - } -} - - -struct ThreadVrV { - void (*closure)(void); - int count; -}; - -static void * -threadVrV(void *arg) -{ - struct ThreadVrV* t = (struct ThreadVrV *) arg; - - int i; - for (i = 0; i < t->count; i++) { - (*t->closure)(); - } - - return NULL; -} - -void testThreadedClosureVrV(void (*closure)(void), int n) -{ - struct ThreadVrV arg = {closure, n}; -#ifndef _WIN32 - pthread_t t; - pthread_create(&t, NULL, threadVrV, &arg); - pthread_join(t, NULL); -#else - HANDLE hThread = (HANDLE) _beginthread((void (*)(void *))threadVrV, 0, &arg); - WaitForSingleObject(hThread, INFINITE); -#endif -} - -struct s8f32s32 { - char s8; - float f32; - int s32; -}; - -// Takes a struct argument -void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s) -{ - (*closure)(*s); -} - -// Returns a struct value -struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)()) -{ - return (*closure)(); -} - -typedef int (*returnTypeClosure_t)(int) ; -typedef returnTypeClosure_t (*lookupClosure_t)(); - -int testReturnsClosure(lookupClosure_t lookup, int val) -{ - returnTypeClosure_t func = lookup ? (*lookup)() : NULL; - return func ? (*func)(val) : 0; -} - -static int multiplyByTwo(int value) -{ - return value * 2; -} - -returnTypeClosure_t testReturnsFunctionPointer() -{ - return multiplyByTwo; -} - -typedef int (*argumentClosure_t)(int); -typedef int (*withArgumentClosure_t)(argumentClosure_t, int); - -int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val) -{ - return (*closure_with)(closure_arg, val); -} - - -// -// These macros produce functions of the form: -// testClosureBIrV(void (*closure)(char, int), char a1, int a2) {} -// -#define C2_(J1, J2, N1, N2) \ -void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \ -{ \ - if (closure != NULL) (*closure)(a1, a2); \ -} - -#define C2(J, N) \ - C2_(B, J, char, N) \ - C2_(S, J, short, N) \ - C2_(I, J, int, N) \ - C2_(LL, J, long long, N) \ - C2_(F, J, float, N) \ - C2_(D, J, double, N) \ - - -C2(B, char); -C2(S, short); -C2(I, int); -C2(LL, long long); -C2(F, float); -C2(D, double); - -#define C3_(J1, J2, J3, N1, N2, N3) \ -void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \ -{ \ - (*closure)(a1, a2, a3); \ -} - - -#define C3(J, N) \ - C3_(B, J, B, char, N, char) \ - C3_(S, J, S, short, N, short) \ - C3_(I, J, I, int, N, int) \ - C3_(LL, J, LL, long long, N, long long) \ - C3_(F, J, F, float, N, float) \ - C3_(D, J, D, double, N, double) \ - -C3(B, char); -C3(S, short); -C3(I, int); -C3(LL, long long); -C3(F, float); -C3(D, double); -C3_(B, S, I, char, short, int); -C3_(B, S, LL, char, short, long long); -C3_(LL, S, B, long long, short, char); -C3_(LL, B, S, long long, char, short); - - diff --git a/libtest/EnumTest.c b/libtest/EnumTest.c deleted file mode 100644 index 4bf8d236b..000000000 --- a/libtest/EnumTest.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ -#include - -int test_untagged_enum(int val) { - return val; -} - -int test_untagged_typedef_enum(int val) { - return val; -} - -uint8_t test_untagged_nonint_enum(uint8_t val) { - return val; -} - -uint16_t test_tagged_nonint_enum1(uint16_t val) { - return val; -} - -uint32_t test_tagged_nonint_enum2(uint32_t val) { - return val; -} - -uint64_t test_tagged_nonint_enum3(uint64_t val) { - return val; -} - -typedef enum {c1, c2, c3, c4} enum_type1; -enum_type1 test_tagged_typedef_enum1(enum_type1 val) { - return val; -} - -typedef enum {c5 = 42, c6, c7, c8} enum_type2; -enum_type2 test_tagged_typedef_enum2(enum_type2 val) { - return val; -} - -typedef enum {c9 = 42, c10, c11 = 4242, c12} enum_type3; -enum_type3 test_tagged_typedef_enum3(enum_type3 val) { - return val; -} - -typedef enum {c13 = 42, c14 = 4242, c15 = 424242, c16 = 42424242} enum_type4; -enum_type4 test_tagged_typedef_enum4(enum_type4 val) { - return val; -} - diff --git a/libtest/FunctionTest.c b/libtest/FunctionTest.c deleted file mode 100644 index 8cde5f1a5..000000000 --- a/libtest/FunctionTest.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#ifdef _WIN32 -#include -#define sleep(x) Sleep((x)*1000) -#endif - -#ifndef _WIN32 -#include -#include -#endif - -int testAdd(int a, int b) -{ - return a + b; -}; - -int testFunctionAdd(int a, int b, int (*f)(int, int)) -{ - return f(a, b); -}; - -void testBlocking(int seconds) { - sleep(seconds); -}; - -struct async_data { - void (*fn)(int); - int value; -}; - -static void* asyncThreadCall(void *data) -{ - struct async_data* d = (struct async_data *) data; - if (d != NULL && d->fn != NULL) { - (*d->fn)(d->value); - } - - return NULL; -} - -void testAsyncCallback(void (*fn)(int), int value) -{ -#ifndef _WIN32 - pthread_t t; - struct async_data d; - d.fn = fn; - d.value = value; - pthread_create(&t, NULL, asyncThreadCall, &d); - pthread_join(t, NULL); -#else - (*fn)(value); -#endif -} - -#if defined(_WIN32) && !defined(_WIN64) -struct StructUCDP { - unsigned char a1; - double a2; - void *a3; -}; - -void __stdcall testStdcallManyParams(long *a1, char a2, short int a3, int a4, __int64 a5, - struct StructUCDP a6, struct StructUCDP *a7, float a8, double a9) { -} -#endif diff --git a/libtest/GNUmakefile b/libtest/GNUmakefile deleted file mode 100644 index a7ba9e67e..000000000 --- a/libtest/GNUmakefile +++ /dev/null @@ -1,149 +0,0 @@ -# -*- makefile -*- - -ifeq ($(OS),) - BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') - OS := $(BUILD_OS) -endif - -ifeq ($(CPU),) - CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/') -endif - -PLATFORM = $(CPU)-$(OS) - -ifeq ($(OS), sunos) - OS = solaris -endif - -SRC_DIR = libtest -BUILD_DIR ?= build -TEST_BUILD_DIR = $(BUILD_DIR)/libtest -# Set defaults to unix (linux/solaris/bsd) -PREFIX = lib -LIBEXT ?= so -LIBNAME = $(PREFIX)test.$(LIBEXT) - -export MACOSX_DEPLOYMENT_TARGET=10.4 - -CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null))) - -TEST_SRCS = $(wildcard $(SRC_DIR)/*.c) -TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS)) - -# -# Compiler/linker flags from: -# http://weblogs.java.net/blog/kellyohair/archive/2006/01/compilation_of_1.html -JFLAGS = -fno-omit-frame-pointer -fno-strict-aliasing -OFLAGS = -O2 $(JFLAGS) -WFLAGS = -W -Wall -Wno-unused -Wno-parentheses -PICFLAGS = -fPIC -SOFLAGS = -shared -LDFLAGS += $(SOFLAGS) - -IFLAGS = -I"$(BUILD_DIR)" -CFLAGS = $(OFLAGS) $(WFLAGS) $(IFLAGS) $(PICFLAGS) -D_REENTRANT - -ifneq ($(strip $(findstring $(OS), win32, mingw, cygwin)),) - # For cygwin => win32-native builds, strip out cygwin deps - ifneq ($(findstring cygwin, $(BUILD_OS)),) - CC += -mno-cygwin -mwin32 - LDFLAGS += -mno-cygwin -Wl,--add-stdcall-alias - endif - PICFLAGS= - LIBEXT=dll - CC = gcc -endif - -ifeq ($(OS), darwin) - ifneq ($(findstring $(CPU),ppc),) - ARCHFLAGS += -arch ppc - endif - ifneq ($(findstring $(CPU),i386 x86_64),) - ARCHFLAGS += -arch i386 -arch x86_64 - endif - CFLAGS += $(ARCHFLAGS) -DTARGET_RT_MAC_CFM=0 - CFLAGS += -fno-common - LDFLAGS = $(ARCHFLAGS) -dynamiclib - # link against the universal libraries on ppc machines - LDFLAGS += -L$(MACSDK)/usr/lib - LIBEXT = dylib - FFI_CFLAGS += -isysroot $(MACSDK) - PICFLAGS = - SOFLAGS = -endif - -ifeq ($(OS), linux) - SOFLAGS += -Wl,-soname,$(LIBNAME) -endif - -ifeq ($(OS), solaris) - CC = /usr/sfw/bin/gcc -std=c99 - LD = /usr/ccs/bin/ld - SOFLAGS = -shared -static-libgcc -endif - -ifeq ($(OS), aix) - LIBEXT = a - SOFLAGS = -shared -static-libgcc - PICFLAGS += -pthread -endif - -ifneq ($(findstring bsd, $(OS)),) - SOFLAGS = -shared -static-libgcc - CFLAGS += -pthread - LDFLAGS += -pthread -endif - -ifeq ($(CPU), i386) - MODEL = 32 -endif - -ifeq ($(CPU), sparcv9) - MODEL = 64 -endif - -ifeq ($(CPU), amd64) - MODEL = 64 -endif - -ifeq ($(CPU), x86_64) - MODEL = 64 -endif - -ifeq ($(CPU), ppc64) - MODEL = 64 -endif - -ifeq ($(CPU), powerpc64) - MODEL = 64 -endif - -MODELFLAG = -ifneq ($(MODEL),) - MODELFLAG = -m$(MODEL) -endif - -# On platforms (linux, solaris) that support both 32bit and 64bit, force building for one or the other -ifneq ($(or $(findstring linux, $(OS)), $(findstring solaris, $(OS))),) - # Change the CC/LD instead of CFLAGS/LDFLAGS, incase other things in the flags - # makes the libffi build choke - CC += $(MODELFLAG) - LD += $(MODELFLAG) -endif - -LIBTEST = $(BUILD_DIR)/$(LIBNAME) - -all: $(LIBTEST) - -$(TEST_BUILD_DIR)/%.o : $(SRC_DIR)/%.c - @mkdir -p $(@D) - $(CCACHE) $(CC) $(CFLAGS) -c $< -o $@ - -$(LIBTEST): $(TEST_OBJS) - $(CC) -o $@ $(LDFLAGS) $(TEST_OBJS) -lm - -clean:: - # nothing to do - ant will delete the build dir - -debug:: - @echo "SRCS=$(TEST_SRCS)" diff --git a/libtest/GlobalVariable.c b/libtest/GlobalVariable.c deleted file mode 100644 index 39c12a2e9..000000000 --- a/libtest/GlobalVariable.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include - -typedef int8_t s8; -typedef uint8_t u8; -typedef int16_t s16; -typedef uint16_t u16; -typedef int32_t s32; -typedef uint32_t u32; -typedef int64_t s64; -typedef uint64_t u64; -typedef signed long sL; -typedef unsigned long uL; -typedef float f32; -typedef double f64; -#if !defined(__OpenBSD__) -typedef unsigned long ulong; -#endif -typedef void* pointer; -typedef void* P; - -#define GVAR(T) \ - extern T gvar_##T; \ - T gvar_##T = (T) -1; \ - T gvar_##T##_get() { return gvar_##T; }; \ - void gvar_##T##_set(T v) { gvar_##T = v; } - -GVAR(s8); -GVAR(u8); -GVAR(s16); -GVAR(u16); -GVAR(s32); -GVAR(u32); -GVAR(s64); -GVAR(u64); -GVAR(long); -GVAR(ulong); -GVAR(pointer); - -struct gstruct { - long data; -}; - -struct gstruct gvar_gstruct = { -1 }; - -struct gstruct* -gvar_gstruct_get(void) -{ - return &gvar_gstruct; -} - -void -gvar_gstruct_set(const struct gstruct* val) -{ - gvar_gstruct = *val; -} diff --git a/libtest/LastErrorTest.c b/libtest/LastErrorTest.c deleted file mode 100644 index 02ce4a8bc..000000000 --- a/libtest/LastErrorTest.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#if defined(_WIN32) || defined(__WIN32__) -# include -#else -# include -#endif - -int setLastError(int error) { -#if defined(_WIN32) || defined(__WIN32__) - SetLastError(error); -#else - errno = error; -#endif - return -1; -} - diff --git a/libtest/NumberTest.c b/libtest/NumberTest.c deleted file mode 100644 index 3fa25a800..000000000 --- a/libtest/NumberTest.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#include -#include - -#if defined(__sparc) && defined(__sun__) - #define fix_mem_access __asm("ta 6") -#else - #define fix_mem_access -#endif - -typedef int8_t s8; -typedef uint8_t u8; -typedef int16_t s16; -typedef uint16_t u16; -typedef int32_t s32; -typedef uint32_t u32; -typedef int64_t s64; -typedef uint64_t u64; -typedef signed long sL; -typedef unsigned long uL; -typedef float f32; -typedef double f64; -typedef long double f128; -#if !defined(__OpenBSD__) -typedef unsigned long ulong; -#endif - -#define ADD(T) T add_##T(T arg1, T arg2) { return arg1 + arg2; } -#define SUB(T) T sub_##T(T arg1, T arg2) { return arg1 - arg2; } -#define MUL(T) T mul_##T(T arg1, T arg2) { return arg1 * arg2; } -#define DIV(T) T div_##T(T arg1, T arg2) { return arg1 / arg2; } -#define RET(T) T ret_##T(T arg1) { return arg1; } -#define SET(T) static T T##_;void set_##T(T arg1) { T##_ = arg1; } -#define GET(T) T get_##T() { return T##_; } -typedef char* ptr; -#define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) RET(T) SET(T) GET(T) -TEST(s8); -TEST(u8); -TEST(s16); -TEST(u16); -TEST(s32); -TEST(u32); -TEST(s64); -TEST(u64); -TEST(float); -TEST(double); -TEST(long); -TEST(ulong); -TEST(f128); - -#define ADD2(R, T1, T2) R add_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 + arg2; } -#define SUB2(R, T1, T2) R sub_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 - arg2; } -#define MUL2(R, T1, T2) R mul_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 * arg2; } -#define DIV2(R, T1, T2) R div_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 / arg2; } - -#define T2__(R, T1, T2) ADD2(R, T1, T2) SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) -#define T2_(R, T1) \ - T2__(R, T1, s8) T2__(R, T1, u8) \ - T2__(R, T1, s16) T2__(R, T1, u16) \ - T2__(R, T1, s32) T2__(R, T1, u32) \ - T2__(R, T1, sL) T2__(R, T1, uL) \ - T2__(R, T1, s64) T2__(R, T1, u64) \ - -#define TEST2(R) \ - T2_(R, s8) T2_(R, u8) T2_(R, s16) T2_(R, u16) T2_(R, s32) T2_(R, u32) \ - T2_(R, sL) T2_(R, uL) T2_(R, s64) T2_(R, u64) - -#ifdef notyet -TEST2(s32) -TEST2(u32) -TEST2(s64) -TEST2(u64) -#endif - -#define ADD3(R, T1, T2, T3) R add_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3) { return arg1 + arg2 + arg3; } -#define pack_f32(buf, v) do { float f = v; memcpy((buf), &f, sizeof(f)); } while(0) -#define pack_f64(buf, v) do { double f = v; memcpy((buf), &f, sizeof(f)); } while(0) -#define pack_int(buf, v) do { *(buf) = v; } while(0) -#define pack_s8 pack_int -#define pack_u8 pack_int -#define pack_s16 pack_int -#define pack_u16 pack_int -#define pack_s32 pack_int -#define pack_u32 pack_int -#define pack_s64 pack_int -#define pack_u64 pack_int -#define pack_sL pack_int -#define pack_uL pack_int - -#define PACK3(R, T1, T2, T3) void pack_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3, R* r) { \ - fix_mem_access; \ - pack_##T1(&r[0], arg1); \ - pack_##T2(&r[1], arg2); \ - pack_##T3(&r[2], arg3); \ -} - -#define T3___(R, T1, T2, T3) PACK3(R, T1, T2, T3) /* SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) */ -#define T3__(R, T1, T2) \ - T3___(R, T1, T2, s8) T3___(R, T1, T2, u8) \ - T3___(R, T1, T2, s16) T3___(R, T1, T2, u16) \ - T3___(R, T1, T2, s32) T3___(R, T1, T2, u32) \ - T3___(R, T1, T2, sL) T3___(R, T1, T2, uL) \ - T3___(R, T1, T2, s64) T3___(R, T1, T2, u64) \ - T3___(R, T1, T2, f32) T3___(R, T1, T2, f64) \ - -#define T3_(R, T1) \ - T3__(R, T1, s8) T3__(R, T1, u8) \ - T3__(R, T1, s16) T3__(R, T1, u16) \ - T3__(R, T1, s32) T3__(R, T1, u32) \ - T3__(R, T1, sL) T3__(R, T1, uL) \ - T3__(R, T1, s64) T3__(R, T1, u64) \ - T3__(R, T1, f32) T3__(R, T1, f64) \ - -#define TEST3(R) \ - T3_(R, s8) T3_(R, u8) T3_(R, s16) T3_(R, u16) T3_(R, s32) T3_(R, u32) \ - T3_(R, sL) T3_(R, uL) T3_(R, s64) T3_(R, u64) T3_(R, f32) T3_(R, f64) - -TEST3(s64) - -void -foo6(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5, intptr_t i6) { } - -void -foo5(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5) { } - diff --git a/libtest/PointerTest.c b/libtest/PointerTest.c deleted file mode 100644 index 7237ab20e..000000000 --- a/libtest/PointerTest.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#include -#include -#include -#include -typedef void* ptr; -typedef void* pointer; -#ifdef _WIN32 -typedef char* caddr_t; -#endif - -#define RET(T) T ptr_ret_##T(void* arg1, int offset) { \ - T tmp; memcpy(&tmp, (caddr_t) arg1 + offset, sizeof(tmp)); return tmp; \ -} -#define SET(T) void ptr_set_##T(void* arg1, int offset, T value) { \ - memcpy((caddr_t) arg1 + offset, &value, sizeof(value)); \ -} -#define TEST(T) SET(T) RET(T) - -TEST(int8_t); -TEST(int16_t); -TEST(int32_t); -TEST(int64_t); -TEST(float); -TEST(double); -TEST(pointer); - -void* -ptr_return_array_element(void **ptrArray, int arrayIndex) -{ - return ptrArray[arrayIndex]; -} - -void -ptr_set_array_element(void **ptrArray, int arrayIndex, void *value) -{ - ptrArray[arrayIndex] = value; -} - -void* -ptr_malloc(int size) -{ - return calloc(1, size); -} -void -ptr_free(void* ptr) -{ - free(ptr); -} - -void* -ptr_from_address(uintptr_t addr) -{ - return (void *) addr; -} - diff --git a/libtest/ReferenceTest.c b/libtest/ReferenceTest.c deleted file mode 100644 index d1dd88bc9..000000000 --- a/libtest/ReferenceTest.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include - -#define REF(T) void ref_##T(T arg, T* result) { *result = arg; } -#define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; } -#define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; } -#define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; } -#define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; } -#define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T) - -TEST(int8_t); -TEST(int16_t); -TEST(int32_t); -TEST(int64_t); -TEST(float); -TEST(double); - - diff --git a/libtest/StringTest.c b/libtest/StringTest.c deleted file mode 100644 index 292242bb9..000000000 --- a/libtest/StringTest.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include - -int -string_equals(const char* s1, const char* s2) -{ - return strcmp(s1, s2) == 0; -} - -void -string_set(char* s1, const char* s2) -{ - strcpy(s1, s2); -} -void -string_concat(char* dst, const char* src) -{ - strcat(dst, src); -} -void -string_dummy(char* dummy) -{ -} -const char* -string_null(void) -{ - return NULL; -} - diff --git a/libtest/StructTest.c b/libtest/StructTest.c deleted file mode 100644 index 25683d396..000000000 --- a/libtest/StructTest.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. - * Copyright (c) 2009 Andrea Fazzi . - * - * All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#include -#include -#include -#include - -typedef char s8; -typedef short s16; -typedef int s32; -typedef long long s64; -typedef float f32; -typedef double f64; - -typedef struct bugged_struct { - unsigned char visible; - unsigned int x; - unsigned int y; - short rx; - short ry; - unsigned char order; - unsigned char size; -} bugged_struct_t; - -unsigned int -bugged_struct_size() { - return sizeof(bugged_struct_t); -} - -struct test1 { - char b; - short s; - int i; - long long j; - long l; - float f; - double d; - char string[32]; -}; - -struct struct_with_array { - char c; - int a[5]; -}; - -struct nested { - int i; -}; - -struct container { - char first; - struct nested s; -}; - -int -struct_align_nested_struct(struct container* a) { return a->s.i; } - -void* -struct_field_array(struct struct_with_array* s) { return &s->a; } - -struct container* -struct_make_container_struct(int i) -{ - static struct container cs; - memset(&cs, 0, sizeof(cs)); - cs.first = 1; - cs.s.i = i; - return &cs; -} - -#define T(x, type) \ - type struct_field_##type(struct test1* t) { return t->x; } \ - struct type##_align { char first; type value; }; \ - type struct_align_##type(struct type##_align* a) { return a->value; } - -T(b, s8); -T(s, s16); -T(i, s32); -T(j, s64); -T(f, f32); -T(d, f64); -T(l, long); - -void -struct_set_string(struct test1* t, char* s) -{ - strcpy(t->string, s); -} - -struct test1* -struct_make_struct(char b, short s, int i, long long ll, float f, double d) -{ - static struct test1 t; - memset(&t, 0, sizeof(t)); - t.b = b; - t.s = s; - t.i = i; - t.j = ll; - t.f = f; - t.d = d; - return &t; -} - -typedef int (*add_cb)(int a1, int a2); -typedef int (*sub_cb)(int a1, int a2); -struct test2 { - add_cb add_callback; - sub_cb sub_callback; -}; - -int -struct_call_add_cb(struct test2* t, int a1, int a2) -{ - return t->add_callback(a1, a2); -} - -int -struct_call_sub_cb(struct test2* t, int a1, int a2) -{ - return t->sub_callback(a1, a2); -} - - -struct struct_with_array* -struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4) -{ - static struct struct_with_array s; - - memset(&s, 0, sizeof(s)); - - s.a[0] = a_0; - s.a[1] = a_1; - s.a[2] = a_2; - s.a[3] = a_3; - s.a[4] = a_4; - - return &s; - -} - -struct s8s32 { - char s8; - int s32; -}; - -struct s8s32 -struct_return_s8s32() -{ - struct s8s32 s; - s.s8 = 0x7f; - s.s32 = 0x12345678; - - return s; -} - -struct s8s32 -struct_s8s32_set(char s8, int s32) -{ - struct s8s32 s; - - s.s8 = s8; - s.s32 = s32; - - return s; -} - -int -struct_s8s32_get_s8(struct s8s32 s) -{ - return s.s8; -} - -int -struct_s8s32_get_s32(struct s8s32 s) -{ - return s.s32; -} - -struct s8s32 -struct_s8s32_ret_s8s32(struct s8s32 s) -{ - return s; -} - -// Pass a struct and an int arg, ensure the int arg is passed correctly -int -struct_s8s32_s32_ret_s32(struct s8s32 s, int s32) -{ - return s32; -} - -// Pass a struct and a long long arg, ensure the long long arg is passed correctly -long long -struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64) -{ - return s64; -} - -// Pass a struct and a long long arg, ensure the long long arg is passed correctly -int -struct_s32_ptr_s32_s8s32_ret_s32(int s32a, void *ptr, int s32b, struct s8s32 s) -{ - if (ptr != NULL) *(struct s8s32 *) ptr = s; - return s.s32; -} - -// Pass a char *, copy into buffer length struct -struct struct_string { - char *bytes; - int len; -}; - -struct struct_string -struct_varargs_ret_struct_string(int len, ...) -{ - struct struct_string ss; - va_list vl; - char* cp = NULL; - - va_start(vl, len); - - ss.len = len; - ss.bytes = va_arg(vl, char *); - if (ss.bytes != NULL) { - cp = malloc(strlen(ss.bytes) + 1); - strcpy(cp, ss.bytes); - ss.bytes = cp; - } - - va_end(vl); - - return ss; -} - diff --git a/libtest/UnionTest.c b/libtest/UnionTest.c deleted file mode 100644 index 0929a31f6..000000000 --- a/libtest/UnionTest.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#include -#include -#include - -typedef char s8; -typedef short s16; -typedef int s32; -typedef long long s64; -typedef float f32; -typedef double f64; - -typedef union union_test { - char b; - short s; - int i; - long long j; - long l; - float f; - double d; - s8 a[10]; -} union_test_t; - -#define T(x, type) \ - type union_align_##type(union_test_t* u) { return u->x; } \ - union_test_t* union_make_union_with_##type(type value) { static union_test_t u; u.x = value; return &u; } - -T(b, s8); -T(s, s16); -T(i, s32); -T(j, s64); -T(f, f32); -T(d, f64); -T(l, long); - -unsigned int union_size() { return sizeof(union_test_t); } diff --git a/libtest/VariadicTest.c b/libtest/VariadicTest.c deleted file mode 100644 index 2f3d801ba..000000000 --- a/libtest/VariadicTest.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2007 Wayne Meissner. All rights reserved. - * - * For licensing, see LICENSE.SPECS - */ - -#include -#include -#include -#include -#include - -typedef int8_t s8; -typedef uint8_t u8; -typedef int16_t s16; -typedef uint16_t u16; -typedef int32_t s32; -typedef uint32_t u32; -typedef int64_t s64; -typedef uint64_t u64; -typedef signed long sL; -typedef unsigned long uL; -typedef float F; -typedef double D; - -void pack_varargs(s64* buf, const char* fmt, ...) -{ - va_list ap; - int c; - double d; - va_start(ap, fmt); - while ((c = *fmt++)) { - switch (c) { - case 'c': - case 's': - case 'i': - *buf++ = va_arg(ap, s32); - break; - case 'l': - *buf++ = va_arg(ap, long); - break; - case 'j': - *buf++ = va_arg(ap, s64); - break; - case 'f': - case 'd': - d = va_arg(ap, double); - memcpy(buf++, &d, sizeof(d)); - break; - case 'C': - case 'S': - case 'I': - *buf++ = va_arg(ap, u32); - break; - case 'L': - *buf++ = va_arg(ap, unsigned long); - break; - } - } - va_end(ap); -} - -int pack_varargs2(s64* buf, int retval, const char* fmt, ...) -{ - va_list ap; - int c; - double d; - va_start(ap, fmt); - while ((c = *fmt++)) { - switch (c) { - case 'c': - case 's': - case 'i': - *buf++ = va_arg(ap, s32); - break; - case 'l': - *buf++ = va_arg(ap, long); - break; - case 'j': - *buf++ = va_arg(ap, s64); - break; - case 'f': - case 'd': - d = va_arg(ap, double); - memcpy(buf++, &d, sizeof(d)); - break; - case 'C': - case 'S': - case 'I': - *buf++ = va_arg(ap, u32); - break; - case 'L': - *buf++ = va_arg(ap, unsigned long); - break; - } - } - va_end(ap); - return retval + 1; -}