Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded CStruct/CUnions incorrectly considered undefined when defined, but 0 #6249

Open
p6rt opened this issue May 14, 2017 · 2 comments
Open
Labels

Comments

@p6rt
Copy link

p6rt commented May 14, 2017

Migrated from rt.perl.org#131311 (status was 'new')

Searchable as RT131311$

@p6rt
Copy link
Author

p6rt commented May 14, 2017

From curt@tilmes.org

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

@p6rt p6rt added the Bug label Jan 5, 2020
@dogbert17
Copy link

Seems to work now:

dogbert@dogbert-VirtualBox ~ $ perl6 -v
This is Rakudo version 2020.05.1-285-g8134470 built on MoarVM version 2020.05-85-g02c8cf7
implementing Raku 6.d.
dogbert@dogbert-VirtualBox ~ $ perl6 gist.pl6 
27
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants