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 passes- 10
A CStruct's attributes are read fresh from native memory, so a method reading
$!fieldsees 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 passes- 1
A live
CArray, such as one read back from aCStructfield, 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 passes- 4
A native int array's
.WHATisarray[int].
More from this test: Hashes & sets (1), I/O & processes (1), Lists & laziness (1), Strings & Unicode (1).
carray-type-identityRaku++ passesRakudo passes- 1
A
CArray[int32]value reports and type-checks asCArray[int32].isa-ok($c, CArray[int32])passes
dbdish-native-and-list-defectsRaku++ passesRakudo passes- 1
is nativemay be applied to a method. - 2
A CPointer class can be an
is rwout-parameter of a native sub.sqlite3_open'ssqlite3**argument - 3
CStruct field types may be spelled through a
constantalias. - 4
Pointer.ofisvoid. - 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 passes- 6
A
CStructclass with no attributes is refused.
More from this test: Compile-time errors (5).
ecosweep-batch-fiveRaku++ passesRakudo passes- 3
A
CArray[Str]field of a CStruct reads its elements as strings, and the NULL terminator reads back as an undefined Str. - 4
A native sub's
--> Treturn 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 passes- 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 bywhen X::AdHoc - 5
is native(LIB)resolves LIB in the declaring module, and an undefined library means the default namespace. - 7
cglobalaccepts a sub that returns the library, and aStrglobal 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 it- 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 asCArray[uint8]isAlso held by
carray-types.
exe-native-loop-headerRaku++ passesRakudo cannot run it- 2
A
my int $ideclared in aloopheader is still a nativeintthat wraps after the loop.
exe-nfc-join-and-destructureRaku++ passesRakudo cannot run it- 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 passes- 2
%anddivon two native ints floor,int.min div -1wraps, and a zero divisor is refused. - 5
A native num stored into an
intconverts 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 passes- 1
A native call fills a CArray or a Buf that reached it through
|@argsor|$capture, as through a slurpy wrapper that calls$native(|@arguments).
More from this test: Containers & assignment (1).
librarycheck-native-roleRaku++ passesRakudo passes- 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 passes- 1
eqvon tworepr('CStruct')instances compares their scalar fields and does not compare pointer fields. - 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 pass- 2
$*VM.platform-library-nameturns a library path stem into the platform's file name.$*VM.platform-library-name("…/lib/x")is"…/lib/libx.<ext>" - 3
is native(&sub)resolves the library by calling the sub. - 4
A native sub declared as returning
Strgives the C string as a RakuStr.
More from this test: Modules (1).
native-array-element-storesRaku++ passesRakudo passes- 1
@a[$i] = vinto a nativeint/num/strarray converts the value or throws an X::TypeCheck naming the element.@a[0] = Truestores 1, 300 into anint8is 44, and@a[0] = 1.5into anintarray dies - 2
On a native array element
+=and||=convert or refuse the value as an unbox, and++/--wrap at the element's width. - 3
A slice assignment
@a[0, 1] = …into a native array coerces each value through.Int,.Numor.Str. - 4
pushandunshiftof a value a native array cannot hold throw an X::TypeCheck naming the operation, whileappend,prependandsplicerefuse it as an unbox.@a.push(1)on anumarray is refused - 5
An
intarray takes an Int that fits (a Bool as 0 or 1, an IntStr or an enum as its Int) wrapped to its width, anumarray takes a Num (num32rounds), astrarray takes a Str, and a big Int is too wide except in a step. - 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 it- 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_bufcan read the buffer after the call - 2
is symbol(EXPR)accepts a computed expression, evaluated at the native sub's first call rather than at its declaration. - 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 - 5
Nilpassed for aStrparameter 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 passes- 1
A store into a native
int/num/strarray element through an alias of it (:=, a sigilless name, afortopic,is rw,<->,given/with, anis rw/is raw/\aparameter, a list assignment) converts or refuses as a store through the element itself does.my $x := @n[1]; $x = 1.5dies;for @i8 { $_ = 300 }leaves 44;Truestores 1 - 2
An assignment through an alias of a native array element answers the value the element holds afterwards.
($x = -1)is255for auint8element - 3
Storing
Nil,Anyor a Str into a native element or native variable is refused as an unbox, also via@n[0] ||= Nil,&&= Nil,$i ||= Nil,$i .= Strand$i = $ywith$yholding Any.
native-int-arith-wrapsRaku++ passesRakudo passes- 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 passes- 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-nativeholds its Num - 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 passes- 1
is native(EXPR)accepts any expression, such as a constant holding%?RESOURCES<libraries/sha1>, besides a string literal,Stror&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 it- 2
is nativenaming 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 passes- 1
An Int no machine word holds, bound to a native integer parameter (
atomicintincluded), is refused with the messagemy int $x = …gives: the width is the value's bit length, and it endsDid you mix int and Int or literals?.2**70 is reported as 71 bits wide
native-refuses-other-numeric-kindRaku++ passesRakudo passes- 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/2andmy int $c = 7/2dieAlso held by
native-int-num-convert. - 2
The native-kind refusal holds for sized natives (
int8,num32,uint8), a later=, compound operators, list assignment, and anis rwparameter written inside the routine.$i /= 2on a native int dies - 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/2stores the RatAlso held by
native-int-arith-wraps. - 4
$i ** -1on a native int is the native candidate and answers an Int.$i ** -1on a native int is0
native-return-carray-paramRaku++ passesRakudo passes- 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 passes- 1
A class forward-declared with a representation,
class FT_Library is repr('CPointer') {...}, keeps that representation when its body is declared later. - 2
A
constantalias of a native type is resolved in a native signature, so a parameter declaredFT_Int is rwafterconstant FT_Int = int32is a native scalar that is written back. - 3
A native
Pointer is rwwrite-back keeps the element type of thePointer[T]argument the caller passed. - 4
.derefon aPointer[T]whoseTis a native class answers an instance ofT, not a raw Int.
nativecall-c-integer-aliasesRaku++ passesRakudo passes- 1
NativeCall's C integer spellings
long,ulong,longlong,ulonglong,size_t,ssize_tandboolare 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 = 0is accepted
nativecall-cache-and-rw-pointerRaku++ passesRakudo passes- 2
A
Pointer is rwparameter of a native sub passes the address of a slot and receives a live Pointer back.sqlite3_open'ssqlite3**argument yields a usable handle
nativecall-carray-elementsRaku++ passesRakudo passes- 1
Assigning to an element of a
CArray,$carray[$i] = v, writes native memory and leaves the object aCArray, which a native function receives as a pointer. - 2
CArrayelements of pointer-like types (Pointer,Str, a nestedCArray) occupy a machine pointer each. - 3
Reading a pointer-typed
CArrayelement gives something that can itself be subscripted, so$out[0][^$n]reads the buffer whose address a native call stored there. - 4
A Range or list subscript on a
CArrayslices it.
nativecall-carray-of-cstructRaku++ passesRakudo passes- 1
Each slot of a
CArrayof 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'sGError ** - 2
C reads the structs stored into a
CArrayof a CStruct class, and a stored struct reads back as itself. - 3
.allocateon aCArrayof a CStruct class fills each slot with a fresh zeroed struct. - 4
A CArray's
.rakuand.gistdescribe the CArray object rather than dumping its bytes. inferred
nativecall-featuresRaku++ passesRakudo does not pass- 1
An
is rwparameter of a native sub passes a pointer to the value, and what C writes there is copied back into the variable. - 2
A native sub accepts mixed integer and floating-point arguments in either order.
- 3
nativecastreinterprets a native value as another type, andcglobalreads a global variable of a C library. inferred - 4
Pointersupports.new,.deref,.definedand the typed formPointer[T]. inferred - 5
Reading a
CArrayelement reads live native memory, for byte-backed and native-allocated arrays alike.
nativecall-has-inline-structRaku++ passesRakudo passes- 1
HAS Inner $.inin 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
A plain
has Inner $.inmember in a CStruct stores a pointer to the inner struct.
More from this test: divergences (1).
nativecall-libffiRaku++ passesRakudo cannot run it- 1
A NativeCall sub passes and returns
num32values as C floats. - 2
A NativeCall sub may declare a large number of integer arguments, seventeen included.
- 3
In a NativeCall signature
*@argsmarks where C's variadic...arguments begin. - 4
NativeCall callbacks may be typed with Pointer parameters and have any arity.
nativecall-names-and-null-fieldsRaku++ passesRakudo passes- 1
For NativeCall types,
.^nameand a type object's.rakucarry theNativeCall::Typespackage. - 2
A NULL
PointerorCArrayfield of a CStruct reads as the type object. - 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
An element of a
CArray[Pointer]is a Pointer, NULL included. - 5
A Pointer's
.gistand.rakuname theNativeCall::Typespackage.
nativecall-struct-callbackRaku++ passesRakudo passes- 1
A class with
is repr('CStruct')has native layout:.newallocates native memory, its fields read and write, and a C function can fill it.gettimeofdayfills a struct whose fields are then readable - 2
A Raku sub passed to a native function becomes a C function pointer that is invoked synchronously, and a
CArrayargument reflects what C wrote.qsortwith a Raku comparator sorts aCArray
nativecall-types-and-versioned-cglobalRaku++ passesRakudo passes- 1
use NativeCall::Typesloads as a compilation unit of its own. - 2
cglobalaccepts a(name, version)list as its library, the formis nativetakes, and resolves it to the versioned library name rather than stringifying the list.cglobal(('freetype', v6), …)does not ask for a library literally namedfreetype 6
nativecall-void-and-exportsRaku++ passesRakudo passes- 1
voidis a NativeCall type name and parameterisesPointerandCArray, soPointer[void]is the Cvoid *. - 2
The qualified spellings
NativeCall::Types::void,NativeCall::Types::Pointerand the like resolve to the same types as the short names, including inside a parameterisation. - 3
NativeCall provides
refreshandexplicitly-manage, andguess_library_nameandcheck_routine_sanityunder their qualified names. - 4
CArray[T].ofanswers the element typeT. - 5
nativecast(Pointer, $carray)on a CArray answers the array's real, non-null address. - 6
cglobal(Str, …)with theStrtype object as the library looks the symbol up in the running program.
nativecast-of-a-routineRaku++ passesRakudo does not pass- 1
nativecast(Pointer, &some-sub)is refused; a function pointer comes only from a declared callback parameter.
opaquepointer-is-pointerRaku++ passesRakudo passes- 1
NativeCall's
OpaquePointeris another name forPointer.OpaquePointer === Pointer
pointer-is-realRaku++ passesRakudo passes- 1
abs $pon a NativeCall Pointer is its address as an Int. - 2
$p + 1,$p == $qand$p cmp $qanswer for NativeCall Pointers.
More from this test: divergences (1).
pointer-numeric-is-intRaku++ passesRakudo passes- 1
A NativeCall Pointer is numerically its address, an Int.
0 + $pand$p + 1are Ints
runtime-built-signatureRaku++ passesRakudo does not pass- 3
nativecast($signature, $ptr)answers a Callable that calls the function at that pointer. - 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 it- 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] = 42makes$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 pass- 9
Assigning to
$!fieldinside a method of arepr('CStruct')class writes the native field. - 26
Pointer.succsteps a typed pointer by one element and keeps its type, andPointer.add(n)steps it by n elements.for a
Pointer[uint16]overCArray[uint16].new(10, 20, 30),.succ.derefis20and.add(2).derefis30 - 27
CArray[uint8].new($blob)takes the Blob's bytes as its elements.CArray[uint8].new("abc".encode).elemsis3
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 passes- 3
An
intloop parameter is a native, so+past int64 wraps and** -1is 0, where anIntone does neither.
More from this test: Signatures & dispatch (2).
zero-dep-module-sweepRaku++ passesRakudo passes- 1
NativeCall's container types are valid return types, as in
--> CArrayand--> CArray[uint8].
More from this test: Regexes & grammars (1), Syntax & parsing (3).