# New Ticket Created by  Jürgen Bömmels 
# Please include the string:  [perl #22899]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22899 >


Hello,

The integer file descriptors are depreciated. In this two step patch
they are removed from io.ops.

In the first patch (io11.diff) the replacement ops printerr_[insp] and
print_p_[insp] are created. Also the ops getfd and getstd{in,out,err}
are introduced. The test are adjusted to follow the new
convention. A test for the new ops getfd and getstd{n,out,err} is
added to t/op/hacks.t (the inofficial io.t).

In the second patch (io12.diff) the old ops are removed. But this may
break present programs. (make test and cd languages/scheme ; make test
runs with no errors, but i did not check the rest).



-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/60490/44740/4962e7/io11.diff

-- attachment  2 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/60490/44741/8a57a9/io12.diff

Index: io.ops
===================================================================
RCS file: /cvs/public/parrot/io.ops,v
retrieving revision 1.24
diff -u -r1.24 io.ops
--- io.ops	1 Jul 2003 15:41:00 -0000	1.24
+++ io.ops	7 Jul 2003 22:04:51 -0000
@@ -36,8 +36,8 @@
 =cut
 
 inline op close(in PMC) {
-	PIO_close(interpreter, $1);
-	goto NEXT();
+  PIO_close(interpreter, $1);
+  goto NEXT();
 }
 
 ########################################
@@ -55,7 +55,6 @@
 #ifdef PIO_OS_UNIX
   /* These char * need to go away soon */
   const char * mode;
-  ParrotIO *io;
   mode = string_to_cstring(interpreter, $3);
 
   $1 = PIO_fdopen(interpreter, $2, mode);
@@ -73,6 +72,52 @@
   goto NEXT();
 }
 
+=item B<getfd>(out INT, in PMC)
+
+Get the file descriptor out of the ParrotIO object $2 and store it in $1
+
+XXX: integral file descriptors may not exist outside of the UNIX
+     platform.
+
+=cut
+
+inline op getfd(out INT, in PMC) {
+  $1 = PIO_getfd(interpreter, $2);
+  goto NEXT();
+}
+
+=item B<getstdin>(out PMC)
+
+Create a new ParrotIO object for the stdin file descriptor and
+store it in $1
+
+=item B<getstdout>(out PMC)
+
+Create a new ParrotIO object for the stdout file descriptor and
+store it in $1
+
+=item B<getstderr>(out PMC)
+
+Create a new ParrotIO object for the stderr file descriptor and
+store it in $1
+
+=cut
+
+inline op getstdin(out PMC) {
+  $1 = new_io_pmc(interpreter, PIO_STDIN(interpreter));
+  goto NEXT();
+}
+
+inline op getstdout(out PMC) {
+  $1 = new_io_pmc(interpreter, PIO_STDOUT(interpreter));
+  goto NEXT();
+}
+
+inline op getstderr(out PMC) {
+  $1 = new_io_pmc(interpreter, PIO_STDERR(interpreter));
+  goto NEXT();
+}
+
 #########################################
 
 =item B<open>(out PMC, in STR, in STR)
@@ -80,6 +125,11 @@
 Open URL (file, address, database, in core image) named $2 with
 Perl style mode string in $3 and create an IO object in $1.
 
+=item B<open>(out PMC, in STR)
+
+Open URL (file, address, database, in core image) named $2 with
+read/write mode and create an IO object in $1.
+
 =cut
 
 inline op open(out PMC, in STR, in STR) {
@@ -98,6 +148,20 @@
   goto NEXT();
 }
 
+inline op open(out PMC, in STR) {
+  /* These char * need to go away soon */
+  const char * path;
+
+  path = string_to_cstring(interpreter, $2);
+
+  $1 = PIO_open(interpreter, path, "+<");
+  /* string_cstring_free(path); */
+  if(!$1) {
+    $1 = pmc_new(interpreter, enum_class_PerlUndef);
+  }
+  goto NEXT();
+}
+
 =item B<open>(out INT, in STR)
 
 Open file named $2 for reading and writing and save the file
@@ -255,31 +319,100 @@
 
 ##########################################
 
-=item B<print>(in PMC, in STR)
+=item B<printerr>(in INT)
+
+=item B<printerr>(in NUM)
+
+=item B<printerr>(in STR)
+
+=item B<printerr>(in PMC)
 
-Print String $2 on the IO stream object $1.
+Print $1 to standard error.
 
 =cut
 
-op print(in PMC, in STR) {
-  if ($2 && $1) {
-    PIO_write(interpreter, $1, ($2)->strstart, string_length($2));
+op printerr(in INT) {
+  PIO_eprintf(interpreter, INTVAL_FMT, (double)$1);
+  goto NEXT();
+}
+
+op printerr(in NUM) {
+  PIO_eprintf(interpreter, "%f", (double)$1);
+  goto NEXT();
+}
+
+op printerr(in STR) {
+  STRING *s = $1;
+  if (s && string_length(s)) {
+    PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDERR(interpreter)),
+              s);
+  }
+  goto NEXT();
+}
+
+op printerr(in PMC) {
+  PMC *p = $1;
+  STRING *s = (VTABLE_get_string(interpreter, p));
+  if (s) {
+    PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDOUT(interpreter)),
+              s);
   }
   goto NEXT();
 }
 
 ##########################################
 
-=item B<printerr>(in STR)
+=item B<print>(in PMC, in INT)
 
-Print $1 to interp.stderr IO stream (unbuffered)
+=item B<print>(in PMC, in NUM)
+
+=item B<print>(in PMC, in STR)
+
+=item B<print>(in PMC, in PMC)
+
+Print $2 on the IO stream object $1.
 
 =cut
 
-op printerr(in STR) {
+op print(in PMC, in INT) {
   if ($1) {
-    PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDERR(interpreter)),
-              $1);
+    STRING *s = Parrot_sprintf_c(interpreter, INTVAL_FMT, $2);
+    PIO_putps(interpreter, $1, s);
+  }
+  else {
+    /* Handle error here */
+  }
+  goto NEXT();
+}
+
+op print(in PMC, in NUM) {
+  if ($1) {
+    STRING *s = Parrot_sprintf_c(interpreter, "%f", (double)$2);
+    PIO_putps(interpreter, $1, s);
+  }
+  else {
+    /* Handle error here */
+  }
+  goto NEXT();
+}
+
+op print(in PMC, in STR) {
+  if ($2 && $1) {
+    PIO_putps(interpreter, $1, $2);
+  }
+  else {
+    /* Handle error here */
+  }
+  goto NEXT();
+}
+
+op print(in PMC, in PMC) {
+  if ($2 && $1) {
+    STRING *s = VTABLE_get_string(interpreter, $2);
+    PIO_putps(interpreter, $1, s);
+  }
+  else {
+    /* Handle error here */
   }
   goto NEXT();
 }
@@ -293,9 +426,6 @@
 =item B<puts>(in NUM)
 
 Print $1 to standard output stream
-This will go away when print ops are all migrated to
-use ParrotIO instead of STDIO. Right now ParrotIO is
-not stable enough to replace STDIO.
 
 =cut
 
@@ -372,6 +502,29 @@
   goto NEXT();
 }
 
+=item B<readline>(out STR, in PMC)
+
+Read a line up to EOL from IO-object $2.
+At the moment this switches the filehandle to linebuffer-mode.
+
+If for some reason the line's longer than 64K you get only 64K
+
+=cut
+
+inline op readline(out STR, in PMC) {
+  ParrotIO *io;
+  size_t len = 0;
+  $1 = string_make(interpreter, NULL, 65535, NULL, 0, NULL);
+  memset(($1)->strstart, 0, 65535);
+
+  if ($2) {
+    PIO_setlinebuf(interpreter, $2);
+    len = PIO_read(interpreter, $2, ($1)->strstart, 65534);
+    ($1)->strlen = ($1)->bufused = len;
+  }
+  goto NEXT();
+}
+
 =item B<readline>(out STR, in INT)
 
 Read a line up to EOL from filehandle $2.
@@ -428,14 +581,7 @@
   goto NEXT();
 }
 
-
 ########################################
-
-
-
-
-
-
 
 =back
 
Index: t/op/hacks.t
===================================================================
RCS file: /cvs/public/parrot/t/op/hacks.t,v
retrieving revision 1.7
diff -u -r1.7 hacks.t
--- t/op/hacks.t	20 May 2003 11:11:11 -0000	1.7
+++ t/op/hacks.t	7 Jul 2003 22:04:51 -0000
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 9;
+use Parrot::Test tests => 10;
 use Test::More;
 
 # It would be very embarrassing if these didn't work...
@@ -8,11 +8,11 @@
 print FOO "2\n1\n";
 close FOO;
 output_is(<<'CODE', <<'OUTPUT', "open and readline");
-	open I0, "temp.file"
+	open P0, "temp.file"
 	set S0, ""
 	set S1, ""
-	readline S0, I0
-	readline S1, I0
+	readline S0, P0
+	readline S1, P0
 	print S1
 	print S0
 	end
@@ -31,16 +31,16 @@
        new P0, .PerlString
        set P0, "Bar\n"
 
-       open I1, "temp.file"
-       print I1, I0
-       print I1, N0
-       print I1, S0
-       print I1, P0
-       close I1
-
-       open I2, "temp.file"
-       readline S1, I2
-       close I2
+       open P1, "temp.file"
+       print P1, I0
+       print P1, N0
+       print P1, S0
+       print P1, P0
+       close P1
+
+       open P2, "temp.file"
+       readline S1, P2
+       close P2
 
        print S1
        end
@@ -53,13 +53,13 @@
 
 # This one passes, but for the wrong reason
 output_is(<<'CODE', <<'OUTPUT', "3-arg open");
-       open I1, "temp.file", "<"
+       open P1, "temp.file", "<"
        print "Foobar\n"
-       close I1
+       close P1
 
-       open I3, "temp.file", "r"
-       readline S1, I3
-       close I3
+       open P3, "temp.file", "<"
+       readline S1, P3
+       close P3
 
        print S1
        end
@@ -70,9 +70,9 @@
 unlink("temp.file");
 
 output_is(<<'CODE', <<'OUTPUT', 'open and close');
-       open I1, "temp.file"
-       print I1, "Hello, World!\n"
-       close I1
+       open P1, "temp.file"
+       print P1, "Hello, World!\n"
+       close P1
        print "done\n"
        end
 CODE
@@ -89,9 +89,9 @@
 close FOO;
 
 output_is(<<'CODE', '', 'append');
-       open I1, "temp.file", ">>"
-       print I1, "Parrot flies\n"
-       close I1
+       open P1, "temp.file", ">>"
+       print P1, "Parrot flies\n"
+       close P1
        end
 CODE
 
@@ -105,9 +105,9 @@
 close FOO;
 
 output_is(<<'CODE', '', 'write to file');
-       open I1, "temp.file", ">"
-       print I1, "Parrot overwrites\n"
-       close I1
+       open P1, "temp.file", ">"
+       print P1, "Parrot overwrites\n"
+       close P1
        end
 CODE
 
@@ -118,5 +118,18 @@
 OUTPUT
          
 unlink("temp.file");
+
+output_is(<<'CODE', '012', 'standard file descriptors');
+       getstdin P0
+       getfd I0, P0
+       print I0
+       getstdout P1
+       getfd I1, P1
+       print I1
+       getstderr P2
+       getfd I2, P2
+       print I2
+       end
+CODE
 
 1; # HONK
Index: t/op/interp.t
===================================================================
RCS file: /cvs/public/parrot/t/op/interp.t,v
retrieving revision 1.9
diff -u -r1.9 interp.t
--- t/op/interp.t	28 Jun 2003 11:25:24 -0000	1.9
+++ t/op/interp.t	7 Jul 2003 22:04:51 -0000
@@ -19,20 +19,20 @@
 ending
 OUTPUT
 output_like(<<'CODE', <<'OUTPUT', "restart trace");
-	print 2, "ok 1\n"
+	printerr "ok 1\n"
 	set I0, 1
 	trace I0
-	print 2, "ok 2\n"
+	printerr "ok 2\n"
 	dec I0
 	trace I0
-	print 2, "ok 3\n"
+	printerr "ok 3\n"
 	end
 CODE
 /^ok\s1\n
-(?:PC=8.*)?\n
+(?:PC=7.*)?\n
 ok\s2\n
+(?:PC=9.*)?\n
 (?:PC=11.*)?\n
-(?:PC=13.*)?\n
 ok\s3\n$/x
 OUTPUT
 
Index: t/op/macro.t
===================================================================
RCS file: /cvs/public/parrot/t/op/macro.t,v
retrieving revision 1.12
diff -u -r1.12 macro.t
--- t/op/macro.t	3 Jul 2003 11:15:19 -0000	1.12
+++ t/op/macro.t	7 Jul 2003 22:04:51 -0000
@@ -192,13 +192,11 @@
 OUTPUT
 
 ##############################
-output_is(<<'CODE', <<'OUT', "find file in runtime includes");
+output_is(<<'CODE', '1', "find file in runtime includes");
     .include "stdio.pasm"
-    print .PIO_STDOUT_FILENO, "ok\n"
+    print .PIO_STDOUT_FILENO
     end
 CODE
-ok
-OUT
 
 open FOO, ">macro.tempfile";   # Clobber previous
 close FOO;
--- io.ops	Mon Jul  7 20:09:15 2003
+++ io.ops.new	Mon Jul  7 20:52:50 2003
@@ -162,67 +162,6 @@
   goto NEXT();
 }
 
-=item B<open>(out INT, in STR)
-
-Open file named $2 for reading and writing and save the file
-descriptor into $1.
-
-=item B<open>(out INT, in STR, in STR)
-
-Open file named $2 with flags $3 and mode 0644 (rw-r--r--), and save the file
-descriptor into $1.
-
-=cut
-
-op open(out INT, in STR) {
-  char *path = string_to_cstring(interpreter, $2);
-  PMC *io = PIO_open(interpreter, path, "+<");
-  /* string_cstring_free(path); */
-  if (io) {
-    $1 = PIO_getfd(interpreter, io);
-  }
-  else {
-    $1 = -1;
-  }
-  goto NEXT();
-}
-
-op open(out INT, in STR, in STR) {
-  char *path = string_to_cstring(interpreter, $2);
-  char *mode = string_to_cstring(interpreter, $3);
-  PMC *io = PIO_open(interpreter, path, mode);
-  /* string_cstring_free(mode); */
-  /* string_cstring_free(path); */
-  if (io) {
-    $1 = PIO_getfd(interpreter, io);
-  }
-  else {
-    $1 = -1;
-  }
-  goto NEXT();
-}
-
-########################################
-
-=item B<close>(inout INT)
-
-Close file opened on file descriptor $1.
-
-=cut
-
-inline op close(inout INT) {
-  ParrotIOTable table;
-  ParrotIO     *io;
-
-  if ($1 >= 0) {
-    table = ((ParrotIOData*)interpreter->piodata)->table;
-    io = table[$1];
-    table[$1] = NULL;
-    PIO_close(interpreter, new_io_pmc(interpreter, io));
-  }
-  goto NEXT();
-}
-
 ########################################
 
 =item B<print>(in INT)
@@ -235,17 +174,6 @@
 
 Print $1 to standard output.
 
-=item B<print>(in INT, in INT)
-
-=item B<print>(in INT, in NUM)
-
-=item B<print>(in INT, in STR)
-
-=item B<print>(in INT, in PMC)
-
-Print $2 to the file specified by file descriptor $1; for $1 equal to
-0, 1 or 2, we use stdin, stdout or stderr respectively.
-
 =cut
 
 inline op print(in INT) {
@@ -277,46 +205,6 @@
   goto NEXT();
 }
 
-
-op print(in INT, in INT) {
-  ParrotIO *io = ((ParrotIOData*)interpreter->piodata)->table[$1];
-  STRING *s = Parrot_sprintf_c(interpreter, INTVAL_FMT, $2);
-  PIO_putps(interpreter, new_io_pmc(interpreter, io), s);
-  goto NEXT();
-}
-
-op print(in INT, in NUM) {
-  ParrotIO *io = ((ParrotIOData*)interpreter->piodata)->table[$1];
-  STRING *s = Parrot_sprintf_c(interpreter, "%f", (double)$2);
-  PIO_putps(interpreter, new_io_pmc(interpreter, io), s);
-  goto NEXT();
-}
-
-op print(in INT, in STR) {
-  STRING *s = $2;
-  ParrotIO *io = ((ParrotIOData*)interpreter->piodata)->table[$1];
-  if (s && string_length(s)) {
-    PIO_putps(interpreter, new_io_pmc(interpreter, io), s);
-  }
-  goto NEXT();
-}
-
-op print(in INT, in PMC) {
-  PMC *p = $2;
-  ParrotIO *io = ((ParrotIOData*)interpreter->piodata)->table[$1];
-  STRING *s = (p->vtable->get_string(interpreter, p));
-  if (s) {
-    PIO_putps(interpreter, new_io_pmc(interpreter, io), s);
-  }
-  goto NEXT();
-}
-
-op flush(in INT) {
-  ParrotIO *io = ((ParrotIOData*)interpreter->piodata)->table[$1];
-  PIO_flush(interpreter, new_io_pmc(interpreter, io));
-  goto NEXT();
-}
-
 ##########################################
 
 =item B<printerr>(in INT)
@@ -417,39 +305,7 @@
   goto NEXT();
 }
 
-########################################
-
-=item B<puts>(in STR)
-
-=item B<puts>(in INT)
-
-=item B<puts>(in NUM)
-
-Print $1 to standard output stream
-
-=cut
-
-op puts(in STR) {
-  if ($1) {
-    PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDOUT(interpreter)),
-             $1);
-  }
-  goto NEXT();
-}
-
-op puts(in INT) {
-  STRING * s = string_from_int(interpreter, $1);
-  PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDOUT(interpreter)), s);
-  goto NEXT();
-}
-
-op puts(in NUM) {
-  STRING * s = Parrot_sprintf_c(interpreter, "%f", $1);
-  PIO_putps(interpreter, new_io_pmc(interpreter, PIO_STDOUT(interpreter)), s);
-  goto NEXT();
-}
-
-########################################
+##########################################
 
 =item B<read>(out STR, in INT)
 
@@ -504,8 +360,8 @@
 
 =item B<readline>(out STR, in PMC)
 
-Read a line up to EOL from IO-object $2.
-At the moment this switches the filehandle to linebuffer-mode.
+Read a line up to EOL from filehandle $2.
+This switches the filehandle to linebuffer-mode.
 
 If for some reason the line's longer than 64K you get only 64K
 
@@ -520,32 +376,6 @@
   if ($2) {
     PIO_setlinebuf(interpreter, $2);
     len = PIO_read(interpreter, $2, ($1)->strstart, 65534);
-    ($1)->strlen = ($1)->bufused = len;
-  }
-  goto NEXT();
-}
-
-=item B<readline>(out STR, in INT)
-
-Read a line up to EOL from filehandle $2.
-This switches the filehandle to linebuffer-mode.
-
-If for some reason the line's longer than 64K you get only 64K
-
-=cut
-
-inline op readline(out STR, in INT) {
-  ParrotIO *io;
-  size_t len = 0;
-  $1 = string_make(interpreter, NULL, 65535, NULL, 0, NULL);
-  memset(($1)->strstart, 0, 65535);
-
-  if ($2 >= 0) {
-    PMC *pmc;
-    io = ((ParrotIOData*)interpreter->piodata)->table[$2];
-    pmc = new_io_pmc(interpreter, io);
-    PIO_setlinebuf(interpreter, pmc);
-    len = PIO_read(interpreter, pmc, ($1)->strstart, 65534);
     ($1)->strlen = ($1)->bufused = len;
   }
   goto NEXT();
-- 
Juergen Boemmels                        [EMAIL PROTECTED]
Fachbereich Physik                      Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern             Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F  23 F6 C7 2F 85 93 DD 47

Reply via email to