Class in ffi::types compiler

Ptr

class Ptr
Import
use ffi::types::{Ptr};
Source: compiler/src/builtin_docs/ffi/types.hy

FFI tag for a raw pointer (void *), returned as an int address.

A Vec<T>, [T; N] or tuple type written in a declare signature also means Ptr.

As an argument, an int is passed as the address itself, and a non-empty array or tuple of int is passed as a pointer to a temporary int64_t[] copy whose changes are copied back after the call. Keep a value C retains alive with gc::root.

Examples#

use ffi::{dload, declare, invoke};
use ffi::types::{Int, Ptr};

let lib = dload("sum")?;
// int64_t sum_array(const int64_t *xs, int64_t n)
let id = declare(lib, "sum_array", (Ptr, Int), Int)?;
let n = invoke(lib, id, ([1, 2, 3, 4, 5], 5))?; // 15

See also#

  • int
  • Vec
  • gc::root
  • Int: FFI tag for a 64-bit signed integer (int64_t), passed from and returned as int.
  • Float: FFI tag for a 64-bit float (double), passed from and returned as float.
  • String: FFI tag for a NUL-terminated C string (const char *), passed from and returned as string.
  • Void: FFI tag for no value (void), valid only as a return type.
  • Bool: FFI tag for a C bool (one byte, 0 or 1), passed from and returned as bool.
↑ ↓ navigate ↵ open