Skip to content

Commit

Permalink
Fix iterate_function_inplace to actually do the right thing without s…
Browse files Browse the repository at this point in the history
…egfaulting
  • Loading branch information
Whiteknight committed Nov 6, 2009
1 parent 382a6a9 commit 24b8b55
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/pmc/nummatrix2d.pmc
Expand Up @@ -513,17 +513,19 @@ value with the return value of the called function.
*/

METHOD iterate_function_inplace(PMC * func, PMC * args :slurpy) {
Parrot_NumMatrix2D_attributes * const attrs =
(Parrot_NumMatrix2D_attributes *) PARROT_NUMMATRIX2D(SELF);
Parrot_NumMatrix2D_attributes * const attrs = PARROT_NUMMATRIX2D(SELF);
const INTVAL x_size = attrs->x;
const INTVAL y_size = attrs->y;
const INTVAL newsize = x_size * y_size;
FLOATVAL * old_s = attrs->storage;
FLOATVAL * new_s = (FLOATVAL *)mem_sys_allocate_zeroed(newsize * sizeof (FLOATVAL));

INTVAL i, j;
for (i = 0; i < y_size; j++) {
for (j = 0; j < x_size; i++) {

if (newsize == 0 || old_s == NULL)
RETURN();

for (j = 0; j < y_size; j++) {
for (i = 0; i < x_size; i++) {
FLOATVAL value = ITEM_XY_ROWMAJOR(old_s, x_size, y_size, i, j);
FLOATVAL result = 0.0;
Parrot_ext_call(INTERP, func, "PNIIPf->N", SELF, value, i, j, args, &result);
Expand Down

0 comments on commit 24b8b55

Please sign in to comment.