Commits

Anonymous committed d749543

added a test for int-args

Comments (0)

Files changed (5)

 
 - it would be handy to also handle structs
 
+- better handling of types with no direct equivalent in go (short,void,...)
 
 Documentation
 -------------
 var (
 	Void       = Type{&C.ffi_type_void}
 	Uchar      = Type{&C.ffi_type_uchar}
-	Schar      = Type{&C.ffi_type_schar}
+	Char       = Type{&C.ffi_type_schar}
 	Ushort     = Type{&C.ffi_type_ushort}
-	Sshort     = Type{&C.ffi_type_sshort}
+	Short      = Type{&C.ffi_type_sshort}
 	Uint       = Type{&C.ffi_type_uint}
-	Sint       = Type{&C.ffi_type_sint}
+	Int        = Type{&C.ffi_type_sint}
 	Ulong      = Type{&C.ffi_type_ulong}
-	Slong      = Type{&C.ffi_type_slong}
+	Long       = Type{&C.ffi_type_slong}
 	Uint8      = Type{&C.ffi_type_uint8}
-	Sint8      = Type{&C.ffi_type_sint8}
+	Int8       = Type{&C.ffi_type_sint8}
 	Uint16     = Type{&C.ffi_type_uint16}
-	Sint16     = Type{&C.ffi_type_sint16}
+	Int16      = Type{&C.ffi_type_sint16}
 	Uint32     = Type{&C.ffi_type_uint32}
-	Sint32     = Type{&C.ffi_type_sint32}
+	Int32      = Type{&C.ffi_type_sint32}
 	Uint64     = Type{&C.ffi_type_uint64}
-	Sint64     = Type{&C.ffi_type_sint64}
+	Int64      = Type{&C.ffi_type_sint64}
 	Float      = Type{&C.ffi_type_float}
 	Double     = Type{&C.ffi_type_double}
 	LongDouble = Type{&C.ffi_type_longdouble}
 	return out.Elem(), nil
 }
 
-type go_void struct {}
+type go_void struct{}
 
 func rtype_from_ffi(t *C.ffi_type) reflect.Type {
 	switch t {

pkg/ffi/ffi_darwin_test.go

 package ffi_test
 
+var libc_name = "libc.dylib"
 var libm_name = "libm.dylib"
 
 // EOF

pkg/ffi/ffi_linux_test.go

 package ffi_test
 
+var libc_name = "libc.so.6"
 var libm_name = "libm.so"
 
 // EOF
 	res float64 // expected value
 }
 
-func TestFFIMath(t *testing.T) {
+func TestFFIMathf(t *testing.T) {
 	lib, err := ffi.NewLibrary(libm_name)
 
 	if err != nil {
 	}
 }
 
+func TestFFIMathi(t *testing.T) {
+	lib, err := ffi.NewLibrary(libm_name)
+
+	if err != nil {
+		t.Errorf("%v", err)
+	}
+
+	f, err := lib.Fct("abs", ffi.Int, []ffi.Type{ffi.Int})
+	if err != nil {
+		t.Errorf("could not locate function [abs]: %v", err)
+	}
+	{
+		out := f(10).Int()
+		if out != 10 {
+			t.Errorf("expected [10], got [%v] (fct=abs(10))", out)
+		}
+
+	}
+	{
+		out := f(-10).Int()
+		if out != 10 {
+			t.Errorf("expected [10], got [%v] (fct=abs(-10))", out)
+		}
+
+	}
+
+	err = lib.Close()
+	if err != nil {
+		t.Errorf("error closing [%s]: %v", libm_name, err)
+	}
+}
+
 // EOF