cvsuser 03/09/17 10:34:11
Modified: . io.ops
classes parrotio.pmc
include/parrot io.h
io io.c io_stdio.c io_unix.c io_win32.c
t/pmc io.t
Log:
Change of fdopen semantics
- getfd returns the OS-filehandle (return type changed to PIOHANDLE)
- fdopen needs a valid OS-handle (i.e. fdopen 0 only works on UNIX)
- fdopened files are not closed but only flushed on destruction
- updated tests to new semantics
Revision Changes Path
1.34 +1 -5 parrot/io.ops
Index: io.ops
===================================================================
RCS file: /cvs/public/parrot/io.ops,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -w -r1.33 -r1.34
--- io.ops 12 Aug 2003 07:57:30 -0000 1.33
+++ io.ops 17 Sep 2003 17:34:01 -0000 1.34
@@ -52,7 +52,6 @@
=cut
inline op fdopen(out PMC, in INT, in STR) {
-#ifdef PIO_OS_UNIX
/* These char * need to go away soon */
const char * mode;
mode = string_to_cstring(interpreter, $3);
@@ -66,9 +65,6 @@
but this generates ugly warnings WRT discarding the const
qualifier -lt
*/
-#else
- $1 = pmc_new(interpreter, enum_class_PerlUndef);
-#endif
goto NEXT();
}
@@ -82,7 +78,7 @@
=cut
inline op getfd(out INT, in PMC) {
- $1 = PIO_getfd(interpreter, $2);
+ $1 = (INTVAL)PIO_getfd(interpreter, $2);
goto NEXT();
}
1.11 +10 -3 parrot/classes/parrotio.pmc
Index: parrotio.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/parrotio.pmc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- parrotio.pmc 28 Aug 2003 13:17:01 -0000 1.10
+++ parrotio.pmc 17 Sep 2003 17:34:03 -0000 1.11
@@ -1,7 +1,7 @@
/* ParrotIO.pmc
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: parrotio.pmc,v 1.10 2003/08/28 13:17:01 leo Exp $
+ * $Id: parrotio.pmc,v 1.11 2003/09/17 17:34:03 boemmels Exp $
* Overview:
* These are the vtable functions for Parrot IO
* Data Structure and Algorithms:
@@ -78,8 +78,15 @@
void destroy () {
ParrotIO *io = PMC_data(SELF);
- if (io && !(io->flags & PIO_F_SHARED))
+ if (io) {
+ /* shared filehandles will only get flushed */
+ if (io->flags & PIO_F_SHARED) {
+ PIO_flush(interpreter, SELF);
+ }
+ else {
PIO_close(interpreter, SELF);
+ }
+ }
}
void clone (PMC *dest) {
1.41 +2 -2 parrot/include/parrot/io.h
Index: io.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/io.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -w -r1.40 -r1.41
--- io.h 28 Aug 2003 11:03:05 -0000 1.40
+++ io.h 17 Sep 2003 17:34:05 -0000 1.41
@@ -1,7 +1,7 @@
/* io.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io.h,v 1.40 2003/08/28 11:03:05 leo Exp $
+ * $Id: io.h,v 1.41 2003/09/17 17:34:05 boemmels Exp $
* Overview:
* Parrot IO subsystem
* Data Structure and Algorithms:
@@ -272,7 +272,7 @@
extern INTVAL PIO_fprintf(theINTERP, PMC *io, const char *s, ...);
extern INTVAL PIO_printf(theINTERP, const char *s, ...);
extern INTVAL PIO_eprintf(theINTERP, const char *s, ...);
-extern INTVAL PIO_getfd(theINTERP, PMC *io);
+extern PIOHANDLE PIO_getfd(theINTERP, PMC *io);
extern PIOOFF_T PIO_tell(theINTERP, PMC *io);
extern void Parrot_IOData_mark(theINTERP, ParrotIOData *piodata);
1.54 +6 -13 parrot/io/io.c
Index: io.c
===================================================================
RCS file: /cvs/public/parrot/io/io.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -w -r1.53 -r1.54
--- io.c 2 Sep 2003 16:41:14 -0000 1.53
+++ io.c 17 Sep 2003 17:34:08 -0000 1.54
@@ -1,7 +1,7 @@
/* io.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io.c,v 1.53 2003/09/02 16:41:14 boemmels Exp $
+ * $Id: io.c,v 1.54 2003/09/17 17:34:08 boemmels Exp $
* Overview:
* This is the Parrot IO subsystem API. Generic IO stuff
* goes here, each specific layer goes in its own file...
@@ -701,23 +701,16 @@
return ret;
}
-INTVAL
+PIOHANDLE
PIO_getfd(theINTERP, PMC *pmc)
{
- INTVAL i;
-
- ParrotIOTable table = ((ParrotIOData*)interpreter->piodata)->table;
+ ParrotIO *io = PMC_data(pmc);
- for(i = 0; i < PIO_NR_OPEN; i++) {
- if (table[i] == pmc) return i;
- if (table[i] == NULL) {
- table[i] = pmc;
- return i;
- }
+ if (io) {
+ return io->fd;
}
- /* XXX boe: increase size of the fdtable */
- return -1;
+ return (PIOHANDLE)0;
}
/* Implemenation of the PIO_STD* functions on basis of the macro */
1.30 +5 -1 parrot/io/io_stdio.c
Index: io_stdio.c
===================================================================
RCS file: /cvs/public/parrot/io/io_stdio.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -w -r1.29 -r1.30
--- io_stdio.c 17 Sep 2003 17:17:34 -0000 1.29
+++ io_stdio.c 17 Sep 2003 17:34:08 -0000 1.30
@@ -1,7 +1,7 @@
/* io_stdio.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io_stdio.c,v 1.29 2003/09/17 17:17:34 boemmels Exp $
+ * $Id: io_stdio.c,v 1.30 2003/09/17 17:34:08 boemmels Exp $
* Overview:
* This is the Parrot IO STDIO layer. This may provide a subset of
* full functionality, but must compile on any system with the
@@ -159,6 +159,10 @@
if (PIO_isatty(fptr))
flags |= PIO_F_CONSOLE;
+
+ /* fdopened files are always shared */
+ flags |= PIO_F_SHARED;
+
io = PIO_new(interpreter, PIO_F_FILE, flags, mode);
io->fd = fptr;
return io;
1.33 +5 -1 parrot/io/io_unix.c
Index: io_unix.c
===================================================================
RCS file: /cvs/public/parrot/io/io_unix.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -w -r1.32 -r1.33
--- io_unix.c 5 Sep 2003 12:31:43 -0000 1.32
+++ io_unix.c 17 Sep 2003 17:34:08 -0000 1.33
@@ -1,7 +1,7 @@
/* io_unix.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io_unix.c,v 1.32 2003/09/05 12:31:43 boemmels Exp $
+ * $Id: io_unix.c,v 1.33 2003/09/17 17:34:08 boemmels Exp $
* Overview:
* This is the Parrot IO UNIX layer. May be changed to
* include other platforms if that platform is similar
@@ -221,6 +221,10 @@
if (PIO_unix_isatty(fd))
flags |= PIO_F_CONSOLE;
+
+ /* fdopened files are always shared */
+ flags |= PIO_F_SHARED;
+
io = PIO_new(interpreter, PIO_F_FILE, flags, mode);
io->fd = fd;
return io;
1.33 +5 -1 parrot/io/io_win32.c
Index: io_win32.c
===================================================================
RCS file: /cvs/public/parrot/io/io_win32.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -w -r1.32 -r1.33
--- io_win32.c 17 Sep 2003 14:20:04 -0000 1.32
+++ io_win32.c 17 Sep 2003 17:34:08 -0000 1.33
@@ -1,7 +1,7 @@
/* io_win32.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io_win32.c,v 1.32 2003/09/17 14:20:04 boemmels Exp $
+ * $Id: io_win32.c,v 1.33 2003/09/17 17:34:08 boemmels Exp $
* Overview:
* This is the Parrot IO OS layer for Win32 platforms.
* Data Structure and Algorithms:
@@ -180,6 +180,10 @@
if (PIO_win32_isatty(fd))
flags |= PIO_F_CONSOLE;
+
+ /* fdopened files are always shared */
+ flags |= PIO_F_SHARED;
+
io = PIO_new(interpreter, PIO_F_FILE, flags, mode);
io->fd = fd;
return io;
1.14 +25 -12 parrot/t/pmc/io.t
Index: io.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/io.t,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- io.t 25 Aug 2003 11:59:05 -0000 1.13
+++ io.t 17 Sep 2003 17:34:11 -0000 1.14
@@ -35,12 +35,14 @@
1
OUTPUT
-output_is(<<'CODE', <<'OUTPUT', "fdopen");
- fdopen P0, 1, ">"
- defined I0, P0
+output_is(<<'CODE', <<'OUTPUT', "getfd/fdopen");
+ getstdout P0
+ getfd I0, P0
+ fdopen P1, I0, ">"
+ defined I0, P1
unless I0, nok
- print P0, "ok\n"
- close P0
+ print P1, "ok\n"
+ close P1
end
nok:
print "fdopen failed\n"
@@ -50,10 +52,12 @@
OUTPUT
output_is(<<'CODE', <<'OUTPUT', "fdopen - no close");
- fdopen P0, 1, ">"
- defined I0, P0
+ getstdout P0
+ getfd I0, P0
+ fdopen P1, I0, ">"
+ defined I0, P1
unless I0, nok
- print P0, "ok\n"
+ print P1, "ok\n"
end
nok:
print "fdopen failed\n"
@@ -233,18 +237,27 @@
unlink("temp.file");
-output_is(<<'CODE', '012', 'standard file descriptors');
+output_is(<<'CODE', <<'OUT', 'standard file descriptors');
getstdin P0
getfd I0, P0
- print I0
+ # I0 is 0 on Unix and non-Null on stdio and win32
+ print "ok 1\n"
getstdout P1
getfd I1, P1
- print I1
+ if I1, OK_2
+ print "not "
+OK_2: print "ok 2\n"
getstderr P2
getfd I2, P2
- print I2
+ if I2, OK_3
+ print "not "
+OK_3: print "ok 3\n"
end
CODE
+ok 1
+ok 2
+ok 3
+OUT
output_is(<<'CODE', <<'OUTPUT', 'printerr');
new P0, .PerlString