diff options
author | Rui Guo <guorui.xt@gmail.com> | 2016-10-03 07:55:30 +0300 |
---|---|---|
committer | Rui Guo <guorui.xt@gmail.com> | 2016-10-03 07:55:30 +0300 |
commit | d643d5582e688faec4d0ad70fad9fb6ad215e3ce (patch) | |
tree | 62fe5fe87b5fbb35042fb8743378a497c77a5e19 /generic | |
parent | eb397ad0bd77cfe67a5e27f05d25217cba95ffef (diff) |
replace long with ptrdiff_t for memory size/offset etc
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Storage.c | 33 | ||||
-rw-r--r-- | generic/Tensor.c | 26 |
2 files changed, 31 insertions, 28 deletions
diff --git a/generic/Storage.c b/generic/Storage.c index 287796b..134dc63 100644 --- a/generic/Storage.c +++ b/generic/Storage.c @@ -20,15 +20,15 @@ static int torch_Storage_(new)(lua_State *L) int isShared = 0; if(luaT_optboolean(L, index + 1, 0)) isShared = TH_ALLOCATOR_MAPPED_SHARED; - long size = luaL_optlong(L, index + 2, 0); + ptrdiff_t size = luaL_optinteger(L, index + 2, 0); if (isShared && luaT_optboolean(L, index + 3, 0)) isShared = TH_ALLOCATOR_MAPPED_SHAREDMEM; storage = THStorage_(newWithMapping)(fileName, size, isShared); } else if(lua_type(L, index) == LUA_TTABLE) { - long size = lua_objlen(L, index); - long i; + ptrdiff_t size = lua_objlen(L, index); + ptrdiff_t i; if (allocator) storage = THStorage_(newWithAllocator)(size, allocator, NULL); else @@ -52,11 +52,11 @@ static int torch_Storage_(new)(lua_State *L) THStorage *src = luaT_checkudata(L, index, torch_Storage); real *ptr = src->data; - long offset = luaL_optlong(L, index + 1, 1) - 1; + ptrdiff_t offset = luaL_optinteger(L, index + 1, 1) - 1; if (offset < 0 || offset >= src->size) { luaL_error(L, "offset out of bounds"); } - long size = luaL_optlong(L, index + 2, src->size - offset); + ptrdiff_t size = luaL_optinteger(L, index + 2, src->size - offset); if (size < 1 || size > (src->size - offset)) { luaL_error(L, "size out of bounds"); } @@ -67,8 +67,8 @@ static int torch_Storage_(new)(lua_State *L) } else if(lua_type(L, index + 1) == LUA_TNUMBER) { - long size = luaL_optlong(L, index, 0); - real *ptr = (real *)luaL_optlong(L, index + 1, 0); + ptrdiff_t size = luaL_optinteger(L, index, 0); + real *ptr = (real *)luaL_optinteger(L, index + 1, 0); if (allocator) storage = THStorage_(newWithDataAndAllocator)(ptr, size, allocator, NULL); else @@ -77,7 +77,7 @@ static int torch_Storage_(new)(lua_State *L) } else { - long size = luaL_optlong(L, index, 0); + ptrdiff_t size = luaL_optinteger(L, index, 0); if (allocator) storage = THStorage_(newWithAllocator)(size, allocator, NULL); else @@ -104,7 +104,7 @@ static int torch_Storage_(free)(lua_State *L) static int torch_Storage_(resize)(lua_State *L) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); - long size = luaL_checklong(L, 2); + ptrdiff_t size = luaL_checkinteger(L, 2); /* int keepContent = luaT_optboolean(L, 3, 0); */ THStorage_(resize)(storage, size);/*, keepContent); */ lua_settop(L, 1); @@ -148,14 +148,14 @@ static int torch_Storage_(fill)(lua_State *L) static int torch_Storage_(elementSize)(lua_State *L) { - luaT_pushlong(L, THStorage_(elementSize)()); + luaT_pushinteger(L, THStorage_(elementSize)()); return 1; } static int torch_Storage_(__len__)(lua_State *L) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); - luaT_pushlong(L, storage->size); + luaT_pushinteger(L, storage->size); return 1; } @@ -164,7 +164,7 @@ static int torch_Storage_(__newindex__)(lua_State *L) if(lua_isnumber(L, 2)) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); - long index = luaL_checklong(L, 2) - 1; + ptrdiff_t index = luaL_checkinteger(L, 2) - 1; real number = luaG_(checkreal)(L, 3); THStorage_(set)(storage, index, number); lua_pushboolean(L, 1); @@ -180,7 +180,7 @@ static int torch_Storage_(__index__)(lua_State *L) if(lua_isnumber(L, 2)) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); - long index = luaL_checklong(L, 2) - 1; + ptrdiff_t index = luaL_checkinteger(L, 2) - 1; luaG_(pushreal)(L, THStorage_(get)(storage, index)); lua_pushboolean(L, 1); return 2; @@ -214,7 +214,7 @@ static int torch_Storage_(string)(lua_State *L) static int torch_Storage_(totable)(lua_State *L) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); - long i; + ptrdiff_t i; lua_newtable(L); for(i = 0; i < storage->size; i++) @@ -237,6 +237,9 @@ static int torch_Storage_(write)(lua_State *L) THStorage *storage = luaT_checkudata(L, 1, torch_Storage); THFile *file = luaT_checkudata(L, 2, "torch.File"); +#ifdef DEBUG + THAssert(storage->size < LONG_MAX); +#endif THFile_writeLongScalar(file, storage->size); THFile_writeRealRaw(file, storage->data, storage->size); @@ -247,7 +250,7 @@ static int torch_Storage_(read)(lua_State *L) { THStorage *storage = luaT_checkudata(L, 1, torch_Storage); THFile *file = luaT_checkudata(L, 2, "torch.File"); - long size = THFile_readLongScalar(file); + ptrdiff_t size = THFile_readLongScalar(file); THStorage_(resize)(storage, size); THFile_readRealRaw(file, storage->data, storage->size); diff --git a/generic/Tensor.c b/generic/Tensor.c index 3067213..abb7819 100644 --- a/generic/Tensor.c +++ b/generic/Tensor.c @@ -5,7 +5,7 @@ #include "luaG.h" static void torch_Tensor_(c_readTensorStorageSizeStride)(lua_State *L, int index, int allowNone, int allowTensor, int allowStorage, int allowStride, - THStorage **storage_, long *storageOffset_, THLongStorage **size_, THLongStorage **stride_); + THStorage **storage_, ptrdiff_t *storageOffset_, THLongStorage **size_, THLongStorage **stride_); static void torch_Tensor_(c_readSizeStride)(lua_State *L, int index, int allowStride, THLongStorage **size_, THLongStorage **stride_); @@ -29,7 +29,7 @@ static int torch_Tensor_(size)(lua_State *L) static int torch_Tensor_(elementSize)(lua_State *L) { - luaT_pushlong(L, THStorage_(elementSize)()); + luaT_pushinteger(L, THStorage_(elementSize)()); return 1; } @@ -55,7 +55,7 @@ static int torch_Tensor_(stride)(lua_State *L) static int torch_Tensor_(nDimension)(lua_State *L) { THTensor *tensor = luaT_checkudata(L, 1, torch_Tensor); - luaT_pushlong(L, tensor->nDimension); + luaT_pushinteger(L, tensor->nDimension); return 1; } @@ -76,21 +76,21 @@ static int torch_Tensor_(storage)(lua_State *L) static int torch_Tensor_(storageOffset)(lua_State *L) { THTensor *tensor = luaT_checkudata(L, 1, torch_Tensor); - luaT_pushlong(L, tensor->storageOffset+1); + luaT_pushinteger(L, tensor->storageOffset+1); return 1; } static int torch_Tensor_(new)(lua_State *L) { THTensor *tensor; - long storageOffset; + ptrdiff_t storageOffset; THLongStorage *size, *stride; if(lua_type(L, 1) == LUA_TTABLE) { - long i, j; + ptrdiff_t i, j; THLongStorage *counter; - long si = 0; + ptrdiff_t si = 0; int dimension = 0; int is_finished = 0; @@ -214,7 +214,7 @@ static int torch_Tensor_(set)(lua_State *L) { THTensor *self = luaT_checkudata(L, 1, torch_Tensor); THStorage *storage; - long storageOffset; + ptrdiff_t storageOffset; THLongStorage *size, *stride; torch_Tensor_(c_readTensorStorageSizeStride)(L, 2, 1, 1, 1, 1, @@ -651,7 +651,7 @@ static int torch_Tensor_(isSetTo)(lua_State *L) static int torch_Tensor_(nElement)(lua_State *L) { THTensor *tensor = luaT_checkudata(L, 1, torch_Tensor); - luaT_pushlong(L, THTensor_(nElement)(tensor)); + luaT_pushinteger(L, THTensor_(nElement)(tensor)); return 1; } @@ -752,7 +752,7 @@ static int torch_Tensor_(__newindex__)(lua_State *L) } else if((idx = luaT_toudata(L, 2, "torch.LongStorage"))) { - long index = THTensor_(storageOffset)(tensor); + ptrdiff_t index = THTensor_(storageOffset)(tensor); real value = luaG_(checkreal)(L,3); int dim; @@ -904,7 +904,7 @@ static int torch_Tensor_(__index__)(lua_State *L) } else if((idx = luaT_toudata(L, 2, "torch.LongStorage"))) { - long index = THTensor_(storageOffset)(tensor); + ptrdiff_t index = THTensor_(storageOffset)(tensor); int dim; THArgCheck(idx->size == tensor->nDimension, 2, "invalid size"); @@ -1071,7 +1071,7 @@ static void torch_Tensor_(c_readSizeStride)(lua_State *L, int index, int allowSt } static void torch_Tensor_(c_readTensorStorageSizeStride)(lua_State *L, int index, int allowNone, int allowTensor, int allowStorage, int allowStride, - THStorage **storage_, long *storageOffset_, THLongStorage **size_, THLongStorage **stride_) + THStorage **storage_, ptrdiff_t *storageOffset_, THLongStorage **size_, THLongStorage **stride_) { THTensor *src = NULL; THStorage *storage = NULL; @@ -1105,7 +1105,7 @@ static void torch_Tensor_(c_readTensorStorageSizeStride)(lua_State *L, int index } else { - *storageOffset_ = luaL_checklong(L, index+1)-1; + *storageOffset_ = luaL_checkinteger(L, index+1)-1; torch_Tensor_(c_readSizeStride)(L, index+2, allowStride, size_, stride_); } return; |