Changeset 3bfc79e1f3545570168565ca6300ef50bb20841b

Show
Ignore:
Timestamp:
11/18/10 21:28:34 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1290115714 +0000
git-parent:

[3821135574760be709319f24bb718263569486b4]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1290115714 +0000
Message:

fixes #327

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua_noit.c

    refa9375 r3bfc79e  
    11121112} 
    11131113 
     1114struct gunzip_crutch { 
     1115  z_stream *stream; 
     1116  void *scratch_buffer; 
     1117}; 
    11141118static int 
    11151119nl_gunzip_deflate(lua_State *L) { 
     1120  struct gunzip_crutch *crutch; 
    11161121  const char *input; 
    11171122  size_t inlen; 
     
    11271132  } 
    11281133 
    1129   stream = lua_touserdata(L, lua_upvalueindex(1)); 
     1134  crutch = lua_touserdata(L, lua_upvalueindex(1)); 
     1135  stream = crutch->stream; 
    11301136 
    11311137  input = lua_tolstring(L, 1, &inlen); 
     
    11771183    return 1; 
    11781184  } 
     1185  if(data) free(data); 
     1186  switch(err) { 
     1187    case Z_NEED_DICT: luaL_error(L, "zlib: dictionary error"); break; 
     1188    case Z_STREAM_ERROR: luaL_error(L, "zlib: stream error"); break; 
     1189    case Z_DATA_ERROR: luaL_error(L, "zlib: data error"); break; 
     1190    case Z_MEM_ERROR: luaL_error(L, "zlib: out-of-memory"); break; 
     1191    case Z_BUF_ERROR: luaL_error(L, "zlib: buffer error"); break; 
     1192    case Z_VERSION_ERROR: luaL_error(L, "zlib: version mismatch"); break; 
     1193    case Z_ERRNO: luaL_error(L, strerror(errno)); break; 
     1194  } 
    11791195  lua_pushnil(L); 
    11801196  return 1; 
     
    11821198static int 
    11831199nl_gunzip(lua_State *L) { 
     1200  struct gunzip_crutch *crutch; 
    11841201  z_stream *stream; 
    11851202   
    1186   stream = (z_stream *)lua_newuserdata(L, sizeof(*stream)); 
    1187   memset(stream, 0, sizeof(*stream)); 
     1203  crutch = (struct gunzip_crutch *)lua_newuserdata(L, sizeof(*crutch)); 
     1204  crutch->stream = malloc(sizeof(*stream)); 
     1205  memset(crutch->stream, 0, sizeof(*crutch->stream)); 
    11881206  luaL_getmetatable(L, "noit.gunzip"); 
    11891207  lua_setmetatable(L, -2); 
    11901208 
    1191   stream->next_in = NULL; 
    1192   stream->avail_in = 0; 
    1193   stream->next_out = malloc(DEFLATE_CHUNK_SIZE); 
    1194   stream->avail_out = stream->next_out ? DEFLATE_CHUNK_SIZE : 0; 
    1195   inflateInit2(stream, MAX_WBITS+32); 
     1209  crutch->stream->next_in = NULL; 
     1210  crutch->stream->avail_in = 0; 
     1211  crutch->scratch_buffer = 
     1212    crutch->stream->next_out = malloc(DEFLATE_CHUNK_SIZE); 
     1213  crutch->stream->avail_out = crutch->stream->next_out ? DEFLATE_CHUNK_SIZE : 0; 
     1214  inflateInit2(crutch->stream, MAX_WBITS+32); 
    11961215 
    11971216  lua_pushcclosure(L, nl_gunzip_deflate, 1); 
     
    12001219static int 
    12011220noit_lua_gunzip_gc(lua_State *L) { 
    1202   z_stream *stream
    1203   stream = (z_stream *)lua_touserdata(L,1); 
    1204   if(stream->next_out) free(stream->next_out); 
    1205   inflateEnd(stream); 
     1221  struct gunzip_crutch *crutch
     1222  crutch = (struct gunzip_crutch *)lua_touserdata(L,1); 
     1223  if(crutch->scratch_buffer) free(crutch->scratch_buffer); 
     1224  inflateEnd(crutch->stream); 
    12061225  return 0; 
    12071226}