source: trunk/package/lua/patches/040-gzip-source-loader.patch @ 15109

Last change on this file since 15109 was 15109, checked in by jow, 7 years ago

[package] lua: add zlib build dependency, fix inaccuracy in gzip loader

File size: 4.1 KB
  • src/Makefile

    diff -ur lua-5.1.4.orig/src/Makefile lua-5.1.4/src/Makefile
    old new  
    1212AR= ar rcu 
    1313RANLIB= ranlib 
    1414RM= rm -f 
    15 LIBS= -lm $(MYLIBS) 
     15LIBS= -lm -lz $(MYLIBS) 
    1616 
    1717MYCFLAGS= 
    1818MYLDFLAGS= 
  • src/lauxlib.c

    diff -ur lua-5.1.4.orig/src/lauxlib.c lua-5.1.4/src/lauxlib.c
    old new  
    1111#include <stdio.h> 
    1212#include <stdlib.h> 
    1313#include <string.h> 
     14#include <zlib.h> 
    1415 
    1516 
    1617/* This file uses only the official API of Lua. 
     
    535536  char buff[LUAL_BUFFERSIZE]; 
    536537} LoadF; 
    537538 
     539typedef struct LoadGZ { 
     540  int first_chunk; 
     541  gzFile f; 
     542  char buffer[LUAL_GZLDBUFFER]; 
     543} LoadGZ; 
     544 
    538545 
    539546static const char *getF (lua_State *L, void *ud, size_t *size) { 
    540547  LoadF *lf = (LoadF *)ud; 
     
    550557} 
    551558 
    552559 
     560static const char *getGZ (lua_State *L, void *ud, size_t *size) { 
     561  LoadGZ *lf = (LoadGZ *)ud; 
     562  char *sp = 0; 
     563  (void)L; 
     564  if (gzeof(lf->f)) return NULL; 
     565  *size = gzread(lf->f, lf->buffer, sizeof(lf->buffer)); 
     566  if (*size > 0) { 
     567    if (lf->first_chunk) { 
     568      lf->first_chunk = 0; 
     569      if ((lf->buffer[0] == '#') && (lf->buffer[1] == '!') && 
     570          (sp=strstr(lf->buffer, "\n")) != NULL) 
     571      { 
     572        *size -= ((uint)sp - (uint)lf->buffer); 
     573        return sp; 
     574      } 
     575    } 
     576    return lf->buffer; 
     577  } 
     578  return NULL; 
     579} 
     580 
     581 
    553582static int errfile (lua_State *L, const char *what, int fnameindex) { 
    554583  const char *serr = strerror(errno); 
    555584  const char *filename = lua_tostring(L, fnameindex) + 1; 
     
    560589 
    561590 
    562591LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { 
     592  if ((filename != NULL) && strstr(filename, ".lua.gz")) { 
     593    return luaL_loadfile_gzip(L, filename); 
     594  } 
     595  else { 
     596    return luaL_loadfile_plain(L, filename); 
     597  } 
     598} 
     599 
     600 
     601LUALIB_API int luaL_loadfile_gzip (lua_State *L, const char *filename) { 
     602  LoadGZ gzf; 
     603  int status; 
     604  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */ 
     605  lua_pushfstring(L, "@%s", filename); 
     606  gzf.f = gzopen(filename, "r"); 
     607  gzf.first_chunk = 1; 
     608  if (gzf.f == Z_NULL) return errfile(L, "open", fnameindex); 
     609  status = lua_load(L, getGZ, &gzf, lua_tostring(L, -1)); 
     610  (void)gzclose(gzf.f); 
     611  lua_remove(L, fnameindex); 
     612  return status; 
     613} 
     614 
     615   
     616LUALIB_API int luaL_loadfile_plain (lua_State *L, const char *filename) { 
    563617  LoadF lf; 
    564618  int status, readstatus; 
    565619  int c; 
  • src/lauxlib.h

    diff -ur lua-5.1.4.orig/src/lauxlib.h lua-5.1.4/src/lauxlib.h
    old new  
    8181LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 
    8282 
    8383LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 
     84LUALIB_API int (luaL_loadfile_gzip) (lua_State *L, const char *filename); 
     85LUALIB_API int (luaL_loadfile_plain) (lua_State *L, const char *filename); 
    8486LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 
    8587                                  const char *name); 
    8688LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 
  • src/luaconf.h

    diff -ur lua-5.1.4.orig/src/luaconf.h lua-5.1.4/src/luaconf.h
    old new  
    101101#define LUA_CDIR        LUA_ROOT "lib/lua/5.1/" 
    102102#define LUA_PATH_DEFAULT  \ 
    103103                "./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \ 
    104                             LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua" 
     104                            LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua;" \ 
     105                "./?.lua.gz;"  LUA_LDIR"?.lua.gz;"  LUA_LDIR"?/init.lua.gz;" \ 
     106                               LUA_CDIR"?.lua.gz;"  LUA_CDIR"?/init.lua.gz" 
    105107#define LUA_CPATH_DEFAULT \ 
    106108        "./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so" 
    107109#endif 
     
    506508*/ 
    507509#define LUAL_BUFFERSIZE         BUFSIZ 
    508510 
     511 
     512/* 
     513@@ LUAL_GZLDBUFFER is the buffer size used by the gzip source loader. 
     514*/ 
     515#define LUAL_GZLDBUFFER         8192 
     516 
    509517/* }================================================================== */ 
    510518 
    511519 
Note: See TracBrowser for help on using the repository browser.