Skip Menu |
Report information
Id: 129240
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cookbook_000 [at] yahoo.co.jp <titsuki [at] cpan.org>
Cc:
AdminCc:

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



Subject: [NativeCall] nativesizeof routine returns the different result from sizeof function in C when it takes a CArray object as an argument.
Download (untitled) / with headers
text/plain 801b
See the following result $ perl6 -MNativeCall -e 'my $null = Pointer; my $not-null = CArray[int32].new; $not-null[0] = 1; $not-null[1] = 1; $not-null[2] = 1; say nativesizeof($not-null)' 8 I think that it should return 12, since the following equivalent C code returns 12. -- #include <stdio.h> int main() { int a[3]; a[0] = 1; a[1] = 1; a[2] = 1; printf("sizeof a: %d\n", sizeof(a)); // sizeof a: 12 } -- $ gcc --version gcc (Debian 4.9.2-10) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ perl6 --version This is Rakudo version 2016.07.1-199-gdd9b760 built on MoarVM version 2016.07-17-g40948f6 implementing Perl 6.c.
Date: Sat, 10 Sep 2016 14:52:36 -0400
To: perl6-compiler <perl6-compiler [...] perl.org>
From: Brandon Allbery <allbery.b [...] gmail.com>
CC: bugs-bitbucket [...] rt.perl.org
Subject: Re: [perl #129240] [NativeCall] nativesizeof routine returns the different result from sizeof function in C when it takes a CArray object as an argument.
Download (untitled) / with headers
text/plain 713b

On Sat, Sep 10, 2016 at 10:11 AM, Itsuki Toyota <perl6-bugs-followup@perl.org> wrote:
Show quoted text
$ perl6 -MNativeCall -e 'my $null = Pointer; my $not-null = CArray[int32].new; $not-null[0] = 1; $not-null[1] = 1; $not-null[2] = 1; say nativesizeof($not-null)'
8

That size looks doubly wrong to me. Its not going to happen for a 3-element array no matter how you slice it... so I suspect you're getting the size of one element, which is itself twice the size of what C thinks.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
From: Tobias Leich <email [...] froggs.de>
Subject: Re: [perl #129240] [NativeCall] nativesizeof routine returns the different result from sizeof function in C when it takes a CArray object as an argument.
To: perl6-bugs-followup [...] perl.org, titsuki [...] cpan.org
Date: Sun, 11 Sep 2016 10:09:15 +0200
Download (untitled) / with headers
text/plain 764b
You get 8 there because an array is a pointerish thing... Btw, this: my $not-null = CArray[int32].new is not the same as this: int a[3]; So, we would need fixed sized native arrays here to tell the truth. Am 10.09.2016 um 20:53 schrieb Brandon Allbery via RT: Show quoted text
> On Sat, Sep 10, 2016 at 10:11 AM, Itsuki Toyota < > perl6-bugs-followup@perl.org> wrote: >
>> $ perl6 -MNativeCall -e 'my $null = Pointer; my $not-null = >> CArray[int32].new; $not-null[0] = 1; $not-null[1] = 1; $not-null[2] = 1; >> say nativesizeof($not-null)' >> 8 >>
> That size looks doubly wrong to me. Its not going to happen for a 3-element > array no matter how you slice it... so I suspect you're getting the size of > one element, which is itself twice the size of what C thinks. >


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