Skip Menu |
Report information
Id: 131311
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: curt [at]

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)

From: Curt Tilmes <curt [...]>
To: rakudobug [...]
Date: Sat, 13 May 2017 22:06:35 -0400
Subject: [BUG] Embedded CStruct/CUnions incorrectly considered undefined when defined, but 0
Download (untitled) / with headers
text/plain 1.1k
If I have embedded (with 'HAS', not referenced with 'has') CStruct or CUnions, and set
the first field in the embedded struct to a 0 (looks like a NULL pointer?)
I get an incorrect error message about the struct being a 'type object' (undefined)

Perhaps easiest to demonstrate with an example:

$ cat foo.h
#include <inttypes.h>

typedef struct foo {
    struct {
        uint64_t a;
    } data;
} foo_t;

extern void fill_foo(foo_t *f, uint64_t a);
$ cat foo.c
#include "foo.h"

void fill_foo(foo_t *f, uint64_t a)
    f->data.a = a;
$ gcc -c -Wall -Werror -fpic foo.c
$ gcc -shared -o foo.o
$ perl6 -v
This is Rakudo version 2017.04.3-47-gf0414c4 built on MoarVM version 2017.04-44-gf0db882
implementing Perl 6.c.
$ cat 
use v6;

use NativeCall;

class data is repr('CStruct') {
    has uint64 $.a;

class foo is repr('CStruct') {
    HAS data $.data;

sub fill_foo(foo, uint64) is native('foo') {*}

my $foo =;

fill_foo($foo, 27);

say $;   # Works fine, data looks 'defined'

fill_foo($foo, 0);

say $;   # Error, data looks 'undefined'?
$ perl6 
Cannot look up attributes in a data type object
  in block <unit> at line 23

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at