diff --git a/src/pmc/NumMatrix2D.pmc b/src/pmc/NumMatrix2D.pmc index 3eac8c6..18ed156 100644 --- a/src/pmc/NumMatrix2D.pmc +++ b/src/pmc/NumMatrix2D.pmc @@ -53,7 +53,8 @@ pmclass NumMatrix2D auto_attrs { y_size = attrs->y; GET_INDICES_FROM_KEY(INTERP, key, x, y); if (x >= x_size || y >= y_size) - Parrot_ex_throw_from_c_args(INTERP, ...); + Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, + "NumMatrix2d: indices out of bounds"); return ITEM_XY_ROWMAJOR(attrs->storage, x_size, y_size, x, y); } diff --git a/src/pmc/NumMatrix2D.pmc~ b/src/pmc/NumMatrix2D.pmc~ index 475c724..18ed156 100644 --- a/src/pmc/NumMatrix2D.pmc~ +++ b/src/pmc/NumMatrix2D.pmc~ @@ -15,8 +15,26 @@ #define INDEX_MAX(a, b) (((a) >= (b))?(a):(b)) void -resize_matrix(PARROT_INTERP, PMC * self, INTVAL x, INTVAL y) +resize_matrix(PARROT_INTERP, PMC * self, INTVAL new_x, INTVAL new_y) { + Parrot_NumMatrix2D_attributes * const attrs = PARROT_NUMMATRIX2D(self); + const INTVAL old_x = attrs->x; + const INTVAL old_y = attrs->y; + const INTVAL newsize = new_x * new_y; + FLOATVAL * new_s = (FLOATVAL *)calloc(newsize * sizeof (FLOATVAL)); + FLOATVAL * old_s = attrs->storage; + const INTVAL min_x = INDEX_MIN(old_x, new_x); + const INTVAL min_y = INDEX_MIN(old_y, new_y); + INTVAL i, j; + for (i = 0; i < min_x; i++) { + for (j = 0; j < min_y; j++) { + ITEM_XY_ROWMAJOR(new_s, new_x, new_y, i, j) = + ITEM_XY_ROWMAJOR(old_s, old_x, old_y, i, j); + } + } + attrs->storage = new_s; + free(old_s); +} pmclass NumMatrix2D auto_attrs { @@ -35,7 +53,8 @@ pmclass NumMatrix2D auto_attrs { y_size = attrs->y; GET_INDICES_FROM_KEY(INTERP, key, x, y); if (x >= x_size || y >= y_size) - Parrot_ex_throw_from_c_args(INTERP, ...); + Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, + "NumMatrix2d: indices out of bounds"); return ITEM_XY_ROWMAJOR(attrs->storage, x_size, y_size, x, y); } @@ -49,4 +68,4 @@ pmclass NumMatrix2D auto_attrs { resize_matrix(INTERP, SELF, x, y); ITEM_XY_ROWMAJOR(attrs->storage, x_size, y_size, x, y) = value; } -} \ No newline at end of file +}