Skip to content

Commit

Permalink
Removed unnecsary interp arg from Parrot_pa_insert. Changed the ARGIN…
Browse files Browse the repository at this point in the history
…(self) to ARGMOD. Fixed some spelling typos.
  • Loading branch information
petdance committed Apr 13, 2012
1 parent 0c62b2d commit 3d3c833
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
47 changes: 24 additions & 23 deletions include/parrot/pointer_array.h
@@ -1,5 +1,5 @@
/* /*
Copyright (C) 2010-2011, Parrot Foundation. Copyright (C) 2010-2012, Parrot Foundation.
=head1 NAME =head1 NAME
Expand Down Expand Up @@ -84,10 +84,9 @@ Insert pointer into the array.
static static
PARROT_INLINE PARROT_INLINE
void * void *
Parrot_pa_insert(PARROT_INTERP, ARGIN(Parrot_Pointer_Array *self), ARGIN(void *ptr)) Parrot_pa_insert(ARGMOD(Parrot_Pointer_Array *self), ARGIN(void *ptr))
{ {
Parrot_Pointer_Array_Chunk *chunk; void *ret;
void *ret;


/* Reuse removed cell */ /* Reuse removed cell */
if (self->next_free) { if (self->next_free) {
Expand All @@ -98,27 +97,29 @@ Parrot_pa_insert(PARROT_INTERP, ARGIN(Parrot_Pointer_Array *self), ARGIN(void *p
ret = self->next_free; ret = self->next_free;
*self->next_free = ptr; *self->next_free = ptr;
self->next_free = next; self->next_free = next;
return ret;
} }

else {
/* If there is no free chunks */ Parrot_Pointer_Array_Chunk *chunk;
if (self->current_chunk >= self->total_chunks
|| !self->chunks[self->current_chunk]->num_free) { /* If there is no free chunks */
self->current_chunk = self->total_chunks++; if (self->current_chunk >= self->total_chunks
mem_internal_realloc_n_typed(self->chunks, || !self->chunks[self->current_chunk]->num_free) {
self->total_chunks, self->current_chunk = self->total_chunks++;
Parrot_Pointer_Array_Chunk*); mem_internal_realloc_n_typed(self->chunks,
self->chunks[self->current_chunk] = mem_internal_allocate_typed(Parrot_Pointer_Array_Chunk); self->total_chunks,
self->chunks[self->current_chunk]->num_free = CELL_PER_CHUNK; Parrot_Pointer_Array_Chunk*);
self->chunks[self->current_chunk]->next_free = 0; self->chunks[self->current_chunk] = mem_internal_allocate_typed(Parrot_Pointer_Array_Chunk);
self->chunks[self->current_chunk]->num_free = CELL_PER_CHUNK;
self->chunks[self->current_chunk]->next_free = 0;
}

chunk = self->chunks[self->current_chunk];
--chunk->num_free;
/* Invariant: all chunks after chunk->next_free are free */
/* We handle previously freed chunks early */
ret = &chunk->data[chunk->next_free];
chunk->data[chunk->next_free++] = ptr;
} }

chunk = self->chunks[self->current_chunk];
--chunk->num_free;
/* Invariant: all chunks after chunk->next_free are free */
/* We handle previously freed chunks early */
ret = &chunk->data[chunk->next_free];
chunk->data[chunk->next_free++] = ptr;
return ret; return ret;
} }


Expand Down
18 changes: 9 additions & 9 deletions src/gc/gc_gms.c
Expand Up @@ -937,7 +937,7 @@ gc_gms_cleanup_dirty_list(PARROT_INTERP,
PObj_live_CLEAR(pmc); PObj_live_CLEAR(pmc);
PObj_GC_on_dirty_list_CLEAR(pmc); PObj_GC_on_dirty_list_CLEAR(pmc);
Parrot_pa_remove(interp, dirty_list, item->ptr); Parrot_pa_remove(interp, dirty_list, item->ptr);
item->ptr = Parrot_pa_insert(interp, self->objects[gen], item); item->ptr = Parrot_pa_insert(self->objects[gen], item);
gc_gms_seal_object(interp, pmc); gc_gms_seal_object(interp, pmc);
} }
else { else {
Expand Down Expand Up @@ -1028,7 +1028,7 @@ gc_gms_process_work_list(PARROT_INTERP,
PARROT_ASSERT(!PObj_GC_on_dirty_list_TEST(pmc)); PARROT_ASSERT(!PObj_GC_on_dirty_list_TEST(pmc));


Parrot_pa_remove(interp, work_list, item->ptr); Parrot_pa_remove(interp, work_list, item->ptr);
item->ptr = Parrot_pa_insert(interp, self->objects[gen], item);); item->ptr = Parrot_pa_insert(self->objects[gen], item););


} }


Expand Down Expand Up @@ -1071,12 +1071,12 @@ gc_gms_sweep_pools(PARROT_INTERP, ARGMOD(MarkSweep_GC *self))
Parrot_pa_remove(interp, self->objects[i], item->ptr); Parrot_pa_remove(interp, self->objects[i], item->ptr);
/* If this was freshly allocated object in C stack - move it to dirty list */ /* If this was freshly allocated object in C stack - move it to dirty list */
if (PObj_GC_soil_root_TEST(pmc)) { if (PObj_GC_soil_root_TEST(pmc)) {
item->ptr = Parrot_pa_insert(interp, self->dirty_list, item); item->ptr = Parrot_pa_insert(self->dirty_list, item);
PObj_GC_soil_root_CLEAR(pmc); PObj_GC_soil_root_CLEAR(pmc);
PObj_GC_on_dirty_list_SET(pmc); PObj_GC_on_dirty_list_SET(pmc);
} }
else { else {
item->ptr = Parrot_pa_insert(interp, self->objects[i + 1], item); item->ptr = Parrot_pa_insert(self->objects[i + 1], item);
gc_gms_seal_object(interp, pmc); gc_gms_seal_object(interp, pmc);
} }
} }
Expand Down Expand Up @@ -1111,7 +1111,7 @@ gc_gms_sweep_pools(PARROT_INTERP, ARGMOD(MarkSweep_GC *self))
PObj_live_CLEAR(str); PObj_live_CLEAR(str);
if (move_to_old) { if (move_to_old) {
Parrot_pa_remove(interp, self->strings[i], item->ptr); Parrot_pa_remove(interp, self->strings[i], item->ptr);
item->ptr = Parrot_pa_insert(interp, self->strings[i + 1], item); item->ptr = Parrot_pa_insert(self->strings[i + 1], item);
SET_GEN_FLAGS(str, i + 1); SET_GEN_FLAGS(str, i + 1);
} }
} }
Expand Down Expand Up @@ -1170,7 +1170,7 @@ gc_gms_mark_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc))
PObj_live_SET(pmc); PObj_live_SET(pmc);


Parrot_pa_remove(interp, self->objects[gen], item->ptr); Parrot_pa_remove(interp, self->objects[gen], item->ptr);
item->ptr = Parrot_pa_insert(interp, self->work_list, item); item->ptr = Parrot_pa_insert(self->work_list, item);
} }


/* /*
Expand Down Expand Up @@ -1417,7 +1417,7 @@ gc_gms_allocate_pmc_header(PARROT_INTERP, UINTVAL flags)
interp->gc_sys->stats.mem_used_last_collect += sizeof (PMC); interp->gc_sys->stats.mem_used_last_collect += sizeof (PMC);


item = (pmc_alloc_struct *)Parrot_gc_pool_allocate(interp, pool); item = (pmc_alloc_struct *)Parrot_gc_pool_allocate(interp, pool);
item->ptr = Parrot_pa_insert(interp, self->objects[0], item); item->ptr = Parrot_pa_insert(self->objects[0], item);


return &(item->pmc); return &(item->pmc);
} }
Expand Down Expand Up @@ -1533,7 +1533,7 @@ gc_gms_allocate_string_header(PARROT_INTERP, SHIM(UINTVAL flags))
interp->gc_sys->stats.mem_used_last_collect += sizeof (STRING); interp->gc_sys->stats.mem_used_last_collect += sizeof (STRING);


item = (string_alloc_struct *)Parrot_gc_pool_allocate(interp, pool); item = (string_alloc_struct *)Parrot_gc_pool_allocate(interp, pool);
item->ptr = Parrot_pa_insert(interp, self->strings[0], item); item->ptr = Parrot_pa_insert(self->strings[0], item);


ret = &(item->str); ret = &(item->str);
memset(ret, 0, sizeof (STRING)); memset(ret, 0, sizeof (STRING));
Expand Down Expand Up @@ -1939,7 +1939,7 @@ gc_gms_write_barrier(PARROT_INTERP, ARGMOD(PMC *pmc))
return; return;


Parrot_pa_remove(interp, self->objects[gen], item->ptr); Parrot_pa_remove(interp, self->objects[gen], item->ptr);
item->ptr = Parrot_pa_insert(interp, self->dirty_list, item); item->ptr = Parrot_pa_insert(self->dirty_list, item);


pmc->flags |= PObj_GC_on_dirty_list_FLAG; pmc->flags |= PObj_GC_on_dirty_list_FLAG;


Expand Down
6 changes: 3 additions & 3 deletions src/gc/gc_ms2.c
Expand Up @@ -706,7 +706,7 @@ gc_ms2_allocate_pmc_header(PARROT_INTERP, UINTVAL flags)
interp->gc_sys->stats.memory_used += sizeof (PMC); interp->gc_sys->stats.memory_used += sizeof (PMC);


ptr = (pmc_alloc_struct *)Parrot_gc_pool_allocate(interp, pool); ptr = (pmc_alloc_struct *)Parrot_gc_pool_allocate(interp, pool);
ptr->ptr = Parrot_pa_insert(interp, self->objects, ptr); ptr->ptr = Parrot_pa_insert(self->objects, ptr);


return &ptr->pmc; return &ptr->pmc;
} }
Expand Down Expand Up @@ -760,7 +760,7 @@ gc_ms2_mark_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc))


if (!PObj_constant_TEST(pmc)) { if (!PObj_constant_TEST(pmc)) {
Parrot_pa_remove(interp, self->objects, item->ptr); Parrot_pa_remove(interp, self->objects, item->ptr);
item->ptr = Parrot_pa_insert(interp, self->new_objects, item); item->ptr = Parrot_pa_insert(self->new_objects, item);
} }


} }
Expand Down Expand Up @@ -815,7 +815,7 @@ gc_ms2_allocate_string_header(PARROT_INTERP, UINTVAL flags)
interp->gc_sys->stats.memory_used += sizeof (STRING); interp->gc_sys->stats.memory_used += sizeof (STRING);


ptr = (string_alloc_struct *)Parrot_gc_pool_allocate(interp, pool); ptr = (string_alloc_struct *)Parrot_gc_pool_allocate(interp, pool);
ptr->ptr = Parrot_pa_insert(interp, self->strings, ptr); ptr->ptr = Parrot_pa_insert(self->strings, ptr);


ret = &ptr->str; ret = &ptr->str;
memset(ret, 0, sizeof (STRING)); memset(ret, 0, sizeof (STRING));
Expand Down
28 changes: 14 additions & 14 deletions t/src/pointer_array.t
@@ -1,5 +1,5 @@
#!perl #!perl
# Copyright (C) 2006-2010, Parrot Foundation. # Copyright (C) 2006-2012, Parrot Foundation.


use strict; use strict;
use warnings; use warnings;
Expand Down Expand Up @@ -54,7 +54,7 @@ int main(int argc, char* argv[])
printf("ok 1\n"); printf("ok 1\n");
/* Push first pointer */ /* Push first pointer */
pi = Parrot_pa_insert(interp, pa, &i); pi = Parrot_pa_insert(pa, &i);
if (pa->total_chunks != 1) { if (pa->total_chunks != 1) {
printf("Fail to allocate 1 chunk"); printf("Fail to allocate 1 chunk");
Expand All @@ -70,7 +70,7 @@ int main(int argc, char* argv[])
/* Insert many pointers */ /* Insert many pointers */
for (count = CELL_PER_CHUNK * 2; count; count--) { for (count = CELL_PER_CHUNK * 2; count; count--) {
pi = Parrot_pa_insert(interp, pa, &i); pi = Parrot_pa_insert(pa, &i);
} }
if (pa->total_chunks < 2) { if (pa->total_chunks < 2) {
printf("Fail to allocate more chunks"); printf("Fail to allocate more chunks");
Expand Down Expand Up @@ -108,9 +108,9 @@ int main(int argc, char* argv[])
void *pi, *pj, *pk; void *pi, *pj, *pk;
/* Push first pointer */ /* Push first pointer */
pi = Parrot_pa_insert(interp, pa, &i); pi = Parrot_pa_insert(pa, &i);
pj = Parrot_pa_insert(interp, pa, &j); pj = Parrot_pa_insert(pa, &j);
pk = Parrot_pa_insert(interp, pa, &k); pk = Parrot_pa_insert(pa, &k);
POINTER_ARRAY_ITER(pa, POINTER_ARRAY_ITER(pa,
if (ptr == &i) if (ptr == &i)
Expand All @@ -120,7 +120,7 @@ int main(int argc, char* argv[])
else if (ptr == &k) else if (ptr == &k)
++count; ++count;
else { else {
printf("Unkown poiner! %p - %p %p %p", ptr, pi, pj, pk); printf("Unknown pointer! %p - %p %p %p", ptr, pi, pj, pk);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
); );
Expand All @@ -140,7 +140,7 @@ int main(int argc, char* argv[])
else if (ptr == &k) else if (ptr == &k)
++count; ++count;
else { else {
printf("Unkown poiner! %p - %p %p %p", ptr, pi, pj, pk); printf("Unknown pointer! %p - %p %p %p", ptr, pi, pj, pk);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
); );
Expand All @@ -156,7 +156,7 @@ int main(int argc, char* argv[])
if (ptr == &j) if (ptr == &j)
++count; ++count;
else { else {
printf("Unkown poiner! %p - %p %p %p", ptr, pi, pj, pk); printf("Unknown pointer! %p - %p %p %p", ptr, pi, pj, pk);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
); );
Expand All @@ -167,10 +167,10 @@ int main(int argc, char* argv[])
printf("ok 4\n"); printf("ok 4\n");
/* Push stuff back. Twice. */ /* Push stuff back. Twice. */
pi = Parrot_pa_insert(interp, pa, &i); pi = Parrot_pa_insert(pa, &i);
pi = Parrot_pa_insert(interp, pa, &i); pi = Parrot_pa_insert(pa, &i);
pk = Parrot_pa_insert(interp, pa, &k); pk = Parrot_pa_insert(pa, &k);
pk = Parrot_pa_insert(interp, pa, &k); pk = Parrot_pa_insert(pa, &k);
POINTER_ARRAY_ITER(pa, POINTER_ARRAY_ITER(pa,
if (ptr == &i) if (ptr == &i)
++count; ++count;
Expand All @@ -179,7 +179,7 @@ int main(int argc, char* argv[])
else if (ptr == &k) else if (ptr == &k)
++count; ++count;
else { else {
printf("Unkown poiner! %p - %p %p %p", ptr, pi, pj, pk); printf("Unknown pointer! %p - %p %p %p", ptr, pi, pj, pk);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
); );
Expand Down

0 comments on commit 3d3c833

Please sign in to comment.