Re: [perl #37700] [TODO] Changing Default STDOUT/STDERR Filehandles for PIR Code

2009-02-02 Thread NotFound
Method added in r36305, created TT #264 about it.

-- 
Salu2


Re: [perl #37700] [TODO] Changing Default STDOUT/STDERR Filehandles for PIR Code

2009-01-27 Thread NotFound
On Wed, Dec 17, 2008 at 12:52 AM, chromatic chroma...@wgz.org wrote:
 On Tuesday 16 December 2008 15:40:32 Allison Randal via RT wrote:

 The simple solution is to add opcodes for 'setstdin', 'setstdout', and
 'setstderr' that change the interpreter's stored FileHandle PMCs to a
 PMC passed in as an argument. This will not effect any C code that
 directly calls the low-level read/write functions instead of using the
 Parrot_io_* functions, but then C code should pretty much always use the
 Parrot_io_* functions. (Some exceptions to the general rule apply, like
 when the code specifically needs to override any user changes to
 STD[IN|OUT|ERR]).

 Do these need to be opcodes?  Can they be methods on the interpreter instead?

Here is patch:

Index: src/pmc/parrotinterpreter.pmc
===
--- src/pmc/parrotinterpreter.pmc   (revision 36072)
+++ src/pmc/parrotinterpreter.pmc   (working copy)
@@ -30,6 +30,8 @@
 #include parrot/dynext.h
 #include pmc_class.h

+#include ../io/io_private.h
+
 /*

 =item Cvoid
@@ -718,7 +720,17 @@
 Parrot_register_HLL_type(INTERP, hll_id, core_type_id, hll_type_id);
 }

+METHOD stdhandle(INTVAL fileno, PMC *newhandle :optional) {
+PMC * handle = PMCNULL;
+if (fileno = PIO_STDIN_FILENO  fileno = PIO_STDERR_FILENO) {
+handle = interp-piodata-table[fileno];
+if (!PMC_IS_NULL(newhandle))
+interp-piodata-table[fileno] = newhandle;
+}
+RETURN(PMC *handle);
+}

+
 }

 /*


And a test:

$ cat handle.pir
.sub main
  .local pmc interp, nullout, stdout

  interp = getinterp
  nullout = open '/dev/null', 'w'
  stdout = interp.'stdhandle'(1, nullout)
  stdout.'print'(Hello\n)
  say 'Hi'
  interp.'stdhandle'(1, stdout)
  say 'Bye'
.end
$ ./parrot handle.pir
Hello
Bye

-- 
Salu2


Re: [perl #37700] [TODO] Changing Default STDOUT/STDERR Filehandles for PIR Code

2008-12-16 Thread chromatic
On Tuesday 16 December 2008 15:40:32 Allison Randal via RT wrote:

 The simple solution is to add opcodes for 'setstdin', 'setstdout', and
 'setstderr' that change the interpreter's stored FileHandle PMCs to a
 PMC passed in as an argument. This will not effect any C code that
 directly calls the low-level read/write functions instead of using the
 Parrot_io_* functions, but then C code should pretty much always use the
 Parrot_io_* functions. (Some exceptions to the general rule apply, like
 when the code specifically needs to override any user changes to
 STD[IN|OUT|ERR]).

Do these need to be opcodes?  Can they be methods on the interpreter instead?

-- c


Re: [perl #37700] [TODO] Changing Default STDOUT/STDERR Filehandles for PIR Code

2005-11-18 Thread Chip Salzenberg
On Thu, Nov 17, 2005 at 08:10:59AM -0800, jerry gay wrote:
 it seems we're missing an op (freopen) that would make this
 possible. we've already got fdopen, getfd, getstdout, getstderr, so
 we're mostly there.

Sounds more like you want fdreopen.
-- 
Chip Salzenberg [EMAIL PROTECTED]