From fedc4cb57130c4b261d0812dec41d8fbfed05dc6 Mon Sep 17 00:00:00 2001
From: retropikzel 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. 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.Installation
+ Installation
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 73dfb0d1d5fe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