static int lcairo_image_destroy(lua_State *L){ tImage *p=luaT_checkudata(L,1,tImage_id); luaT_free(L,p->data); cairo_surface_destroy(p->surf); luaT_free(L,p); lua_settop(L,1); return 1; }
static int torch_DiskFile_free(lua_State *L) { DiskFile *file = luaT_checkudata(L, 1, torch_DiskFile_id); if(file->handle) fclose(file->handle); luaT_free(L, file->name); luaT_free(L, file); return 0; }
static int cutorch_Event_free(lua_State *L) { cudaEvent_t *event = luaT_checkudata(L, 1, "cutorch.Event"); THCudaCheck(cudaEventDestroy(*event)); luaT_free(L, event); return 0; }
static int pa_stream_free(lua_State *L) { pa_Stream *stream = NULL; int narg = lua_gettop(L); if(narg == 1 && luaT_isudata(L, 1, "pa.Stream")) stream = luaT_toudata(L, 1, "pa.Stream"); else luaL_error(L, "expected arguments: Stream"); if(stream->id) Pa_CloseStream(stream->id); /* should also free input/output buffers */ luaT_free(L, stream); return 0; }
void* luaT_realloc(lua_State *L, void *ptr, long size) { if(!ptr) return(luaT_alloc(L, size)); if(size == 0) { luaT_free(L, ptr); return NULL; } if(size < 0) luaL_error(L, "$ Torch: invalid memory size -- maybe an overflow?"); ptr = realloc(ptr, size); if(!ptr) luaL_error(L, "$ Torch: not enough memory: you tried to reallocate %dGB. Buy new RAM!", size/1073741824); return ptr; }