diff --git a/README.md b/README.md index 3fec8b0..741220e 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,9 @@ Returns **#t** if _obj_ is a null C pointer, otherwise returns **#f**. 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 diff --git a/documentation/foreign-c.html b/documentation/foreign-c.html index e0b7eec..be7e230 100644 --- a/documentation/foreign-c.html +++ b/documentation/foreign-c.html @@ -26,13 +26,71 @@ Schemes - 0.10.0
Foreign-c c-bytevector interface is copied from R6RS + bytevectors, with some added functionality for C null + pointers.
(make-c-null)
Returns a null C pointer.
(c-null? obj)
@@ -480,7 +540,30 @@ make -C snow/foreign/c SCHEME_IMPLEMENTATION_NAME pointer, otherwise returns #f.(c-free c-bytevector)
Frees c-bytevector from memory.
-(make-c-bytevector k) +
(call-with-address-of)
+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.
+Example:
+Calling from C:
+//void func(int** i);
+func(&i);
+ Calling from Scheme:
+(define cbv (make-bytevector (c-type-size 'int)))
+(call-with-address-of
+ cbv
+ (lambda (address)
+ (func address)))
+; Use cbv here
+ The passed c-bytevector, in example named cbv, should only be + used after call to call-with-addres-of + ends.
+(native-endianness)
+Returns the endianness symbol associated implementation’s + preferred endianness (usually that of the underlying machine + architecture). This may be any <endianness symbol>, + including a symbol other than big and little.
+(make-c-bytevector k) (make-c-bytevector k fill)
Returns a newly allocated c-bytevector of k @@ -490,32 +573,76 @@ make -C snow/foreign/c SCHEME_IMPLEMENTATION_NAME
If the fill argument is present, it’s value must confine to C uint8_t values , it specifies the initial value for the bytes of the c-bytevector
-(native-endianness)
-c-bytevector-s8-set! c-bytevector-s8-ref - 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-sint-set! c-bytevector-sint-ref - c-bytevector-uint-set! c-bytevector-uint-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 - call-with-address-of
-string->c-utf8 c-utf8->string
+(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.
+(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.
+(c-bytevector-sint-set! bytevector + k endianness size) + (c-bytevector-sint-ref 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.
+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}.
+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)
Setting environment variables like this on Windows works for this library:
diff --git a/documentation/foreign-c.pdf b/documentation/foreign-c.pdf index 5aa5ee9..73dfb0d 100644 Binary files a/documentation/foreign-c.pdf and b/documentation/foreign-c.pdf differ