▼ |  | The Racket Foreign Interface

1 | Overview
2 | Loading Foreign Libraries
3 | C Types
4 | Pointer Functions
5 | Derived Utilities
6 | Miscellaneous Support
7 | Unexported Primitive Functions
| Bibliography
| Index

On this page:

list->cblock
vector->cblock
vector->cpointer
flvector->cpointer
saved-errno
lookup-errno
cast
cblock->list
cblock->vector

top ← prev up next →

### 6`` Miscellaneous Support

> procedure (list->cblock lst type) → any
> lst : list?
> type : ctype?

Allocates a memory block of an appropriate size, and initializes it using values from lst and the given type. The lst must hold values that can all be converted to C values according to the given type.

> procedure (vector->cblock vec type) → any
> vec : vector?
> type : type?

Like list->cblock, but for Racket vectors.

> procedure (vector->cpointer vec) → cpointer?
> vec : vector?

Returns a pointer to an array of _scheme values, which is the internal representation of vec.

> procedure (flvector->cpointer flvec) → cpointer?
> flvec : flvector?

Returns a pointer to an array of _double values, which is the internal representation of flvec.

> procedure (saved-errno) → exact-integer?

Returns the value most recently saved (in the current thread) after a foreign call with a non-#f #:save-errno option (see _fun and _cprocedure).

> procedure (lookup-errno sym) → exact-integer?
> sym : (or/c 'EINTR 'EEXIST 'EAGAIN)

Returns a platform-specific value corresponding to a Posix errno symbol. The set of supported symbols is likely to expand in the future.

> procedure (cast v from-type to-type) → any/c
> v : any/c
> from-type : ctype?
> to-type : ctype?

Converts v from a value matching from-type to a value matching to-type, where (ctype-sizeof from-type) matches (ctype-sizeof to-type).

The conversion is roughly equivalent to

> (let ([p (malloc from-type)])
> (ptr-set! p from-type v)
> (ptr-ref p to-type))

If v is a cpointer, (cpointer-gcable? v) is true, and from-type and to-type are both based on _pointer or _gcpointer, then from-type is implicitly converted with _gcable to ensure that the result cpointer is treated as referring to memory that is managed by the garbage collector.

If v is a pointer with an offset component (e.g., from ptr-add), (cpointer-gcable? v) is true, and the result is a cpointer, then the result pointer has the same offset component as v. If (cpointer-gcable? v) is false, then any offset is folded into the pointer base for the result.

> procedure (cblock->list cblock type length) → list?
> cblock : any/c
> type : ctype?
> length : exact-nonnegative-integer?

Converts C cblock, which is a vector of types, to a Racket list. The arguments are the same as in the list->cblock. The length must be specified because there is no way to know where the block ends.

> procedure (cblock->vector cblock type length) → vector?
> cblock : any/c
> type : ctype?
> length : exact-nonnegative-integer?

Like cblock->vector, but for Racket vectors.
top ← prev up next →