addrOf: Get the address of a native data instance

addrOfR Documentation

Get the address of a native data instance

Description

This function returns a pointer containing the address of the specified C-level/native data instance. This allocates a pointer and fills it with the address of the object. This is used when we want to pass the address of a C object to a C routine so that its contents can be modified by that routine. In other words, this is similar to when we pass an argument to a C routine by taking its address as foo(&obj).

The native routine R_address_of returns the address of the externalptr value, so is the address of the pointer.

Usage

addrOf(x, ...) 

Arguments

x

the reference to the native object

...

additional parameters for methods.

Value

an externalptr.

Author(s)

Duncan Temple Lang

See Also

callCIF alloc

Examples

   # We describe a struct that is defined in test.c of this package
  myStruct.type = structType(list(s = sint16Type, i = sint32Type, d = doubleType, str = stringType))

   # The routine setStructP takes the address of a pointer to a
   # MyStruct instance and then populates it. So the CIF is just a
   # pointer type and a void return type.
  cif = CIF(voidType, list(pointerType))

   # Allocate the MyStruct instance.
  ptr = alloc(myStruct.type)
   # Call the setStructP routine, but pass the address of ptr
  ans = callCIF(cif, "setStructP", ptr@ref) # addrOf(ptr))

   # Now get the contents of ptr.
   getStructValue(ptr, myStruct.type)

   ptr = alloc(myStruct.type)
   getStructValue(ptr, myStruct.type)
   # XX Fix this "naked" call to R_address_of.
   ans = callCIF(cif, "setStructPAddr", .Call("R_address_of", ptr@ref)) 
   getStructValue(ptr, myStruct.type)

omegahat/Rffi documentation built on Nov. 29, 2023, 12:48 a.m.