Raku Cases › Native types & NativeCall

Native types & NativeCall

Native ints, nums and arrays, and calling C.

104 rules from 47 tests. 35 of those tests are confirmed on both engines: Raku++ and Rakudo 2026.11 both pass, or Raku++ gives Rakudo's answer on every probe of a family. The verdict is the test's, not each rule's. How to read a case.

anton-batch-round2Raku++ passesRakudo passes2026-08-28 · 2421c094
  1. 10

    A CStruct's attributes are read fresh from native memory, so a method reading $!field sees what C wrote.

More from this test: Hashes & sets (3), Classes, roles & the MOP (2), Regexes & grammars (3), Signatures & dispatch (1).

at-param-binding-nonpositionalRaku++ passesRakudo passes2026-10-06 · 7b3bb3cf
  1. 1

    A live CArray, such as one read back from a CStruct field, binds to an @ parameter as the Positional it is, both positionally (sub f(@a)) and by name (sub f(:@a)).

More from this test: Classes, roles & the MOP (1), Signatures & dispatch (1).

audited-language-gaps-3Raku++ passesRakudo passes2026-10-04 · 74895f1e
  1. 4

    A native int array's .WHAT is array[int].

More from this test: Hashes & sets (1), I/O & processes (1), Lists & laziness (1), Strings & Unicode (1).

carray-type-identityRaku++ passesRakudo passes2026-08-04 · 6385d398
  1. 1

    A CArray[int32] value reports and type-checks as CArray[int32].

    isa-ok($c, CArray[int32]) passes

dbdish-native-and-list-defectsRaku++ passesRakudo passes2026-08-25 · 5faed01f · #28
  1. 1

    is native may be applied to a method.

  2. 2

    A CPointer class can be an is rw out-parameter of a native sub.

    sqlite3_open's sqlite3** argument

  3. 3

    CStruct field types may be spelled through a constant alias.

  4. 4

    Pointer.of is void.

  5. 5

    A CArray[Str] owns the strings stored in it, so they stay valid for native code. inferred

More from this test: Containers & assignment (2), Lists & laziness (1), Classes, roles & the MOP (3), Regexes & grammars (3), Signatures & dispatch (1), Syntax & parsing (2).

declarations-rakudo-refusesRaku++ passesRakudo passes2026-11-14 · 8f7ac1df · rakudo#2673
  1. 6

    A CStruct class with no attributes is refused.

More from this test: Compile-time errors (5).

ecosweep-batch-fiveRaku++ passesRakudo passes2026-08-25 · 6879a71b
  1. 3

    A CArray[Str] field of a CStruct reads its elements as strings, and the NULL terminator reads back as an undefined Str.

  2. 4

    A native sub's --> T return type may be a constant aliasing a CStruct class.

    my constant GrpAlias = GrpProbe; sub my-getgrgid2(uint32 --> GrpAlias) is native is symbol<getgrgid> { * } returns a struct

More from this test: Hashes & sets (1), Classes, roles & the MOP (2), Operators (1), Regexes & grammars (1), Scoping & phasers (2), Signatures & dispatch (4), Syntax & parsing (1), Types & coercion (2).

ecosweep-batch-threeRaku++ passesRakudo passes2026-08-24 · 298866e3
  1. 4

    Calling a native sub whose library cannot be found throws X::AdHoc.

    sub nope(--> int32) is native('no-such-library-xyz') { * }; nope() is caught by when X::AdHoc

  2. 5

    is native(LIB) resolves LIB in the declaring module, and an undefined library means the default namespace.

  3. 7

    cglobal accepts a sub that returns the library, and a Str global is read as the C string it points to.

    cglobal(&L, 'gsl_version', Str) is a version string

More from this test: Hashes & sets (1), Classes, roles & the MOP (1).

exe-carray-c-int-paramRaku++ passesRakudo cannot run it2026-11-14 · 901a4cca · #261
  1. 2

    A parametric type takes an argument that is a lowercase C type name (CArray[size_t]) or a value held in a variable (CArray[$T], Array[$T], Buf[$U]) and answers the parameterized type.

    CArray[size_t] is a parameterized type as CArray[uint8] is

    Also held by carray-types.

exe-native-loop-headerRaku++ passesRakudo cannot run it2026-10-24 · d0ba733b
  1. 2

    A my int $i declared in a loop header is still a native int that wraps after the loop.

exe-nfc-join-and-destructureRaku++ passesRakudo cannot run it2026-10-22 · 3e97932e
  1. 3

    != between an unsigned native integer and a negative signed one is False.

More from this test: Strings & Unicode (1).

exe-outer-step-native-opsRaku++ passesRakudo passes2026-10-24 · 42f79e98
  1. 2

    % and div on two native ints floor, int.min div -1 wraps, and a zero divisor is refused.

  2. 5

    A native num stored into an int converts toward zero, saturating, with NaN as 0, while a boxed Num is refused.

More from this test: Exceptions & control flow (3).

issue-174-native-buffer-through-flatteningRaku++ passesRakudo passes2026-10-18 · 8e82287e · #174
  1. 1

    A native call fills a CArray or a Buf that reached it through |@args or |$capture, as through a slurpy wrapper that calls $native(|@arguments).

More from this test: Containers & assignment (1).

librarycheck-native-roleRaku++ passesRakudo passes2026-09-13 · f3aa6cb1
  1. 1

    $sub does NativeCall::Native[$sub, $soname] turns a plain sub into a native call, and calling it throws "Cannot locate native library" when the library is absent and a different error when it is present.

math-sparsematrix-installRaku++ passesRakudo passes2026-08-31 · b165e3b8
  1. 1

    eqv on two repr('CStruct') instances compares their scalar fields and does not compare pointer fields.

  2. 6

    Assigning to an element of a live CArray reached through an accessor (self.values[$i] = …) writes the native memory. inferred

More from this test: Lists & laziness (1), Classes, roles & the MOP (1), Operators (2).

native-and-resourcesRaku++ passesRakudo does not pass2026-07-24 · 21e46c1a
  1. 2

    $*VM.platform-library-name turns a library path stem into the platform's file name.

    $*VM.platform-library-name("…/lib/x") is "…/lib/libx.<ext>"

  2. 3

    is native(&sub) resolves the library by calling the sub.

  3. 4

    A native sub declared as returning Str gives the C string as a Raku Str.

More from this test: Modules (1).

native-array-element-storesRaku++ passesRakudo passes2026-10-24 · 960e8aed
  1. 1

    @a[$i] = v into a native int/num/str array converts the value or throws an X::TypeCheck naming the element.

    @a[0] = True stores 1, 300 into an int8 is 44, and @a[0] = 1.5 into an int array dies

  2. 2

    On a native array element += and ||= convert or refuse the value as an unbox, and ++/-- wrap at the element's width.

  3. 3

    A slice assignment @a[0, 1] = … into a native array coerces each value through .Int, .Num or .Str.

  4. 4

    push and unshift of a value a native array cannot hold throw an X::TypeCheck naming the operation, while append, prepend and splice refuse it as an unbox.

    @a.push(1) on a num array is refused

  5. 5

    An int array takes an Int that fits (a Bool as 0 or 1, an IntStr or an enum as its Int) wrapped to its width, a num array takes a Num (num32 rounds), a str array takes a Str, and a big Int is too wide except in a step.

  6. 6

    A refused store into a native array leaves the array as it was, unless the store grew it.

native-buffer-symbol-and-nullRaku++ passesRakudo cannot run it2026-08-15 · 42283242
  1. 1

    A Blob passed to a native function is passed as a pointer that stays valid after the call returns, so a C function that retains it reads the Blob's bytes.

    BIO_new_mem_buf can read the buffer after the call

  2. 2

    is symbol(EXPR) accepts a computed expression, evaluated at the native sub's first call rather than at its declaration.

  3. 4

    A native function declared to return a repr('CStruct') class returns the type object when C returns NULL.

    unless my $s = SSL_load_client_CA_file(…) fires on NULL

  4. 5

    Nil passed for a Str parameter of a native sub is marshalled as NULL.

    ERR_error_string($e, Nil) passes a NULL buffer

More from this test: Classes, roles & the MOP (1).

native-element-aliasesRaku++ passesRakudo passes2026-10-24 · 273863ac
  1. 1

    A store into a native int/num/str array element through an alias of it (:=, a sigilless name, a for topic, is rw, <->, given/with, an is rw/is raw/\a parameter, a list assignment) converts or refuses as a store through the element itself does.

    my $x := @n[1]; $x = 1.5 dies; for @i8 { $_ = 300 } leaves 44; True stores 1

  2. 2

    An assignment through an alias of a native array element answers the value the element holds afterwards.

    ($x = -1) is 255 for a uint8 element

  3. 3

    Storing Nil, Any or a Str into a native element or native variable is refused as an unbox, also via @n[0] ||= Nil, &&= Nil, $i ||= Nil, $i .= Str and $i = $y with $y holding Any.

native-int-arith-wrapsRaku++ passesRakudo passes2026-09-29 · f8d0821a
  1. 1

    Integer arithmetic whose operands are both native ints (a variable declared int, a native operation, or an integer literal that fits 64 bits beside one) is the native candidate and wraps at 64 bits; everywhere else it is Int arithmetic and grows.

native-int-num-convertRaku++ passesRakudo passes2026-09-29 · 87252930
  1. 1

    A store from one native into a native of the other kind converts: a native int into a native num holds its Num, and a native num into a native int truncates toward zero, saturates, and makes NaN 0.

    my num $n = $an-int-native holds its Num

  2. 3

    An operation mixing a native int and a native num ($int * $num) is native, a literal is native only beside a native of its own kind, and / is never native.

native-lib-expression-and-resourcesRaku++ passesRakudo passes2026-07-30 · e8582ba6 · #13
  1. 1

    is native(EXPR) accepts any expression, such as a constant holding %?RESOURCES<libraries/sha1>, besides a string literal, Str or &sub.

    constant SHA1 = %?RESOURCES<libraries/sha1>; … is native( SHA1 ) loads that library

More from this test: Modules (1).

native-library-folded-into-libsystemRaku++ passesRakudo cannot run it2026-09-11 · cc95e49f
  1. 2

    is native naming a library that does not exist is an error when the routine is called, never a silent fallback to another library's symbol.

More from this test: divergences (1).

native-param-bigint-widthRaku++ passesRakudo passes2026-10-15 · b7c47a57
  1. 1

    An Int no machine word holds, bound to a native integer parameter (atomicint included), is refused with the message my int $x = … gives: the width is the value's bit length, and it ends Did you mix int and Int or literals?.

    2**70 is reported as 71 bits wide

native-refuses-other-numeric-kindRaku++ passesRakudo passes2026-09-29 · 5366241a
  1. 1

    A native int container takes an Int (a Bool and an Int enum are Ints) and a native num takes a Num; any other boxed number assigned or bound at run time dies with X::AdHoc.

    my num $a = 1/2 and my int $c = 7/2 die

    Also held by native-int-num-convert.

  2. 2

    The native-kind refusal holds for sized natives (int8, num32, uint8), a later =, compound operators, list assignment, and an is rw parameter written inside the routine.

    $i /= 2 on a native int dies

  3. 3

    A value copied from a native variable into a boxed container carries no native restriction, so the container can then hold any number.

    after my $n = $an-int, $n = 1/2 stores the Rat

    Also held by native-int-arith-wraps.

  4. 4

    $i ** -1 on a native int is the native candidate and answers an Int.

    $i ** -1 on a native int is 0

native-return-carray-paramRaku++ passesRakudo passes2026-09-16 · d11767e8
  1. 1

    A native sub's return type --> CArray[Str] keeps its element parameter, so each slot is decoded as a string rather than read as an address.

nativecall-alias-repr-derefRaku++ passesRakudo passes2026-09-13 · 9e3d5183
  1. 1

    A class forward-declared with a representation, class FT_Library is repr('CPointer') {...}, keeps that representation when its body is declared later.

  2. 2

    A constant alias of a native type is resolved in a native signature, so a parameter declared FT_Int is rw after constant FT_Int = int32 is a native scalar that is written back.

  3. 3

    A native Pointer is rw write-back keeps the element type of the Pointer[T] argument the caller passed.

  4. 4

    .deref on a Pointer[T] whose T is a native class answers an instance of T, not a raw Int.

nativecall-c-integer-aliasesRaku++ passesRakudo passes2026-10-14 · 68e623b6
  1. 1

    NativeCall's C integer spellings long, ulong, longlong, ulonglong, size_t, ssize_t and bool are native integer types that take an Int as a parameter's argument and as a typed constant's value.

    our ulong constant ulong_zero is export = 0 is accepted

nativecall-cache-and-rw-pointerRaku++ passesRakudo passes2026-07-30 · 15150303
  1. 2

    A Pointer is rw parameter of a native sub passes the address of a slot and receives a live Pointer back.

    sqlite3_open's sqlite3** argument yields a usable handle

nativecall-carray-elementsRaku++ passesRakudo passes2026-07-25 · 7b3448d6
  1. 1

    Assigning to an element of a CArray, $carray[$i] = v, writes native memory and leaves the object a CArray, which a native function receives as a pointer.

  2. 2

    CArray elements of pointer-like types (Pointer, Str, a nested CArray) occupy a machine pointer each.

  3. 3

    Reading a pointer-typed CArray element gives something that can itself be subscripted, so $out[0][^$n] reads the buffer whose address a native call stored there.

  4. 4

    A Range or list subscript on a CArray slices it.

nativecall-carray-of-cstructRaku++ passesRakudo passes2026-10-09 · a5489fb6 · #136
  1. 1

    Each slot of a CArray of a CStruct class is a pointer to a struct: a NULL slot reads as the type object and a slot C filled reads as a struct.

    CArray[N-Error] is C's GError **

  2. 2

    C reads the structs stored into a CArray of a CStruct class, and a stored struct reads back as itself.

  3. 3

    .allocate on a CArray of a CStruct class fills each slot with a fresh zeroed struct.

  4. 4

    A CArray's .raku and .gist describe the CArray object rather than dumping its bytes. inferred

nativecall-featuresRaku++ passesRakudo does not pass2026-07-24 · bacbcb1a
  1. 1

    An is rw parameter of a native sub passes a pointer to the value, and what C writes there is copied back into the variable.

  2. 2

    A native sub accepts mixed integer and floating-point arguments in either order.

  3. 3

    nativecast reinterprets a native value as another type, and cglobal reads a global variable of a C library. inferred

  4. 4

    Pointer supports .new, .deref, .defined and the typed form Pointer[T]. inferred

  5. 5

    Reading a CArray element reads live native memory, for byte-backed and native-allocated arrays alike.

nativecall-has-inline-structRaku++ passesRakudo passes2026-09-02 · f9405eb3
  1. 1

    HAS Inner $.in in a CStruct lays the member struct out in place: the outer size and member offsets account for its width and alignment, and the accessor is a view onto those bytes, so writes through it land in the outer struct.

  2. 2

    A plain has Inner $.in member in a CStruct stores a pointer to the inner struct.

More from this test: divergences (1).

nativecall-libffiRaku++ passesRakudo cannot run it2026-08-02 · 05d2adce
  1. 1

    A NativeCall sub passes and returns num32 values as C floats.

  2. 2

    A NativeCall sub may declare a large number of integer arguments, seventeen included.

  3. 3

    In a NativeCall signature *@args marks where C's variadic ... arguments begin.

  4. 4

    NativeCall callbacks may be typed with Pointer parameters and have any arity.

nativecall-names-and-null-fieldsRaku++ passesRakudo passes2026-10-10 · 0c3540cf · #136
  1. 1

    For NativeCall types, .^name and a type object's .raku carry the NativeCall::Types package.

  2. 2

    A NULL Pointer or CArray field of a CStruct reads as the type object.

  3. 3

    A CArray stored in a CStruct field keeps its length when read back, and what is read back still writes through to the shared memory.

  4. 4

    An element of a CArray[Pointer] is a Pointer, NULL included.

  5. 5

    A Pointer's .gist and .raku name the NativeCall::Types package.

nativecall-struct-callbackRaku++ passesRakudo passes2026-07-24 · 46d03f38
  1. 1

    A class with is repr('CStruct') has native layout: .new allocates native memory, its fields read and write, and a C function can fill it.

    gettimeofday fills a struct whose fields are then readable

  2. 2

    A Raku sub passed to a native function becomes a C function pointer that is invoked synchronously, and a CArray argument reflects what C wrote.

    qsort with a Raku comparator sorts a CArray

nativecall-types-and-versioned-cglobalRaku++ passesRakudo passes2026-09-13 · 1df1693b
  1. 1

    use NativeCall::Types loads as a compilation unit of its own.

  2. 2

    cglobal accepts a (name, version) list as its library, the form is native takes, and resolves it to the versioned library name rather than stringifying the list.

    cglobal(('freetype', v6), …) does not ask for a library literally named freetype 6

nativecall-void-and-exportsRaku++ passesRakudo passes2026-09-02 · f9405eb3 · #57
  1. 1

    void is a NativeCall type name and parameterises Pointer and CArray, so Pointer[void] is the C void *.

  2. 2

    The qualified spellings NativeCall::Types::void, NativeCall::Types::Pointer and the like resolve to the same types as the short names, including inside a parameterisation.

  3. 3

    NativeCall provides refresh and explicitly-manage, and guess_library_name and check_routine_sanity under their qualified names.

  4. 4

    CArray[T].of answers the element type T.

  5. 5

    nativecast(Pointer, $carray) on a CArray answers the array's real, non-null address.

  6. 6

    cglobal(Str, …) with the Str type object as the library looks the symbol up in the running program.

nativecast-of-a-routineRaku++ passesRakudo does not pass2026-09-10 · 03454ac8
  1. 1

    nativecast(Pointer, &some-sub) is refused; a function pointer comes only from a declared callback parameter.

opaquepointer-is-pointerRaku++ passesRakudo passes2026-10-05 · 7fff03ca
  1. 1

    NativeCall's OpaquePointer is another name for Pointer.

    OpaquePointer === Pointer

pointer-is-realRaku++ passesRakudo passes2026-10-03 · 4e56e5e5
  1. 1

    abs $p on a NativeCall Pointer is its address as an Int.

  2. 2

    $p + 1, $p == $q and $p cmp $q answer for NativeCall Pointers.

More from this test: divergences (1).

pointer-numeric-is-intRaku++ passesRakudo passes2026-10-03 · 7afa7e62
  1. 1

    A NativeCall Pointer is numerically its address, an Int.

    0 + $p and $p + 1 are Ints

runtime-built-signatureRaku++ passesRakudo does not pass2026-09-14 · 25552063 · #84
  1. 3

    nativecast($signature, $ptr) answers a Callable that calls the function at that pointer.

  2. 4

    cglobal($lib, 'f', Pointer) answers the symbol's address rather than dereferencing it.

More from this test: Signatures & dispatch (2).

top100-four-roots-2026-09-02Raku++ passesRakudo cannot run it2026-09-02 · 3f24e005
  1. 4

    A nativecast(CArray[uint8], $buf) view shares storage with a Buf that was grown by index assignment, so writes through the view show in the Buf.

    after my $b = buf8.new; $b[1023] = 1, writing $view[0] = 42 makes $b[0] 42

More from this test: Lists & laziness (1), Modules (1), Operators (1), Everything else (1).

top100-roots-2026-09-02Raku++ passesRakudo does not pass2026-09-02 · 7af75847
  1. 9

    Assigning to $!field inside a method of a repr('CStruct') class writes the native field.

  2. 26

    Pointer.succ steps a typed pointer by one element and keeps its type, and Pointer.add(n) steps it by n elements.

    for a Pointer[uint16] over CArray[uint16].new(10, 20, 30), .succ.deref is 20 and .add(2).deref is 30

  3. 27

    CArray[uint8].new($blob) takes the Blob's bytes as its elements.

    CArray[uint8].new("abc".encode).elems is 3

More from this test: Containers & assignment (1), Exceptions & control flow (2), Lists & laziness (1), Modules (1), Numerics (1), Classes, roles & the MOP (4), Regexes & grammars (3), Scoping & phasers (1), Stringification (1), Strings & Unicode (2), Syntax & parsing (3), Types & coercion (6).

typed-for-counted-rangeRaku++ passesRakudo passes2026-10-24 · 07775af3
  1. 3

    An int loop parameter is a native, so + past int64 wraps and ** -1 is 0, where an Int one does neither.

More from this test: Signatures & dispatch (2).

zero-dep-module-sweepRaku++ passesRakudo passes2026-07-30 · 75f59c3e
  1. 1

    NativeCall's container types are valid return types, as in --> CArray and --> CArray[uint8].

More from this test: Regexes & grammars (1), Syntax & parsing (3).