diff --git a/README.md b/README.md index 94d41fd..ca5564d 100644 --- a/README.md +++ b/README.md @@ -126,12 +126,12 @@ to being portable by conforming to some specification. | Stklos | X | X | | | Ypsilon | X | X | | -### Installation +## Installation Either download the latest release from -[https://git.sr.ht/~retropikzel/foreign-c/refs](https://git.sr.ht/~retropikzel/foreign-c/refs) or git clone -, preferably with a tag, and copy the _foreign_ directory to your library -directory. +[https://git.sr.ht/~retropikzel/foreign-c/refs](https://git.sr.ht/~retropikzel/foreign-c/refs) +or git clone, preferably with a tag, and copy the _foreign_ directory to your +library directory. Example assuming libraries in directory _snow_: diff --git a/documentation/foreign-c.html b/documentation/foreign-c.html index be7e230..6341993 100644 --- a/documentation/foreign-c.html +++ b/documentation/foreign-c.html @@ -337,7 +337,7 @@ Schemes - 0.10.0 -
Either download the latest release from https://git.sr.ht/~retropikzel/foreign-c/refs or git clone , preferably with a tag, and copy the @@ -540,7 +540,10 @@ make -C snow/foreign/c SCHEME_IMPLEMENTATION_NAME pointer, otherwise returns #f.
(c-free c-bytevector)
Frees c-bytevector from memory.
-(call-with-address-of)
+(call-with-address-of c-bytevector + thunk)
+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.
@@ -558,6 +561,13 @@ func(&i);The passed c-bytevector, in example named cbv, should only be used after call to call-with-addres-of ends.
+(bytevector->c-bytevector + bytevector)
+Returns a newly allocated c-bytevector of the bytes of + bytevector.
+(c-bytevector->bytevector)
+Returns a newly allocated bytevector of the bytes of + c-bytevector.
(native-endianness)
Returns the endianness symbol associated implementation’s preferred endianness (usually that of the underlying machine @@ -583,66 +593,173 @@ func(&i);
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-sint-set! bytevector +
(c-bytevector-uint-ref c-bytevector k endianness size) - (c-bytevector-sint-ref bytevector + (c-bytevector-sint-ref c-bytevector k endianness size) - (c-bytevector-uint-set! bytevector - k endianness size) - (c-bytevector-uint-ref bytevector - k endianness size)
-Size must be a positive exact integer object. If K , . . . , - k + size − 1 is not valid indices of bytevector the behavior is - unspecified.
+ (c-bytevector-uint-set! c-bytevector + k n endianness size) + (c-bytevector-sint-set! c-bytevector + k n endianness size) +Size must be a positive exact integer object. If + k,…,k + size − 1 is not valid indices + of c-bytevector the behavior is unspecified.
The c-bytevector-uint-ref procedure retrieves the exact integer object corresponding to the unsigned representation of size size and specified by endianness at indices k,…,k + size − 1.
The c-bytevector-sint-ref procedure retrieves the exact integer object corresponding to the two’s-complement - representation of size size and specified by endianness at - indices k , . . . , k + size − 1. For c-bytevector-uint-set!, n - must be an exact integer object in the interval {0, . . . , - 256size − 1}.
+ representation of size size and specified by + endianness at indices k,…,k + + size − 1. For c-bytevector-uint-set!, n must + be an exact integer object in the interval + {0,…,256^size − 1}.The c-bytevector-uint-set! procedure stores the unsigned - representation of size size and specified by endianness into - bytevector at indices k , . . . , k + size − 1.
-(c-bytevector-s16-set!) - (c-bytevector-s16-ref) - (c-bytevector-s16-native-set!) - (c-bytevector-s16-native-ref) - (c-bytevector-u16-set!) - (c-bytevector-u16-ref) - (c-bytevector-u16-native-set!) - (c-bytevector-u16-native-ref) - (c-bytevector-s32-set!) - (c-bytevector-s32-ref) - (c-bytevector-s32-native-set!) - (c-bytevector-s32-native-ref) - (c-bytevector-u32-set!) - (c-bytevector-u32-ref) - (c-bytevector-u32-native-set!) - (c-bytevector-u32-native-ref) - (c-bytevector-s64-set!) - (c-bytevector-s64-ref) - (c-bytevector-s64-native-set!) - (c-bytevector-s64-native-ref) - (c-bytevector-u64-set!) - (c-bytevector-u64-ref) - (c-bytevector-u64-native-set!) - (c-bytevector-u64-native-ref) - (c-bytevector-ieee-single-set!) - (c-bytevector-ieee-single-native-set!) - (c-bytevector-ieee-single-ref) - (c-bytevector-ieee-single-native-ref) - (c-bytevector-ieee-double-set!) - (c-bytevector-ieee-double-native-set!) - (c-bytevector-ieee-double-ref) - (c-bytevector-ieee-double-native-ref) - (bytevector->c-bytevector) - (c-bytevector->bytevector) - (string->c-utf8) - (c-utf8->string)
+ representation of size size and specified by + endianness into c-bytevector at indices + k,…,k + size − 1. +The . . . -set! procedures return unspecified values.
+Examples:
+(define cbv (make-c-bytevector (c-type-size 'int)))
+(c-bytevector-sint-set! cbv 0 100 (native-endianness) (c-type-size 'int))
+(c-bytevector-sint-ref cbv 0 (native-endianness) (c-type-size 'int))
+> 100
+ (c-bytevector-u16-ref c-bytevector + k endianness) + (c-bytevector-s16-ref c-bytevector + k endianness) + (c-bytevector-u16-native-ref + c-bytevector k) + (c-bytevector-s16-native-ref + c-bytevector k) + (c-bytevector-u16-set! c-bytevector + k n endianness) + (c-bytevector-s16-set! c-bytevector + k n endianness) + (c-bytevector-u16-native-set! + c-bytevector k n) + (c-bytevector-s16-native-set! + c-bytevector k n)
+K must be a valid index of c-bytevector ; + so must k + 1. For c-bytevector-u16-set! and + c-bytevector-u16-native-set!, n must be an exact + integer object in the interval {0,…,216 − 1}. For + c-bytevector-s16-set! and c-bytevector-s16-native-set!, + n must be an exact integer object in the interval + {−215,…,215 − 1}.
+These retrieve and set two-byte representations of numbers at + indices k and k + 1, according to the + endianness specified by endianness. The procedures with + u16 in their names deal with the unsigned representation; those + with s16 in their names deal with the two’s-complement + representation.
+The procedures with native in their names employ the native + endianness, and work only at aligned indices: k must be + a multiple of 2.
+The …-set! procedures return unspecified values.
+(c-bytevector-u32-ref c-bytevector + k endianness) + (c-bytevector-s32-ref c-bytevector + k endianness) + (c-bytevector-u32-native-ref + c-bytevector k) + (c-bytevector-s32-native-ref + c-bytevector k) + (c-bytevector-u32-set! c-bytevector + k n endianness) + (c-bytevector-s32-set! c-bytevector + k n endianness) + (c-bytevector-u32-native-set! + c-bytevector k n) + (c-bytevector-s32-native-set! + c-bytevector k n)
+K,…,k + 3 must be valid indices of + bytevector. For c-bytevector-u32-set! and + bytevector-u32-native-set!, n must be an exact integer + object in the interval {0,…,232 − 1}. For bytevector-s32-set! + and bytevector-s32-native-set!, n must be an exact + integer object in the interval {−231,…,232 − 1}.
+These retrieve and set four-byte representations of numbers + at indices k,…,k + 3, according to the + endianness specified by endianness. The procedures with + u32 in their names deal with the unsigned representation; those + with s32 with the two’s-complement representation.
+The procedures with native in their names employ the native + endianness, and work only at aligned indices: k must be + a multiple of 4.
+The …-set! procedures return unspecified values.
+(c-bytevector-u64-ref c-bytevector + k endianness) + (c-bytevector-s64-ref c-bytevector + k endianness) + (c-bytevector-u64-native-ref + c-bytevector k) + (c-bytevector-s64-native-ref + c-bytevector k) + (c-bytevector-u64-set! c-bytevector + k n endianness) + (c-bytevector-s64-set! c-bytevector + k n endianness) + (c-bytevector-u64-native-set! + c-bytevector k n) + (c-bytevector-s64-native-set! + c-bytevector k n)
+K,…,k + 7 must be valid indices of + c-bytevector. For c-bytevector-u64-set! and + c-bytevector-u64-native-set!, n must be an exact + integer object in the interval {0,…,264 − 1}. For + c-bytevector-s64-set! and c-bytevector-s64-native-set!, + n must be an exact integer object in the interval + {−263,…,264 − 1}.
+These retrieve and set eight-byte representations of numbers + at indices k,…,k + 7, according to the + endianness specified by endianness. The procedures with + u64 in their names deal with the unsigned representation; those + with s64 with the two’s-complement representation.
+The procedures with native in their names employ the native + endianness, and work only at aligned indices: k must be + a multiple of 8.
+The …-set! procedures return unspecified values.
+(c-bytevector-ieee-single-native-ref) + (c-bytevector-ieee-single-ref)
+K,…,k + 3 must be valid indices of + c-bytevector. For c-bytevector-ieee-single-native-ref, + k must be a multiple of 4.
+These procedures return the inexact real number object that + best represents the IEEE-754 single-precision number represented + by the four bytes beginning at index k.
+(c-bytevector-ieee-double-native-ref) + (c-bytevector-ieee-double-ref)
+K,…,k + 7 must be valid indices of + c-bytevector. For c-bytevector-ieee-double-native-ref, + k must be a multiple of 8.
+These procedures return the inexact real number object that + best represents the IEEE-754 double-precision number represented + by the eight bytes beginning at index k.
+(c-bytevector-ieee-single-native-set!) + (c-bytevector-ieee-single-set!)
+K,…,k + 3 must be valid indices of + c-bytevector. For c-bytevector-ieee-single-native-set!, + k must be a multiple of 4.
+These procedures store an IEEE-754 single-precision + representation of x into elements k through k + + 3 of bytevector, and return unspecified values.
+(c-bytevector-ieee-double-native-set!) + (c-bytevector-ieee-double-set!)
+K,…,k + 7 must be valid indices of + bytevector. For c-bytevector-ieee-double-native-set!, k + must be a multiple of 8.
+These procedures store an IEEE-754 double-precision + representation of x into elements k through k + + 7 of bytevector, andreturn unspecified values.
+(string->c-utf8 string)
+Returns a newly allocated (unless empty) c-bytevector that + contains the UTF-8 encoding of the given string.
+(c-utf8->string + c-bytevector)
+Returns a newly allocated (unless empty) string whose + character sequence is encoded by the given c-bytevector.
Setting environment variables like this on Windows works for this library:
diff --git a/documentation/foreign-c.pdf b/documentation/foreign-c.pdf index 73dfb0d..c86f2ed 100644 Binary files a/documentation/foreign-c.pdf and b/documentation/foreign-c.pdf differ