▼ |  | 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 equivalent to

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

Beware of potential pitfalls with cast:

- If v is a pointer that refers to memory that is managed by the garbage collector, from-type and to-type normally should be based on _gcpointer, not _pointer; see also _gcable.

- If v is a pointer with an offset component (e.g., from ptr-add), the offset is folded into the pointer base for the result. Consequently, cast generally should not be used on a source pointer that refers to memory that is managed by the garbage collector and that has an offset, unless the memory is specially allocated to allow interior pointers.

> 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 →