Skip to content

Commit

Permalink
[io_cleanups] move the functions from src/io/core.c into src/io/api.c…
Browse files Browse the repository at this point in the history
…, since they really were API functions. Separate Parrot_io_init into two separate functions because it was performing two completely separate actions at different times

git-svn-id: https://svn.parrot.org/parrot/branches/io_cleanups@39790 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
whiteknight committed Jun 26, 2009
1 parent c76c8ee commit 108ef84
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 123 deletions.
50 changes: 42 additions & 8 deletions include/parrot/io.h
Expand Up @@ -179,6 +179,10 @@ PMC * Parrot_io_fdopen(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(4);

PARROT_EXPORT
void Parrot_io_finish(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
void Parrot_io_flush(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(1)
Expand All @@ -204,6 +208,14 @@ PIOHANDLE Parrot_io_getfd(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(2)
FUNC_MODIFIES(*pmc);

PARROT_EXPORT
void Parrot_io_init_handles(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
void Parrot_io_init_table(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_is_closed(PARROT_INTERP, ARGMOD(PMC *pmc))
Expand Down Expand Up @@ -342,6 +354,11 @@ INTVAL Parrot_io_write(PARROT_INTERP,
__attribute__nonnull__(3)
FUNC_MODIFIES(*pmc);

PARROT_EXPORT
void Parrot_IOData_mark(PARROT_INTERP, ARGIN(ParrotIOData *piodata))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_WARN_UNUSED_RESULT
PIOOFF_T Parrot_io_make_offset32(INTVAL hi, INTVAL lo);

Expand All @@ -364,6 +381,8 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
#define ASSERT_ARGS_Parrot_io_fdopen __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(sflags)
#define ASSERT_ARGS_Parrot_io_finish __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_flush __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
Expand All @@ -374,6 +393,10 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
#define ASSERT_ARGS_Parrot_io_getfd __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_io_init_handles __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_init_table __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_is_closed __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
Expand Down Expand Up @@ -423,6 +446,9 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc) \
|| PARROT_ASSERT_ARG(buffer)
#define ASSERT_ARGS_Parrot_IOData_mark __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(piodata)
#define ASSERT_ARGS_Parrot_io_make_offset32 __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_make_offset_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
Expand Down Expand Up @@ -618,7 +644,8 @@ PIOOFF_T Parrot_io_get_last_file_position(SHIM_INTERP,
__attribute__nonnull__(2);

PARROT_EXPORT
PIOHANDLE Parrot_io_get_os_handle(SHIM_INTERP, ARGIN(PMC *filehandle))
PIOHANDLE Parrot_io_get_os_handle(PARROT_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
Expand Down Expand Up @@ -656,17 +683,19 @@ void Parrot_io_set_flags(PARROT_INTERP,
__attribute__nonnull__(2);

PARROT_EXPORT
void Parrot_io_set_os_handle(SHIM_INTERP,
void Parrot_io_set_os_handle(PARROT_INTERP,
ARGIN(PMC *filehandle),
PIOHANDLE file_descriptor)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_CAN_RETURN_NULL
void Parrot_io_clear_buffer(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);

PARROT_CAN_RETURN_NULL
INTVAL Parrot_io_get_buffer_flags(SHIM_INTERP, ARGIN(PMC *filehandle))
INTVAL Parrot_io_get_buffer_flags(PARROT_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_CAN_RETURN_NULL
Expand All @@ -687,9 +716,10 @@ void Parrot_io_set_buffer_end(SHIM_INTERP,
ARGIN_NULLOK(unsigned char *new_end))
__attribute__nonnull__(2);

void Parrot_io_set_buffer_flags(SHIM_INTERP,
void Parrot_io_set_buffer_flags(PARROT_INTERP,
ARGIN(PMC *filehandle),
INTVAL new_flags)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

void Parrot_io_set_buffer_next(SHIM_INTERP,
Expand Down Expand Up @@ -727,7 +757,8 @@ void Parrot_io_set_buffer_start(SHIM_INTERP,
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_is_closed_filehandle \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
Expand All @@ -744,11 +775,13 @@ void Parrot_io_set_buffer_start(SHIM_INTERP,
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_clear_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_buffer_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_buffer_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_make_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Expand All @@ -757,7 +790,8 @@ void Parrot_io_set_buffer_start(SHIM_INTERP,
#define ASSERT_ARGS_Parrot_io_set_buffer_end __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_next __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Expand Down
4 changes: 2 additions & 2 deletions src/interp/inter_create.c
Expand Up @@ -157,7 +157,7 @@ make_interpreter(ARGIN_NULLOK(Interp *parent), INTVAL flags)

/* PANIC will fail until this is done */
interp->piodata = NULL;
Parrot_io_init(interp);
Parrot_io_init_table(interp);

if (is_env_var_set("PARROT_GC_DEBUG")) {
#if ! DISABLE_GC_DEBUG
Expand Down Expand Up @@ -243,7 +243,7 @@ make_interpreter(ARGIN_NULLOK(Interp *parent), INTVAL flags)
setup_default_compreg(interp);

/* setup stdio PMCs */
Parrot_io_init(interp);
Parrot_io_init_handles(interp);

/* init IMCC compiler */
imcc_init(interp);
Expand Down
118 changes: 118 additions & 0 deletions src/io/api.c
Expand Up @@ -38,6 +38,8 @@ src/io/io_string.c.

/* HEADERIZER HFILE: include/parrot/io.h */

PIOOFF_T piooffsetzero;

/*
=head2 Generic I/O interface
Expand Down Expand Up @@ -72,6 +74,122 @@ Parrot_io_stdhandle(PARROT_INTERP, INTVAL fileno, ARGIN_NULLOK(PMC *newhandle))
return result;
}


/*
=item C<void Parrot_io_init_handles(PARROT_INTERP)>
Sets up the interpreter's I/O storage and creates the C<STD*> handles.
Called when creating an interpreter.
=cut
*/

PARROT_EXPORT
void
Parrot_io_init_handles(PARROT_INTERP)
{
ASSERT_ARGS(Parrot_io_init_handles)
/* Has interp been initialized already? */
if (interp->piodata) {
/* memsub system is up and running: */
/* Init IO stacks and handles for interp instance. */
PIO_INIT(interp);

if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG))
Parrot_io_eprintf(NULL, "I/O system initialized.\n");
}
else
/* This should never happen, but still good to check */
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"PIO alloc piodata failure.");
}

/*
=item C<void Parrot_io_init_table(PARROT_INTERP)>
Sets up the Parrot IO table to hold the standard handles
=cut
*/

PARROT_EXPORT
void
Parrot_io_init_table(PARROT_INTERP)
{
ASSERT_ARGS(Parrot_io_init_table)
interp->piodata = mem_allocate_typed(ParrotIOData);
if (interp->piodata == NULL)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"PIO alloc piodata failure.");
interp->piodata->table =
(PMC **)mem_sys_allocate_zeroed(PIO_NR_OPEN * sizeof (PMC *));

if (!interp->piodata->table)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"PIO alloc table failure.");
}

/*
=item C<void Parrot_io_finish(PARROT_INTERP)>
Closes the interpreter's IO resourses. Called during its interpreter
destruction.
=cut
*/

PARROT_EXPORT
void
Parrot_io_finish(PARROT_INTERP)
{
ASSERT_ARGS(Parrot_io_finish)
/*
* TODO free IO of std-handles
*/
mem_sys_free(interp->piodata->table);
interp->piodata->table = NULL;
mem_sys_free(interp->piodata);
interp->piodata = NULL;

}


/*
=item C<void Parrot_IOData_mark(PARROT_INTERP, ParrotIOData *piodata)>
Called from C<Parrot_gc_trace_root()> to mark the IO data live.
=cut
*/

PARROT_EXPORT
void
Parrot_IOData_mark(PARROT_INTERP, ARGIN(ParrotIOData *piodata))
{
ASSERT_ARGS(Parrot_IOData_mark)
INTVAL i;
ParrotIOTable table = piodata->table;

/* this was i < PIO_NR_OPEN, but only standard handles 0..2 need
* to be kept alive AFAIK -leo
*/
for (i = 0; i < 3; i++) {
if (table[i]) {
Parrot_gc_mark_PObj_alive(interp, (PObj *)table[i]);
}
}
}


/*
=item C<PMC * Parrot_io_new_pmc(PARROT_INTERP, INTVAL flags)>
Expand Down

0 comments on commit 108ef84

Please sign in to comment.