diff --git a/README.md b/README.md index c483507..a62e6d9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ to being portable by conforming to some specification. [Maling lists](https://sr.ht/~retropikzel/foreign-c/lists) +[Jenkins](https://jenkins.scheme.org/job/foreign_c/job/foreign-c/) + - [Installation](#installation) - [Documentation](#documentation) - [Types](#types) @@ -295,21 +297,21 @@ Example: (define-c-procedure qsort libc-stdlib 'qsort 'void '(pointer int int callback)) ; Define our callback - (pffi-define-callback compare + (define-c-callback compare 'int '(pointer pointer) (lambda (pointer-a pointer-b) - (let ((a (pffi-pointer-get pointer-a 'int 0)) - (b (pffi-pointer-get pointer-b 'int 0))) + (let ((a (c-bytevector-sint-get pointer-a (native-endianness) 0)) + (b (c-bytevector-sint-get pointer-b (native-endianness) 0))) (cond ((> a b) 1) ((= a b) 0) ((< a b) -1))))) ; Create new array of ints to be sorted (define array (make-c-bytevector (* (c-type-size 'int) 3))) - (pffi-pointer-set! array 'int (* (c-type-size 'int) 0) 3) - (pffi-pointer-set! array 'int (* (c-type-size 'int) 1) 2) - (pffi-pointer-set! array 'int (* (c-type-size 'int) 2) 1) + (c-bytevector-s32-native-set! array (* (c-type-size 'int) 0) 3) + (c-bytevector-s32-native-set! array (* (c-type-size 'int) 1) 2) + (c-bytevector-s32-native-set! array (* (c-type-size 'int) 2) 1) (display array) (newline) @@ -564,10 +566,11 @@ encoded by the given c-bytevector. Setting environment variables like this on Windows works for this library: - set "PFFI_LOAD_PATH=C:\Program Files (x86)/foo/bar" + set "FOREIGN_C_LOAD_PATH=C:\Program Files (x86)/foo/bar" -#### PFFI\_LOAD\_PATH +#### FOREIGN_C_\_LOAD\_PATH -To add more paths to where pffi looks for libraries set PFFI\_LOAD\_PATH to -paths separated by ; on windows, and : on other operating systems. +To add more paths to where foreign c looks for libraries set +FOREIGN_C\_LOAD\_PATH to paths separated by ; on windows, and : on other +operating systems. diff --git a/documentation/foreign-c.html b/documentation/foreign-c.html index 6341993..8cf73ac 100644 --- a/documentation/foreign-c.html +++ b/documentation/foreign-c.html @@ -112,7 +112,7 @@ Schemes - 0.10.0 - c-size-of + c-type-size c-bytevector-u8-set! c-bytevector-u8-ref define-c-library @@ -338,9 +338,9 @@ Schemes - 0.10.0

Installation

-

Either download the latest release from Eithe download the latest release from https://git.sr.ht/~retropikzel/foreign-c/refs - or git clone , preferably with a tag, and copy the + or git clone, preferably with a tag, and copy the foreign directory to your library directory.

Example assuming libraries in directory snow:

git clone https://git.sr.ht/~retropikzel/foreign-c --branch LATEST_VERSION
@@ -503,36 +503,36 @@ make -C snow/foreign/c SCHEME_IMPLEMENTATION_NAME
(define-c-procedure qsort libc-stdlib 'qsort 'void '(pointer int int callback)) ; Define our callback -(pffi-define-callback compare +(define-c-callback compare 'int '(pointer pointer) (lambda (pointer-a pointer-b) - (let ((a (pffi-pointer-get pointer-a 'int 0)) - (b (pffi-pointer-get pointer-b 'int 0))) + (let ((a (c-bytevector-sint-get pointer-a (native-endianness) 0)) + (b (c-bytevector-sint-get pointer-b (native-endianness) 0))) (cond ((> a b) 1) ((= a b) 0) ((< a b) -1))))) ; Create new array of ints to be sorted -(define array (make-c-bytevector (* (c-size-of 'int) 3))) -(pffi-pointer-set! array 'int (* (c-size-of 'int) 0) 3) -(pffi-pointer-set! array 'int (* (c-size-of 'int) 1) 2) -(pffi-pointer-set! array 'int (* (c-size-of 'int) 2) 1) +(define array (make-c-bytevector (* (c-type-size 'int) 3))) +(c-bytevector-s32-native-set! array (* (c-type-size 'int) 0) 3) +(c-bytevector-s32-native-set! array (* (c-type-size 'int) 1) 2) +(c-bytevector-s32-native-set! array (* (c-type-size 'int) 2) 1) (display array) (newline) ;> (3 2 1) ; Sort the array -(qsort array 3 (c-size-of 'int) compare) +(qsort array 3 (c-type-size 'int) compare) (display array) (newline) ;> (1 2 3)

c-bytevector

Foreign-c c-bytevector interface is copied from R6RS - bytevectors, with some added functionality for C null - pointers.

+ bytevectors, with some added functionality for C null pointers + and manual memory management.

(make-c-null)

Returns a null C pointer.

(c-null? obj)

@@ -545,8 +545,8 @@ make -C snow/foreign/c SCHEME_IMPLEMENTATION_NAME

Calls thunk with address pointer of c-bytevector.

Since the support for calling C functions taking pointer - address arguments, the ones you would prefix with &, varies, - some additional ceremony is needed on the Scheme side.

+ address arguments, ones prefixrd with & in C, varies, some + additional ceremony is needed on the Scheme side.

Example:

Calling from C:

//void func(int** i);
@@ -585,14 +585,16 @@ func(&i);
the bytes of the c-bytevector

(c-bytevector-s8-set! c-bytevector k byte)

-

If K is not a valid index of c-bytevector the behaviour is - undefined.

-

Stores the byte in element k of c-bytevector.

+

If k is not a valid index of c-bytevector the + behaviour is undefined.

+

Stores the byte in element k of + c-bytevector.

(c-bytevector-s8-ref c-bytevector - k byte)

-

If K is not a valid index of c-bytevector the behaviour is - undefined.

-

Returns the byte at index k of c-bytevector.

+ k)

+

If k is not a valid index of c-bytevector the + behaviour is undefined.

+

Returns the byte at index k of + c-bytevector.

(c-bytevector-uint-ref c-bytevector k endianness size)
(c-bytevector-sint-ref c-bytevector @@ -763,10 +765,10 @@ func(&i);

Environment variables

Setting environment variables like this on Windows works for this library:

-
set "PFFI_LOAD_PATH=C:\Program Files (x86)/foo/bar"
-

PFFI_LOAD_PATH

-

To add more paths to where pffi looks for libraries set - PFFI_LOAD_PATH to paths separated by ; on windows, and : on +

set "FOREIGN_C_LOAD_PATH=C:\Program Files (x86)/foo/bar"
+

FOREIGN_C__LOAD_PATH

+

To add more paths to where foreign c looks for libraries set + FOREIGN_C_LOAD_PATH to paths separated by ; on windows, and : on other operating systems.

diff --git a/documentation/foreign-c.pdf b/documentation/foreign-c.pdf index c86f2ed..1e613d6 100644 Binary files a/documentation/foreign-c.pdf and b/documentation/foreign-c.pdf differ