fix getsup (HH)
[luatex.git] / source / libs / luajit / LuaJIT-PATCHES / patch-01-LuaJITTeX
blob2e8220e0c36da3ff94588671c389faec82e65fdc
1 diff -bur LuaJIT-src-orig/src/lauxlib.h LuaJIT-src/src/lauxlib.h
2 --- LuaJIT-src-orig/src/lauxlib.h       2016-03-07 09:43:42.708069718 +0100
3 +++ LuaJIT-src/src/lauxlib.h    2016-03-04 16:52:23.000000000 +0100
4 @@ -86,6 +86,32 @@
5                                 int level);
6  
7  
9 +/*
10 +** {======================================================
11 +** File handles for IO library
12 +** =======================================================
13 +*/
15 +/*
16 +** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
17 +** initial structure 'luaL_Stream' (it may contain other fields
18 +** after that initial structure).
19 +*/
21 +#define LUA_FILEHANDLE          "FILE*"
24 +typedef struct luaL_Stream {
25 +  FILE *f;  /* stream (NULL for incompletely created streams) */
26 +  lua_CFunction closef;  /* to close stream (NULL for closed streams) */
27 +} luaL_Stream;
29 +/* }====================================================== */
34  /*
35  ** ===============================================================
36  ** some useful macros
37 @@ -144,6 +170,8 @@
38  LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
39  LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
41 +/* Luajittex needs this one because it overloads loadfile */
42 +LUALIB_API int (RESERVED_load_aux_JIT) (lua_State *L, int status, int envarg);
44  /* }====================================================== */
46 diff -bur LuaJIT-src-orig/src/lib_init.c LuaJIT-src/src/lib_init.c
47 --- LuaJIT-src-orig/src/lib_init.c      2016-03-07 09:43:42.720069718 +0100
48 +++ LuaJIT-src/src/lib_init.c   2016-03-07 11:47:15.847946480 +0100
49 @@ -26,6 +26,7 @@
50    { LUA_DBLIBNAME,     luaopen_debug },
51    { LUA_BITLIBNAME,    luaopen_bit },
52    { LUA_JITLIBNAME,    luaopen_jit },
53 +  { LUA_BITLIBNAME_32, luaopen_bit32 },
54    { NULL,              NULL }
55  };
57 diff -bur LuaJIT-src-orig/src/lib_package.c LuaJIT-src/src/lib_package.c
58 --- LuaJIT-src-orig/src/lib_package.c   2016-03-07 09:43:42.712069718 +0100
59 +++ LuaJIT-src/src/lib_package.c        2016-03-07 11:49:15.655944489 +0100
60 @@ -362,6 +362,29 @@
61    return 1;  /* library loaded successfully */
62  }
64 +#define LUA_POF                "luaopen_"
65 +#define LUA_OFSEP      "_"
66 +#define POF            LUA_POF
68 +static const char *mkfuncname (lua_State *L, const char *modname) {
69 +  const char *funcname;
70 +  const char *mark = strchr(modname, *LUA_IGMARK);
71 +  if (mark) modname = mark + 1;
72 +  funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
73 +  funcname = lua_pushfstring(L, POF"%s", funcname);
74 +  lua_remove(L, -2);  /* remove 'gsub' result */
75 +  return funcname;
79 +int loader_C_luatex (lua_State *L, const char *name, const char *filename) {
80 +  const char *funcname;
81 +  funcname = mkfuncname(L, name);
82 +  if (ll_loadfunc(L, filename, funcname,0) != 0)
83 +    loaderror(L, filename);
84 +  return 1;  /* library loaded successfully */
87  static int lj_cf_package_loader_croot(lua_State *L)
88  {
89    const char *filename;
90 @@ -381,6 +404,21 @@
91    return 1;
92  }
94 +int loader_Call_luatex (lua_State *L, const char *name, const char *filename) {
95 +  const char *funcname;
96 +  int stat;
97 +  if (filename == NULL) return 1;  /* root not found */
98 +  funcname = mkfuncname(L, name);
99 +  if ((stat = ll_loadfunc(L, filename, funcname,0)) != 0) {
100 +    if (stat != PACKAGE_ERR_FUNC) loaderror(L, filename);  /* real error */
101 +    lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
102 +                       name, filename);
103 +    return 1;  /* function not found */
104 +  }
105 +  return 1;  /* library loaded successfully */
109  static int lj_cf_package_loader_preload(lua_State *L)
111    const char *name = luaL_checkstring(L, 1);
113 diff -bur LuaJIT-src-orig/src/lj_load.c LuaJIT-src/src/lj_load.c
114 --- LuaJIT-src-orig/src/lj_load.c       2016-03-07 09:43:42.716069718 +0100
115 +++ LuaJIT-src/src/lj_load.c    2016-03-07 12:09:10.771924621 +0100
116 @@ -166,3 +166,19 @@
117      return 1;
120 +/* -- Luajittex needs this one because it overloads loadfile  -- */
121 +LUALIB_API int RESERVED_load_aux_JIT(lua_State *L, int status, int envarg)
123 +  if (status == 0) {
124 +    if (tvistab(L->base+envarg-1)) {
125 +      GCfunc *fn = funcV(L->top-1);
126 +      GCtab *t = tabV(L->base+envarg-1);
127 +      setgcref(fn->c.env, obj2gco(t));
128 +      lj_gc_objbarrier(L, fn, t);
129 +    }
130 +    return 1;
131 +  } else {
132 +    setnilV(L->top-2);
133 +    return 2;
134 +  }
137 diff -bur LuaJIT-src-orig/src/lua.h LuaJIT-src/src/lua.h
138 --- LuaJIT-src-orig/src/lua.h   2016-03-07 09:43:42.716069718 +0100
139 +++ LuaJIT-src/src/lua.h        2016-03-07 11:56:24.855937353 +0100
140 @@ -103,6 +103,9 @@
141  typedef LUA_INTEGER lua_Integer;
144 +/* communication with LuaJiTTeX */
145 +LUA_API int luajittex_choose_hash_function; 
148  /*
149  ** state manipulation
150 @@ -349,6 +352,16 @@
151                        const char *chunkname, const char *mode);
154 +#define LUA_OPEQ 0
155 +#define LUA_OPLT 1
156 +#define LUA_OPLE 2
157 +#define LUA_OK  0
159 +/* see http://comments.gmane.org/gmane.comp.programming.swig/18673 */
160 +# define lua_rawlen lua_objlen 
164  struct lua_Debug {
165    int event;
166    const char *name;    /* (n) */
168 diff -bur LuaJIT-src-orig/src/lualib.h LuaJIT-src/src/lualib.h
169 --- LuaJIT-src-orig/src/lualib.h        2016-03-07 09:43:42.724069718 +0100
170 +++ LuaJIT-src/src/lualib.h     2016-03-07 11:58:19.151935453 +0100
171 @@ -22,6 +22,8 @@
172  #define LUA_JITLIBNAME "jit"
173  #define LUA_FFILIBNAME "ffi"
175 +#define LUA_BITLIBNAME_32  "bit32"
177  LUALIB_API int luaopen_base(lua_State *L);
178  LUALIB_API int luaopen_math(lua_State *L);
179  LUALIB_API int luaopen_string(lua_State *L);
180 @@ -34,6 +36,8 @@
181  LUALIB_API int luaopen_jit(lua_State *L);
182  LUALIB_API int luaopen_ffi(lua_State *L);
184 +LUALIB_API int luaopen_bit32(lua_State *L);
186  LUALIB_API void luaL_openlibs(lua_State *L);
188  #ifndef lua_assert
190 diff -bur LuaJIT-src-orig/src/Makefile LuaJIT-src/src/Makefile
191 --- LuaJIT-src-orig/src/Makefile        2016-03-07 09:43:42.716069718 +0100
192 +++ LuaJIT-src/src/Makefile     2016-03-07 12:02:42.319931078 +0100
193 @@ -99,7 +99,7 @@
194  # enabled by default. Some other features that *might* break some existing
195  # code (e.g. __pairs or os.execute() return values) can be enabled here.
196  # Note: this does not provide full compatibility with Lua 5.2 at this time.
197 -#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
198 +XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
200  # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
201  #XCFLAGS+= -DLUAJIT_DISABLE_JIT
202 @@ -471,7 +471,7 @@
203  LJVM_BOUT= $(LJVM_S)
204  LJVM_MODE= elfasm
206 -LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
207 +LJLIB_O= lib_base.o lib_math.o lbitlib.o lib_bit.o lib_string.o lib_table.o \
208          lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
209  LJLIB_C= $(LJLIB_O:.o=.c)
211 diff -bur LuaJIT-src-orig/src/Makefile.dep LuaJIT-src/src/Makefile.dep
212 --- LuaJIT-src-orig/src/Makefile.dep    2016-03-07 09:43:42.696069718 +0100
213 +++ LuaJIT-src/src/Makefile.dep 2016-03-07 12:05:19.343928468 +0100
214 @@ -6,6 +6,7 @@
215   lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \
216   lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \
217   lj_strfmt.h lj_lib.h lj_libdef.h
218 +lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
219  lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
220   lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \
221   lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \