Skip to content

Commit

Permalink
Change iterator to return pointer-to-value
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed May 16, 2011
1 parent f3c03b8 commit 2b22ed0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 4 additions & 6 deletions include/parrot/pointer_array.h
Expand Up @@ -212,13 +212,12 @@ INTVAL Parrot_pa_iter_cmp(PARROT_INTERP,

PARROT_EXPORT
void Parrot_pa_iter_destroy(PARROT_INTERP,
ARGIN(Parrot_Pointer_Array_Iterator *iter))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
ARGFREE(Parrot_Pointer_Array_Iterator *iter))
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_CAN_RETURN_NULL
void * Parrot_pa_iter_get(PARROT_INTERP,
void ** Parrot_pa_iter_get(PARROT_INTERP,
ARGIN(Parrot_Pointer_Array_Iterator *iter))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
Expand Down Expand Up @@ -277,8 +276,7 @@ size_t Parrot_pa_count_used(PARROT_INTERP,
, PARROT_ASSERT_ARG(lhs) \
, PARROT_ASSERT_ARG(rhs))
#define ASSERT_ARGS_Parrot_pa_iter_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(iter))
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_pa_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(iter))
Expand Down
10 changes: 6 additions & 4 deletions src/pointer_array.c
Expand Up @@ -220,20 +220,22 @@ Parrot_pa_iter_destroy(PARROT_INTERP, ARGFREE(Parrot_Pointer_Array_Iterator *ite
}

/*
=item C<void * Parrot_pa_iter_get(PARROT_INTERP, Parrot_Pointer_Array_Iterator
=item C<void ** Parrot_pa_iter_get(PARROT_INTERP, Parrot_Pointer_Array_Iterator
*iter)>
Get stored value.
Get I<pointer> to stored value.
We return pointer to be able to update item in-place.
=cut
*/

PARROT_EXPORT
PARROT_CAN_RETURN_NULL
void *
void **
Parrot_pa_iter_get(PARROT_INTERP, ARGIN(Parrot_Pointer_Array_Iterator *iter))
{
return iter->chunk->data[iter->in_chunk_index];
return &(iter->chunk->data[iter->in_chunk_index]);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions t/src/pointer_array.t
Expand Up @@ -261,13 +261,13 @@ int main(int argc, char* argv[])
forward = Parrot_pa_begin(interp, pa);
ok(!Parrot_pa_iter_is_empty(interp, forward), "Iterator is not empty");
is(&i, Parrot_pa_iter_get(interp, forward), "Got first item");
is(&i, *Parrot_pa_iter_get(interp, forward), "Got first item");
Parrot_pa_iter_next(interp, forward);
is(&j, Parrot_pa_iter_get(interp, forward), "Got second item");
is(&j, *Parrot_pa_iter_get(interp, forward), "Got second item");
Parrot_pa_iter_next(interp, forward);
is(&k, Parrot_pa_iter_get(interp, forward), "Got third item");
is(&k, *Parrot_pa_iter_get(interp, forward), "Got third item");
Parrot_pa_iter_next(interp, forward);
ok(Parrot_pa_iter_is_empty(interp, forward), "Iterator is now empty");
Expand Down

0 comments on commit 2b22ed0

Please sign in to comment.