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

Doing split on the result of a slurped empty file results in a Null PMC Access in rakudo #268

Closed
p6rt opened this issue Aug 20, 2008 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Aug 20, 2008

Migrated from rt.perl.org#58150 (status was 'resolved')

Searchable as RT58150$

@p6rt
Copy link
Author

p6rt commented Aug 20, 2008

From @masak

r30374​:
$ echo -n > empty
$ < empty ./perl6 -e 'say $*IN.slurp' # works, empty line

$ < empty ./perl6 -e 'say $*IN.slurp.WHAT' # yes
Str
$ < empty ./perl6 -e 'say $*IN.slurp.perl' # yes
""
$ $ < empty ./perl6 -e 'say split("\n", "a\nb\nc").perl' # this works too
["a", "b", "c"]
$ < empty ./perl6 -e 'say split("\n", $*IN.slurp)' # but this fails
Null PMC access in get_integer()
[...]
Segmentation fault

@p6rt
Copy link
Author

p6rt commented Aug 23, 2008

From @ronaldxs

$ < empty ./perl6 -e 'say split("\n", $*IN.slurp)' # but this fails
Null PMC access in get_integer()
[...]
Segmentation fault

The following variation of your script may provide some insight into
the problem​:

< empty ./perl6 -e 'my $x = ""; my $y = $*IN.slurp; if $x eq $y {
say "both empty"; } ; say split("\n", $x); say "split simple empty
str"; say split("\n", $y);'

The script outputs when run​:
both empty

split simple empty str
Null PMC access in get_integer()
[ ... ]
Segmentation Fault

@p6rt
Copy link
Author

p6rt commented Aug 23, 2008

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

@p6rt
Copy link
Author

p6rt commented Aug 29, 2008

From @ronaldxs

$ < empty ./perl6 -e 'say split("\n", $*IN.slurp)' # but this fails

Two proposed patches attached. The patch to src/pmc/parrotiio.pmc seems
to fix the problem as originally stated. Then the patch to
languages/perl6/src/classes/Str.pir seems to fix 'say
$*IN.slurp.split("\n")'. If you have any questions please ask.

Ron

@p6rt
Copy link
Author

p6rt commented Aug 29, 2008

From @ronaldxs

fix_empty_io.patch
Index: src/pmc/parrotio.pmc
===================================================================
--- src/pmc/parrotio.pmc	(revision 30637)
+++ src/pmc/parrotio.pmc	(working copy)
@@ -307,7 +307,7 @@
                 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
                     "Cannot slurp from empty filehandle");
 
-            result = NULL;
+            result = string_make_empty(INTERP, enum_stringrep_one, 0);
 
             do {
                 STRING * const part = PIO_reads(INTERP, SELF, 4096);
Index: languages/perl6/src/classes/Str.pir
===================================================================
--- languages/perl6/src/classes/Str.pir	(revision 30637)
+++ languages/perl6/src/classes/Str.pir	(working copy)
@@ -46,7 +46,7 @@
     .return(retv)
 .end
 
-.sub 'split' :method :multi('Perl6Str')
+.sub 'split' :method
     .param string delim
     .local string objst
     .local pmc pieces

@p6rt
Copy link
Author

p6rt commented Aug 30, 2008

From @masak

---------- Forwarded message ----------
From​: Ron Schmidt via RT <perl6-bugs-followup@​perl.org>
Date​: Fri, Aug 29, 2008 at 10​:14 PM
Subject​: [perl #​58150] Doing split on the result of a slurped empty
file results in a Null PMC Access in rakudo
To​: cmasak@​gmail.com

$ < empty ./perl6 -e 'say split("\n", $*IN.slurp)' # but this fails

Two proposed patches attached. The patch to src/pmc/parrotiio.pmc seems
to fix the problem as originally stated. Then the patch to
languages/perl6/src/classes/Str.pir seems to fix 'say
$*IN.slurp.split("\n")'. If you have any questions please ask.

Ron

@p6rt
Copy link
Author

p6rt commented Aug 30, 2008

From @masak

fix_empty_io.patch
Index: src/pmc/parrotio.pmc
===================================================================
--- src/pmc/parrotio.pmc	(revision 30637)
+++ src/pmc/parrotio.pmc	(working copy)
@@ -307,7 +307,7 @@
                 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
                     "Cannot slurp from empty filehandle");
 
-            result = NULL;
+            result = string_make_empty(INTERP, enum_stringrep_one, 0);
 
             do {
                 STRING * const part = PIO_reads(INTERP, SELF, 4096);
Index: languages/perl6/src/classes/Str.pir
===================================================================
--- languages/perl6/src/classes/Str.pir	(revision 30637)
+++ languages/perl6/src/classes/Str.pir	(working copy)
@@ -46,7 +46,7 @@
     .return(retv)
 .end
 
-.sub 'split' :method :multi('Perl6Str')
+.sub 'split' :method
     .param string delim
     .local string objst
     .local pmc pieces

@p6rt
Copy link
Author

p6rt commented Sep 11, 2008

From @jnthn

On Fri Aug 29 13​:14​:19 2008, ronaldxs wrote​:

$ < empty ./perl6 -e 'say split("\n", $*IN.slurp)' # but this fails

Two proposed patches attached. The patch to src/pmc/parrotiio.pmc seems
to fix the problem as originally stated. Then the patch to
languages/perl6/src/classes/Str.pir seems to fix 'say
$*IN.slurp.split("\n")'. If you have any questions please ask.

Thanks for the patches! The first one to ParrotIO, I fully agree with so
I have applied it in r30981 (if you slurp an empty file, the empty
string would seem a much more sensible and predictable result than a
NULL string, which suggests something went wrong with the read). And
this fixes the test that was originally submitted for this ticket. :-)

The second patch was not quite correct - we need to have it :multi for
when we implement the regex variant. I changed it to​:

.sub 'split' :method :multi('String')

So it's a bit more liberal about what sorts of strings it gets for now.

Thanks!

Jonathan

@p6rt
Copy link
Author

p6rt commented Sep 11, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 11, 2008
@p6rt
Copy link
Author

p6rt commented Sep 11, 2008

From @pmichaud

On Thu, Sep 11, 2008 at 05​:34​:14AM -0700, jnthn@​jnthn.net via RT wrote​:

The second patch was not quite correct - we need to have it :multi for
when we implement the regex variant. I changed it to​:

.sub 'split' :method :multi('String')

So it's a bit more liberal about what sorts of strings it gets for now.

Not only that, but split needs to go into Any so that we can
split on things that aren't strings yet (i.e., by stringifying
the invocant).

Pm

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

No branches or pull requests

1 participant