2 Copyright (C) 2001-2008, Parrot Foundation.
7 src/io/core.c - I/O subsystem core functions
11 Core functions for initializing and destroying the I/O subsystem within an
14 =head2 Resource Functions
22 #include "parrot/parrot.h"
23 #include "io_private.h"
25 /* HEADERIZER HFILE: include/parrot/io.h */
28 The standard streams are:
30 interp->piodata->table[PIO_STD*_FILENO].
33 PIOOFF_T piooffsetzero
;
37 =item C<void Parrot_io_init(PARROT_INTERP)>
39 Sets up the interpreter's I/O storage and creates the C<STD*> handles.
41 Called when creating an interpreter.
49 Parrot_io_init(PARROT_INTERP
)
51 ASSERT_ARGS(Parrot_io_init
)
52 /* Has interp been initialized already? */
53 if (interp
->piodata
) {
54 /* memsub system is up and running: */
55 /* Init IO stacks and handles for interp instance. */
59 if (Interp_debug_TEST(interp
, PARROT_START_DEBUG_FLAG
)) {
60 Parrot_io_eprintf(NULL
, "I/O system initialized.\n");
67 interp
->piodata
= mem_gc_allocate_zeroed_typed(interp
, ParrotIOData
);
68 if (interp
->piodata
== NULL
)
69 Parrot_ex_throw_from_c_args(interp
, NULL
, EXCEPTION_PIO_ERROR
,
70 "PIO alloc piodata failure.");
71 interp
->piodata
->table
=
72 mem_gc_allocate_n_zeroed_typed(interp
, PIO_NR_OPEN
, PMC
*);
74 if (!interp
->piodata
->table
)
75 Parrot_ex_throw_from_c_args(interp
, NULL
, EXCEPTION_PIO_ERROR
,
76 "PIO alloc table failure.");
81 =item C<void Parrot_io_finish(PARROT_INTERP)>
83 Closes the interpreter's IO resourses. Called during its interpreter
92 Parrot_io_finish(PARROT_INTERP
)
94 ASSERT_ARGS(Parrot_io_finish
)
96 * TODO free IO of std-handles
98 mem_gc_free(interp
, interp
->piodata
->table
);
99 interp
->piodata
->table
= NULL
;
100 mem_gc_free(interp
, interp
->piodata
);
101 interp
->piodata
= NULL
;
108 =item C<void Parrot_IOData_mark(PARROT_INTERP, ParrotIOData *piodata)>
110 Called from C<Parrot_gc_trace_root()> to mark the IO data live.
118 Parrot_IOData_mark(PARROT_INTERP
, ARGIN(ParrotIOData
*piodata
))
120 ASSERT_ARGS(Parrot_IOData_mark
)
122 ParrotIOTable table
= piodata
->table
;
124 /* this was i < PIO_NR_OPEN, but only standard handles 0..2 need
125 * to be kept alive AFAIK -leo
127 for (i
= 0; i
< 3; ++i
) {
128 Parrot_gc_mark_PMC_alive(interp
, table
[i
]);
142 F<src/io/portable.c>,
144 F<src/io/io_private.h>.
154 * c-file-style: "parrot"
156 * vim: expandtab shiftwidth=4: