Skip to content

Commit

Permalink
Several fixes so the branch builds and passes most coretests. packfil…
Browse files Browse the repository at this point in the history
…econstanttable.t fails for some odd-looking reasons. I have not made test yet.
  • Loading branch information
Whiteknight committed Nov 18, 2012
1 parent b50b1c0 commit c3edcbd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 48 deletions.
9 changes: 3 additions & 6 deletions src/io/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,10 @@ Parrot_io_buffer_remove_from_handle(PARROT_INTERP, ARGMOD(PMC *handle), INTVAL i
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"Unknown buffer number %d", idx);
{
IO_BUFFER * const buffer = (IO_BUFFER *)VTABLE_get_pointer_keyed_int(interp, handle, idx);
if (!buffer)
PMC * const buffer_pmc = io_get_handle_buffer_pmc(interp, handle, idx, NULL, BUFFER_SIZE_ANY, BUFFER_FLAGS_ANY, 0);
if (PMC_IS_NULL(buffer_pmc))
return;
/* TODO: Decrease reference count, only free it if the refcount is
zero */
Parrot_io_buffer_free(interp, buffer);
VTABLE_set_pointer_keyed_int(interp, handle, idx, NULL);
io_remove_buffer_from_handle(interp, handle, idx);
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/io/io_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,12 @@ PARROT_WARN_UNUSED_RESULT
PMC * io_get_handle_buffer_pmc(PARROT_INTERP,
ARGMOD(PMC *handle),
INTVAL buffer_idx,
ARGIN(const IO_VTABLE *vtable),
ARGIN_NULLOK(const IO_VTABLE *vtable),
size_t buffer_size,
INTVAL flags,
INTVAL autocreate)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
FUNC_MODIFIES(*handle);

PARROT_CANNOT_RETURN_NULL
Expand Down Expand Up @@ -282,6 +281,13 @@ STRING * io_readline_encoded_string(PARROT_INTERP,
FUNC_MODIFIES(*handle)
FUNC_MODIFIES(*buffer);

void io_remove_buffer_from_handle(PARROT_INTERP,
ARGMOD(PMC *handle),
INTVAL buffer_idx)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*handle);

void io_sync_buffers_for_read(PARROT_INTERP,
ARGMOD(PMC *handle),
ARGIN(const IO_VTABLE *vtable),
Expand Down Expand Up @@ -347,8 +353,7 @@ STRING * io_verify_string_encoding(PARROT_INTERP,
, PARROT_ASSERT_ARG(vtable))
#define ASSERT_ARGS_io_get_handle_buffer_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle) \
, PARROT_ASSERT_ARG(vtable))
, PARROT_ASSERT_ARG(handle))
#define ASSERT_ARGS_io_get_new_empty_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_io_get_new_filehandle __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand Down Expand Up @@ -376,6 +381,9 @@ STRING * io_verify_string_encoding(PARROT_INTERP,
, PARROT_ASSERT_ARG(vtable) \
, PARROT_ASSERT_ARG(buffer) \
, PARROT_ASSERT_ARG(rs))
#define ASSERT_ARGS_io_remove_buffer_from_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle))
#define ASSERT_ARGS_io_sync_buffers_for_read __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle) \
Expand Down
10 changes: 9 additions & 1 deletion src/io/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ if necessary.
*/

void
io_remove_buffer_from_handle(PARROT_INTERP, ARGMOD(PMC *handle), INTVAL buffer_idx)
{
//ASSERT_ARGS(io_remove_buffer_from_handle)
STRING * const prop_name = io_get_buffer_prop_name(interp, buffer_idx);
Parrot_pmc_delprop(interp, handle, prop_name);
}

PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
IO_BUFFER *
Expand Down Expand Up @@ -261,7 +269,7 @@ PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC *
io_get_handle_buffer_pmc(PARROT_INTERP, ARGMOD(PMC *handle), INTVAL buffer_idx,
ARGIN(const IO_VTABLE *vtable), size_t buffer_size, INTVAL flags,
ARGIN_NULLOK(const IO_VTABLE *vtable), size_t buffer_size, INTVAL flags,
INTVAL autocreate)
{
ASSERT_ARGS(io_get_handle_buffer_pmc)
Expand Down
11 changes: 8 additions & 3 deletions src/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,13 @@ PMC *
Parrot_pmc_getprop(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(STRING *key))
{
ASSERT_ARGS(Parrot_pmc_getprop)
if (PMC_IS_NULL(PMC_metadata(pmc)))
PMC * const props = PMC_metadata(pmc);
if (PMC_IS_NULL(props))
return check_get_std_props(interp, pmc, key);
else
return VTABLE_get_pmc_keyed_str(interp, PMC_metadata(pmc), key);
else {
PARROT_ASSERT(props);
return VTABLE_get_pmc_keyed_str(interp, props, key);
}
}

/*
Expand Down Expand Up @@ -1386,6 +1389,8 @@ make_prop_hash(PARROT_INTERP, ARGMOD(PMC *self))
PMC * const prop = Parrot_pmc_new(interp, enum_class_Hash);

propagate_std_props(interp, self, prop);
PARROT_ASSERT(prop);
PARROT_ASSERT(prop->data);
PARROT_GC_WRITE_BARRIER(interp, self);
return prop;
}
Expand Down
6 changes: 6 additions & 0 deletions src/pmc/iobuffer.pmc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */

pmclass IOBuffer auto_attrs {
ATTR IO_BUFFER * buffer;

Expand Down Expand Up @@ -29,6 +33,8 @@ pmclass IOBuffer auto_attrs {
}

VTABLE void destroy() {
/* TODO: Decrease reference count, only free it if the refcount is
zero */
Parrot_io_buffer_free(INTERP, PARROT_IOBUFFER(SELF)->buffer);
PARROT_IOBUFFER(SELF)->buffer = NULL;
}
Expand Down
35 changes: 1 addition & 34 deletions t/pmc/filehandle.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 31;
use Parrot::Test tests => 30;
use Parrot::Test::Util 'create_tempfile';

=head1 NAME
Expand Down Expand Up @@ -459,39 +459,6 @@ ok 1 - $P0.record_separator("abc")
ok 2 - $P0.record_separator() # .readline works as expected
OUT

# L<PDD22/I\/O PMC API/=item buffer_type>
pir_output_is( <<'CODE', <<'OUT', 'buffer_type' );
.sub 'test' :main
$P0 = new ['FileHandle']
$P0.'buffer_type'('unbuffered')
$S0 = $P0.'buffer_type'()
if $S0 == 'unbuffered' goto ok_1
print 'not '
ok_1:
say 'ok 1 - $S0 = $P1.buffer_type() # unbuffered'
$P0.'buffer_type'('line-buffered')
$S0 = $P0.'buffer_type'()
if $S0 == 'line-buffered' goto ok_2
print 'not '
ok_2:
say 'ok 2 - $S0 = $P1.buffer_type() # line-buffered'
$P0.'buffer_type'('full-buffered')
$S0 = $P0.'buffer_type'()
if $S0 == 'full-buffered' goto ok_3
print 'not '
ok_3:
say 'ok 3 - $S0 = $P1.buffer_type() # full-buffered'
.end
CODE
ok 1 - $S0 = $P1.buffer_type() # unbuffered
ok 2 - $S0 = $P1.buffer_type() # line-buffered
ok 3 - $S0 = $P1.buffer_type() # full-buffered
OUT

# GH #535 test effects of buffer_type, not just set/get

# GH #458
Expand Down

0 comments on commit c3edcbd

Please sign in to comment.