cvsuser 04/05/28 05:45:06
Modified: classes parrotio.pmc
io io.c io_layers.c io_private.h
t/pmc io.t
Log:
io_layers 8 - implement layer pop; test
Revision Changes Path
1.22 +9 -1 parrot/classes/parrotio.pmc
Index: parrotio.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/parrotio.pmc,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -r1.21 -r1.22
--- parrotio.pmc 24 May 2004 13:46:48 -0000 1.21
+++ parrotio.pmc 28 May 2004 12:44:55 -0000 1.22
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: parrotio.pmc,v 1.21 2004/05/24 13:46:48 leo Exp $
+$Id: parrotio.pmc,v 1.22 2004/05/28 12:44:55 leo Exp $
=head1 NAME
@@ -180,6 +180,10 @@
Push the layer name C<value> onto the PIO's layer stack.
+=item C<STRING* pop_string ()>
+
+Pop a layer off the PIO's layer stack. Returns the layer name.
+
=cut
*/
@@ -187,6 +191,10 @@
void push_string (STRING* value) {
PIO_push_layer_str(INTERP, SELF, value);
}
+
+ STRING* pop_string () {
+ return PIO_pop_layer_str(INTERP, SELF);
+ }
}
/*
1.92 +1 -4 parrot/io/io.c
Index: io.c
===================================================================
RCS file: /cvs/public/parrot/io/io.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -w -r1.91 -r1.92
--- io.c 25 May 2004 08:34:21 -0000 1.91
+++ io.c 28 May 2004 12:44:59 -0000 1.92
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: io.c,v 1.91 2004/05/25 08:34:21 leo Exp $
+$Id: io.c,v 1.92 2004/05/28 12:44:59 leo Exp $
=head1 NAME
@@ -719,9 +719,6 @@
*/
-/* temporary */
-void Parrot_string_downscale(Interp *interpreter, STRING *s,
- parrot_string_representation_t representation);
STRING *
PIO_reads(theINTERP, PMC *pmc, size_t len)
1.4 +31 -1 parrot/io/io_layers.c
Index: io_layers.c
===================================================================
RCS file: /cvs/public/parrot/io/io_layers.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- io_layers.c 24 May 2004 13:46:44 -0000 1.3
+++ io_layers.c 28 May 2004 12:44:59 -0000 1.4
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: io_layers.c,v 1.3 2004/05/24 13:46:44 leo Exp $
+$Id: io_layers.c,v 1.4 2004/05/28 12:44:59 leo Exp $
=head1 NAME
@@ -89,6 +89,11 @@
Push a layer onto an IO object (C<*pmc>) or the default stack.
+=item C<void
+PIO_push_layer_str(theINTERP, PMC *pmc, STRING *layer_name)>
+
+Push a layer onto an IO object (C<*pmc>).
+
=cut
*/
@@ -177,6 +182,12 @@
Pop a layer from an IO object (C<*pmc>) or the default stack.
+=item C<STRING *
+PIO_pop_layer_str(theINTERP, PMC *pmc)>
+
+Pop a layer from an IO object (C<*pmc>) and return the name of the
+popped layer. The layer gets freed.
+
=cut
*/
@@ -190,6 +201,12 @@
if (!PMC_IS_NULL(pmc)) {
if (!io)
return 0;
+ /*
+ * if this is a global layer create a copy first
+ */
+ if (!(io->stack->flags & PIO_L_LAYER_COPIED)) {
+ io->stack = PIO_copy_stack(io->stack);
+ }
layer = io->stack;
if (layer) {
io->stack = layer->down;
@@ -219,6 +236,19 @@
return 0;
}
+STRING *
+PIO_pop_layer_str(Interp *interpreter, PMC *pmc)
+{
+ ParrotIOLayer *layer;
+ STRING *ls;
+
+ layer = PIO_pop_layer(interpreter, pmc);
+ ls = string_make(interpreter, layer->name, strlen(layer->name),
+ "iso-8859-1", 0);
+ mem_sys_free(layer);
+ return ls;
+}
+
/*
=item C<ParrotIOLayer *
1.14 +2 -1 parrot/io/io_private.h
Index: io_private.h
===================================================================
RCS file: /cvs/public/parrot/io/io_private.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- io_private.h 25 May 2004 19:19:19 -0000 1.13
+++ io_private.h 28 May 2004 12:44:59 -0000 1.14
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: io_private.h,v 1.13 2004/05/25 19:19:19 dan Exp $
+$Id: io_private.h,v 1.14 2004/05/28 12:44:59 leo Exp $
=head1 NAME
@@ -261,6 +261,7 @@
ParrotIOLayer * PIO_utf8_register_layer(void);
void PIO_push_layer_str(Interp *interpreter, PMC *pmc, STRING *ls);
+STRING* PIO_pop_layer_str(Interp *interpreter, PMC *pmc);
#endif /* PARROT_IO_PRIVATE_H_GUARD */
1.28 +22 -2 parrot/t/pmc/io.t
Index: io.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/io.t,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -w -r1.27 -r1.28
--- io.t 19 May 2004 12:44:15 -0000 1.27
+++ io.t 28 May 2004 12:45:06 -0000 1.28
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: io.t,v 1.27 2004/05/19 12:44:15 leo Exp $
+# $Id: io.t,v 1.28 2004/05/28 12:45:06 leo Exp $
=head1 NAME
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 24;
+use Parrot::Test tests => 25;
use Test::More;
sub file_content_is {
@@ -431,3 +431,23 @@
CODE
/^(unix|win32|stdio)-buf-buf-\1--$/
OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "layer push, pop");
+ getstdin P0
+ push P0, "utf8"
+ set S0, P0[-1]
+ print S0
+ print "\n"
+ pop S1, P0
+ print S1
+ print "\n"
+ set S0, P0[-1]
+ print S0
+ print "\n"
+ end
+CODE
+utf8
+utf8
+buf
+OUTPUT
+