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

nativesizeof routine returns the different result from sizeof function in C when it takes a CArray object as an argument. #5652

Open
p6rt opened this issue Sep 10, 2016 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Sep 10, 2016

Migrated from rt.perl.org#129240 (status was 'open')

Searchable as RT129240$

@p6rt
Copy link
Author

p6rt commented Sep 10, 2016

From @titsuki

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.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2016

From @geekosaur

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.

--
brandon s allbery kf8nh sine nomine associates
allbery.b@​gmail.com ballbery@​sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

@p6rt
Copy link
Author

p6rt commented Sep 10, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @FROGGS

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​:

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.

@p6rt p6rt added the NativeCall label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant