aboutsummaryrefslogtreecommitdiff
path: root/matrix/generic/mmatrix.c
diff options
context:
space:
mode:
authorcloudygoose <[email protected]>2015-05-31 11:14:20 +0800
committercloudygoose <[email protected]>2015-05-31 11:14:20 +0800
commitcfd06bb974c7088837a107d721b1311a4f160572 (patch)
tree4787a60f272e2cb9aa17ec1742a99b043487005e /matrix/generic/mmatrix.c
parentc4a70df7297f43e3251fa5c0149e813451e52391 (diff)
parentc6f6ac13a1cf00e440e998422f89b42c69b073a6 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'matrix/generic/mmatrix.c')
-rw-r--r--matrix/generic/mmatrix.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/matrix/generic/mmatrix.c b/matrix/generic/mmatrix.c
index 4b43572..3a9ae79 100644
--- a/matrix/generic/mmatrix.c
+++ b/matrix/generic/mmatrix.c
@@ -1,21 +1,22 @@
#ifdef NERV_GENERIC_MMATRIX
#include "matrix.h"
#include "elem_type.h"
-#define MATRIX_DATA_FREE(ptr) free(ptr)
-#define MATRIX_DATA_ALLOC(dptr, stride, width, height) \
- host_matrix_(alloc)(dptr, stride, width, height)
-#define MATRIX_DATA_STRIDE(ncol) (sizeof(MATRIX_ELEM) * (ncol))
-#define MATRIX_DATA_WRITE(data, idx, val) (data[idx] = val)
-#define MATRIX_DATA_READ(data, idx) (data[idx])
+#define MATRIX_DATA_FREE(L, ptr) free(ptr)
+#define MATRIX_DATA_ALLOC(L, dptr, stride, width, height) \
+ host_matrix_(alloc)(L, dptr, stride, width, height)
+#define MATRIX_DATA_WRITE(L, data, idx, val) (data[idx] = val)
+#define MATRIX_DATA_READ(L, data, idx) (data[idx])
#define MATRIX_INIT(L) host_matrix_(init)(L)
#define MATRIX_BASE_TNAME nerv_matrix_host_tname
#define NERV_GENERIC_MATRIX
#include "../../common.h"
#include "../../io/chunk_file.h"
-static void host_matrix_(alloc)(MATRIX_ELEM **dptr, size_t *stride,
- long width, long height) {
- *dptr = (MATRIX_ELEM *)malloc(width * height);
+static void host_matrix_(alloc)(lua_State *L,
+ MATRIX_ELEM **dptr, size_t *stride,
+ long width, long height) {
+ if ((*dptr = (MATRIX_ELEM *)malloc(width * height)) == NULL)
+ nerv_error(L, "mmatrix insufficient memory");
*stride = width;
}
@@ -53,7 +54,7 @@ int nerv_matrix_(load)(lua_State *L) {
FILE *fp = chunk->fp;
if (fscanf(fp, "%ld %ld", &nrow, &ncol) != 2)
return 0;
- self = nerv_matrix_(new_)(nrow, ncol);
+ self = nerv_matrix_(new_)(L, nrow, ncol);
for (i = 0; i < nrow; i++)
{
MATRIX_ELEM *row = MATRIX_ROW_PTR(self, i);