[svn:parrot] r36357 - in trunk: include/parrot src/io src/pmc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Wed Feb 4 16:42:19 UTC 2009


Author: NotFound
Date: Wed Feb  4 16:42:18 2009
New Revision: 36357
URL: https://trac.parrot.org/parrot/changeset/36357

Log:
reimplement stdhandle method, TT #264

Modified:
   trunk/include/parrot/io.h
   trunk/src/io/api.c
   trunk/src/pmc/parrotinterpreter.pmc

Modified: trunk/include/parrot/io.h
==============================================================================
--- trunk/include/parrot/io.h	Wed Feb  4 16:36:12 2009	(r36356)
+++ trunk/include/parrot/io.h	Wed Feb  4 16:42:18 2009	(r36357)
@@ -292,6 +292,13 @@
         __attribute__nonnull__(1);
 
 PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PMC * Parrot_io_stdhandle(PARROT_INTERP,
+    INTVAL fileno,
+    ARGIN_NULLOK(PMC *newhandle))
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 PMC * Parrot_io_STDIN(PARROT_INTERP)
@@ -385,6 +392,8 @@
     || PARROT_ASSERT_ARG(pmc)
 #define ASSERT_ARGS_Parrot_io_STDERR __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_io_stdhandle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_io_STDIN __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_io_STDOUT __attribute__unused__ int _ASSERT_ARGS_CHECK = \

Modified: trunk/src/io/api.c
==============================================================================
--- trunk/src/io/api.c	Wed Feb  4 16:36:12 2009	(r36356)
+++ trunk/src/io/api.c	Wed Feb  4 16:42:18 2009	(r36357)
@@ -37,6 +37,31 @@
 
 =over 4
 
+=item C<PMC * Parrot_io_stdhandle>
+
+Get the current standard IO object and optionally set a new one.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+Parrot_io_stdhandle(PARROT_INTERP, INTVAL fileno, ARGIN_NULLOK(PMC *newhandle))
+{
+    PMC * result = PMCNULL;
+    if (fileno == PIO_STDIN_FILENO || fileno == PIO_STDOUT_FILENO ||
+            fileno == PIO_STDERR_FILENO) {
+        result = interp->piodata->table[fileno];
+        if (! PMC_IS_NULL(newhandle))
+            interp->piodata->table[fileno] = newhandle;
+    }
+    return result;
+}
+
+/*
+
 =item C<PMC * Parrot_io_new_pmc>
 
 Creates a new I/O filehandle object. The value of C<flags> is set

Modified: trunk/src/pmc/parrotinterpreter.pmc
==============================================================================
--- trunk/src/pmc/parrotinterpreter.pmc	Wed Feb  4 16:36:12 2009	(r36356)
+++ trunk/src/pmc/parrotinterpreter.pmc	Wed Feb  4 16:42:18 2009	(r36357)
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2008, The Perl Foundation.
+Copyright (C) 2001-2009, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -28,12 +28,9 @@
 #include "parrot/parrot.h"
 #include "parrot/embed.h"
 #include "parrot/dynext.h"
+#include "parrot/io.h"
 #include "pmc_class.h"
 
-/* Cancelling this until better solution */
-/* This is a quick hack to test the stdhandle feature */
-/* include "../../src/io/io_private.h" */
-
 /*
 
 =item C<void
@@ -740,15 +737,7 @@
 */
 
     METHOD stdhandle(INTVAL fileno, PMC *newhandle :optional) {
-        PMC * handle = PMCNULL;
-/* Temporarily disabled */
-#if 0
-        if (fileno >= PIO_STDIN_FILENO && fileno <= PIO_STDERR_FILENO) {
-            handle = interp->piodata->table[fileno];
-            if (!PMC_IS_NULL(newhandle))
-                interp->piodata->table[fileno] = newhandle;
-        }
-#endif
+        PMC * handle = Parrot_io_stdhandle(interp, fileno, newhandle);
         RETURN(PMC *handle);
     }
 


More information about the parrot-commits mailing list