Re: run() not capturing exitcode properly?

2017-05-29 Thread Gabor Szabo
On Tue, May 30, 2017 at 7:21 AM, Gabor Szabo  wrote:
>> my $p = run "ls", "dadsad", :out, :err;
> Proc.new(in => IO::Pipe, out => IO::Pipe.new(:path(""),:chomp), err =>
> IO::Pipe.new(:path(""),:chomp), exitcode => 0, signal => 0, command =>
> ["ls", "dadsad", "adadsa"])
>>
>> $p.exitcode
> 0
>
>
> While for the same command in the shell   $? will hold 1 as the
> directory does not exist.
>
> Is this a bug or am I misunderstanding something?
>
> This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
> implementing Perl 6.c.
>
> Running on OSX.
>
> Gabor

On the other hand if I try to access the captured output or error, an
exception is raised:

> $p.out.slurp: :close;
The spawned command 'ls' exited unsuccessfully (exit code: 1)
  in block  at  line 1\


Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
Thank you!

On Mon, May 29, 2017 at 6:47 PM, Elizabeth Mattijsen  wrote:

>
> > On 29 May 2017, at 17:33, Fernando Santagata 
> wrote:
> >
> > On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:
> > > On 29 May 2017, at 11:22, Fernando Santagata <
> nando.santag...@gmail.com> wrote:
> > >
> > > /me sighs: NQP is still so poorly documented!
> >
> > Believe it or not, this is documented in nqp/docs/ops.markdown in the
> section under stat.
> >
> > That is not under https://docs.perl6.org/, I presume.
>
> No, as it is specific to the Rakudo / nqp implementation of Perl 6.
>
> You can find it here in rendered format:
>
>   https://github.com/perl6/nqp/blob/master/docs/ops.markdown
>
>
>
> Liz




-- 
Fernando Santagata


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen

> On 29 May 2017, at 17:33, Fernando Santagata  
> wrote:
> 
> On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:
> > On 29 May 2017, at 11:22, Fernando Santagata  
> > wrote:
> >
> > /me sighs: NQP is still so poorly documented!
> 
> Believe it or not, this is documented in nqp/docs/ops.markdown in the section 
> under stat.
> 
> That is not under https://docs.perl6.org/, I presume.

No, as it is specific to the Rakudo / nqp implementation of Perl 6.

You can find it here in rendered format:

  https://github.com/perl6/nqp/blob/master/docs/ops.markdown



Liz

Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:

> > On 29 May 2017, at 11:22, Fernando Santagata 
>> wrote:
>> >
>> > /me sighs: NQP is still so poorly documented!
>>
>
> Believe it or not, this is documented in nqp/docs/ops.markdown in the
> section under stat.
>

That is not under https://docs.perl6.org/, I presume.

-- 
Fernando Santagata


Nativecall and CArray

2017-05-29 Thread Fernando Santagata
Hello,

I'm trying to encapsulate a C struct, one member of which is an array of
pointers to structs, and I'm having some problems to figure out how to do
it.

I tried to follow the hint in the documentation
https://docs.perl6.org/language/nativecall#Structs

use NativeCall;

class A is repr('CStruct') {
  has uint8 $.u8;
}

class B is repr('CStruct') {
  has CArray[A] $.a;
  submethod TWEAK {
my $arr := CArray[A].new;
for ^5 { $arr[$_] = A.new(u8 => $_) }
$!a := $arr;
  }
}

sub MAIN
{
  my B $b .= new;
  say $b.a[2];
  say 'Size of $b: ' ~ nativesizeof($b);
}

but this way the resulting size is of one pointer, 8 bytes (on my
computer), while what I'm trying to get is a size of 5 pointers, 40 bytes.

Obviously I can do this:

use NativeCall;

class A is repr('CStruct') {
  has uint8 $.u8;
}

class C is repr('CStruct') {
  has A $.a1;
  has A $.a2;
  has A $.a3;
  has A $.a4;
  has A $.a5;
}

sub MAIN
{
  my C $c .= new;
  say nativesizeof($c);
}

which returns the size I need. Yet this solution hurts my feelings :-)

Is there any other way to do it, without resorting to this:

https://stackoverflow.com/questions/43544931/passing-an-array-of-structures-to-a-perl-6-nativecall-function

(Which is presented as "enough rope to -hang yourself- *build a workaround*
")

-- 
Fernando Santagata


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen
Perhaps Zoffix is willing to take a PR for an IO::Path.nlinks method as part of 
the IO grant.

> On 29 May 2017, at 11:22, Fernando Santagata  
> wrote:
> 
> /me sighs: NQP is still so poorly documented!
> 
> On Mon, May 29, 2017 at 11:10 AM, Brent Laabs  wrote:
> This works without a module on Rakudo:
> 
> use nqp;
> my $path = "foo".IO;
> my $hardlink-count =  nqp::stat($path.absolute, 
> nqp::const::STAT_PLATFORM_NLINKS);
> 
> 
> 
> 
> On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen  wrote:
> > On 29 May 2017, at 10:42, Fernando Santagata  
> > wrote:
> >
> > The three files are already hard-linked, no need for soft links.
> >
> > BTW, is there a way to detect hard links in Perl6?
> > Perl5 "stat" operator returns an array whose fourth element is the number 
> > of hard links of a file, but I don't see anything like that in the Perl6 
> > docs.
> 
> Generally, unixisms are not directly supported in Perl 6 in the core.  It 
> should be relatively trivial to create an ecosystem module for this using 
> NativeCall directly accessing functionality in libc (which then of course 
> won’t work on Windows).
> 
> 
> Liz
> 
> 
> 
> 
> -- 
> Fernando Santagata


Re: zef, zef-j, zef-m

2017-05-29 Thread Brent Laabs
This works without a module on Rakudo:

use nqp;
my $path = "foo".IO;
my $hardlink-count =  nqp::stat($path.absolute,
nqp::const::STAT_PLATFORM_NLINKS);




On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen  wrote:

> > On 29 May 2017, at 10:42, Fernando Santagata 
> wrote:
> >
> > The three files are already hard-linked, no need for soft links.
> >
> > BTW, is there a way to detect hard links in Perl6?
> > Perl5 "stat" operator returns an array whose fourth element is the
> number of hard links of a file, but I don't see anything like that in the
> Perl6 docs.
>
> Generally, unixisms are not directly supported in Perl 6 in the core.  It
> should be relatively trivial to create an ecosystem module for this using
> NativeCall directly accessing functionality in libc (which then of course
> won’t work on Windows).
>
>
> Liz


Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
The three files are already hard-linked, no need for soft links.

BTW, is there a way to detect hard links in Perl6?
Perl5 "stat" operator returns an array whose fourth element is the number
of hard links of a file, but I don't see anything like that in the Perl6
docs.

On Sun, May 28, 2017 at 5:31 PM, Parrot Raiser <1parr...@gmail.com> wrote:

> If they are really identical, might it be an idea to use symbolic
> links for 2 of them?
> That would reduce the code to be stored, maintained, and transmitted,
> and make it blatantly obvious if different versions are required.
>
> On 5/28/17, Nelo Onyiah  wrote:
> > I presume that's j for JVM and m for MoarVM.
> >
> > On 28 May 2017 2:42 pm, "Gabor Szabo"  wrote:
> >
> >> Hi,
> >>
> >> I've just noticed that in /Applications/Rakudo/share/perl6/site/bin/ I
> >> have 3 copies
> >> of every script. One with a -j and one with a -m at the end just as for
> >> zef:
> >>
> >> zef
> >> zef-j
> >> zef-m
> >>
> >> The files seem to be identical.
> >>
> >> Why are there 3 and what is their purpose?
> >>
> >> Gabor
> >>
> >
>



-- 
Fernando Santagata