cvsuser 04/07/05 00:29:00
Modified: io io.c
t/pmc io.t
Log:
[perl #30585] Allocating memory in PIO_reads
Since a couple of weeks, most Parrot m4 test are failing. The problem could
be boiled down to a test case, with reads from file and does a couple of
'substr' ops. The test is added in t/pmc/io.t.
The problem seemed to be that no memory is allocated in PIO_reads for the
string buffer. This can be helped by using the new function
PIO_make_io_string.
See also ticket No.30412.
Courtesy of Bernhard Schmalhofer <[EMAIL PROTECTED]>
Revision Changes Path
1.99 +3 -3 parrot/io/io.c
Index: io.c
===================================================================
RCS file: /cvs/public/parrot/io/io.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -w -r1.98 -r1.99
--- io.c 3 Jul 2004 10:48:23 -0000 1.98
+++ io.c 5 Jul 2004 07:28:50 -0000 1.99
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: io.c,v 1.98 2004/07/03 10:48:23 leo Exp $
+$Id: io.c,v 1.99 2004/07/05 07:28:50 leo Exp $
=head1 NAME
@@ -795,11 +795,11 @@
STRING *
PIO_reads(theINTERP, PMC *pmc, size_t len)
{
- STRING *res = new_string_header(interpreter, 0);
+ STRING *res = NULL;
ParrotIOLayer *l = PMC_struct_val(pmc);
ParrotIO *io = PMC_data(pmc);
- res->representation = enum_stringrep_one;
+ res = PIO_make_io_string(interpreter, &res, len );
if (!io)
return res;
1.32 +46 -2 parrot/t/pmc/io.t
Index: io.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/io.t,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- io.t 23 Jun 2004 12:42:24 -0000 1.31
+++ io.t 5 Jul 2004 07:29:00 -0000 1.32
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: io.t,v 1.31 2004/06/23 12:42:24 leo Exp $
+# $Id: io.t,v 1.32 2004/07/05 07:29:00 leo Exp $
=head1 NAME
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 27;
+use Parrot::Test tests => 28;
use Test::More;
sub file_content_is {
@@ -497,3 +497,47 @@
01234
OUTPUT
+output_is(<<'CODE', <<'OUTPUT', "multiple substr after reading from file");
+##PIR##
+.sub _main
+ # Write something into a file
+ .local pmc out
+ out = open "temp.file", ">"
+ print out, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
+ close out
+
+ .local pmc in
+ .local string line
+ in = open 'temp.file', '<'
+ line = read in, 50000
+ close in
+
+ .local string sub_1
+ sub_1 = ''
+ .local string sub_2
+ sub_2 = ''
+ .local string sub_3
+ sub_3 = ''
+ substr sub_1, line, 0, 3
+ substr sub_2, line, 0, 3, ''
+ substr sub_3, line, 0, 3, ''
+ print "line: "
+ print line
+ print "sub_1: "
+ print sub_1
+ print "\n"
+ print "sub_2: "
+ print sub_2
+ print "\n"
+ print "sub_3: "
+ print sub_3
+ print "\n"
+
+ end
+.end
+CODE
+line: 6789ABCDEFGHIJKLMNOPQRSTUVWXYZ
+sub_1: 012
+sub_2: 012
+sub_3: 345
+OUTPUT