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

Owner: Nobody
Requestors: curt [at] tilmes.org
Cc:
AdminCc:

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



From: Curt Tilmes <curt [...] tilmes.org>
To: rakudobug [...] perl.org
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 libfoo.so 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 fooperl.pl 
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 = foo.new;

fill_foo($foo, 27);

say $foo.data.a;   # Works fine, data looks 'defined'

fill_foo($foo, 0);

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



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

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