commit 70dd2ed3e69d5d18091185cc6840182882ea90b2 Author: Evgenii Terechkov Date: Sat Sep 6 23:22:19 2014 +0800 Patch http://www.lua.org/bugs.html#5.1.5-2 diff --git a/src/lzio.c b/src/lzio.c index 293edd5..48a76ce 100644 --- a/src/lzio.c +++ b/src/lzio.c @@ -22,10 +22,14 @@ int luaZ_fill (ZIO *z) { size_t size; lua_State *L = z->L; const char *buff; + if (z->eoz) return EOZ; lua_unlock(L); buff = z->reader(L, z->data, &size); lua_lock(L); - if (buff == NULL || size == 0) return EOZ; + if (buff == NULL || size == 0) { + z->eoz = 1; /* avoid calling reader function next time */ + return EOZ; + } z->n = size - 1; z->p = buff; return char2int(*(z->p++)); @@ -51,6 +55,7 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { z->data = data; z->n = 0; z->p = NULL; + z->eoz = 0; } diff --git a/src/lzio.h b/src/lzio.h index 51d695d..e98ce75 100644 --- a/src/lzio.h +++ b/src/lzio.h @@ -59,6 +59,7 @@ struct Zio { lua_Reader reader; void* data; /* additional data */ lua_State *L; /* Lua state (for reader) */ + int eoz; /* true if reader has no more data */ };