utils: Utility functions for working with foreign C data types

Description Usage Arguments Details Value

Description

Functions for low-level operations on C pointers as well as helper functions and objects to handle C float arrays and strings.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

Arguments

x

an R object.

n

number of elements to allocate.

offset

a offset given in bytes.

Details

is.nullptr tests if the external pointer given by x represents a C NULL pointer.

as.extptr returns an external pointer to the data area of atomic vector given by x. The external pointer holds an additional reference to the x R object to prevent it from garbage collection.

is.externalptr tests if the object given by x is an external pointer.

floatraw creates an array with a capacity to store n single-precision C float values. The array is implemented via a raw vector.

as.floatraw coerces a numeric vector into a single-precision C float vector. Values given by x are converted to C float values and stored in the R raw vector via .pack. This function is useful when calling foreign functions that expeect a C float pointer via .dyncall.

floatraw2numeric coerces a C float (raw) vector to a numeric vector.

ptr2str, strarrayptr, strptr are currently experimental.

offsetPtr creates a new external pointer pointing to x plus the byte offset. If x is given as an external pointer, the address is increased by the offset, or, if x is given as a atomic vector, the address of the data (pointing to offset zero) is taken as basis and increased by the offset. The returned external pointer is protected (as offered by the C function R_MakeExternalPtr) by the external pointer x.

Value

A logical value is returned by is.nullptr and is.externalptr. as.extptr returns an external pointer value. floatraw and as.floatraw return an atomic vector of type raw tagged with class 'floatraw'. floatraw2numeric returns a numeric atomic vector.


rdyncall documentation built on May 2, 2019, 6:15 p.m.