fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / io / core.c
blob4fb45f49b49deba53c9b4d53e573a818e4a6aeb2
1 /*
2 Copyright (C) 2001-2008, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/io/core.c - I/O subsystem core functions
9 =head1 DESCRIPTION
11 Core functions for initializing and destroying the I/O subsystem within an
12 interpreter.
14 =head2 Resource Functions
16 =over 4
18 =cut
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.
43 =cut
47 PARROT_EXPORT
48 void
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. */
56 PIO_INIT(interp);
59 if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
60 Parrot_io_eprintf(NULL, "I/O system initialized.\n");
63 return;
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
84 destruction.
86 =cut
90 PARROT_EXPORT
91 void
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.
112 =cut
116 PARROT_EXPORT
117 void
118 Parrot_IOData_mark(PARROT_INTERP, ARGIN(ParrotIOData *piodata))
120 ASSERT_ARGS(Parrot_IOData_mark)
121 INTVAL i;
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]);
135 =back
137 =head1 SEE ALSO
139 F<src/io/api.c>,
140 F<src/io/unix.c>,
141 F<src/io/win32.c>,
142 F<src/io/portable.c>,
143 F<src/io/buffer.c>,
144 F<src/io/io_private.h>.
146 =cut
153 * Local variables:
154 * c-file-style: "parrot"
155 * End:
156 * vim: expandtab shiftwidth=4: