Previous: cbuffers strings, Up: cbuffers [Index]
The API dealing with generalised C buffers and strings, is composed of syntaxes used to validate and normalise the arguments before handing them to the foreign function.
Validating generalised C buffer arguments for details on how to validation generalised C buffer arguments.
Validating generalised C string arguments for details on how to validation generalised C string arguments.
The following bindings are exported by the library (vicare
arguments general-c-buffers).
Expand to an expression which evaluates ?obj once and returns
#t if the result is a generalised C string.
Expand to an expression which evaluates ?obj once and returns
#t if the result is a generalised C buffer.
Expand to an expression which evaluates ?obj once and returns
#t if the result is a generalised C sticky buffer.
Assume that buf and str have already been validated as general C buffer and general C string; validate len as valid length of buffer or string.
When successful: nothing happens. If the validation fails: raise an
exception using procedure-arguments-consistency-violation. The
argument who is used for the condition of type &who.
Return the number of bytes in a generalised C buffer object.
buf must be a bytevector, pointer object or memory-block
struct instance.
When buf is a pointer object: buf.len must be an exact
integer (in the range of the C language type size_t) representing
the number of bytes available in the referenced memory block. Otherwise
buf.len is ignored.
Prepare some generalised C strings to be used by a chunk of code expecting access to raw memory holding a C language string or input buffer.
The values ?str must be identifiers, unique according to
bound-identifier=?.
The values ?expr must be expressions which will always be evaluated only once.
The value ?string->bytevector must be an expression evaluating to
a procedure which converts a string to a bytevector, for example
string->ascii. In the second form of the syntax use:
?string->bytevector defaults to string->ascii.
For each couple ?str and ?expr do the following:
memory-block instance bind it to ?str.
Evaluate the ?body forms in the region in which such bindings are effective. Return the return value of the last ?body form.
Like with-general-c-strings but if a ?expr evaluates
to #f accept the value.
Prepare some generalised C strings to be used by a chunk of code expecting access to raw memory holding a C language string representing a file system pathname.
The values ?ptn must be identifiers, unique according to
bound-identifier=?.
The values ?expr must be expressions which will always be evaluated only once.
For each couple ?ptn and ?expr do the following:
memory-block instance bind it to ?ptn.
string->pathname-func, then bind it to ?ptn.
Evaluate the ?body forms in the region in which such bindings are effective. Return the return value of the last ?body form.
Like with-general-c-pathnames but if a ?expr evaluates to
#f accept the value.
As example, let’s say we have loaded C language code exposing a function
ikptr_posix_file_size(), which given a file pathname returns its
size; we can interface it as follows:
#!r6rs
(import (vicare)
(vicare arguments validation))
(define (file-size pathname)
(define who 'file-size)
(with-arguments-validation (who)
((general-c-string pathname))
(with-general-c-pathnames ((pathname^ pathname))
(foreign-call "ikptr_posix_file_size" pathname^))))
Previous: cbuffers strings, Up: cbuffers [Index]