package/luvi: add patch to fix build issue with OpenSSL 1.1.1a
PATCH 1/1 package/luvi: add patch to fix build issue with OpenSSL 1.1.1a
Bump the bundled lua-openssl version to 0.7.4 for compatibility with OpenSSL 1.1.1a.
Note, that luvi 2.7.6 is the latest version providing a release tarball.
Runtime tested on Banana Pro, note that version string for lua-openssl does not match the tag name (0.7.4):
``` luvi v2.7.6 zlib: 1.2.11 libuv: 1.25.0 ssl: OpenSSL 1.1.1a 20 Nov 2018, lua-openssl 0.7.3 ```
Fixes:
http://autobuild.buildroot.net/results/e87994a3dc987f5aa101a5e721ac927e21453373
http://autobuild.buildroot.net/results/ea725ad90cfcd3c5e242268a593dcabd7297fe70
http://autobuild.buildroot.net/results/f2fb9eea0044e4a5f674742d29ea95af49cf5a45
http://autobuild.buildroot.net/results/de4daa1b930f907f06640dc98a708016217ddea5
.. and many more.
--- ...bundled-lua-openssl-to-version-0.7.4.patch | 31718 ++++++++++++++++ 1 file changed, 31718 insertions(+) create mode 100644 package/luvi/0003-Bump-bundled-lua-openssl-to-version-0.7.4.patch
package/luvi/0003-Bump-bundled-lua-openssl-to-version-0.7.4.patch new file +31718 -0
@@ -0,0 +1,31718 @@ +Bump bundled lua-openssl to version 0.7.4 for compatibility with OpenSSL 1.1.x. + +Signed-off-by: J?rg Krause <[email protected]> + +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/appveyor.yml luvi-src-v2.7.6/deps/lua-openssl/appveyor.yml +--- luvi-src-v2.7.6.orig/deps/lua-openssl/appveyor.yml 2019-02-13 11:31:40.277302045 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/appveyor.yml 2019-02-13 11:53:24.105128513 +0100 +@@ -9,7 +9,7 @@ install: + - git submodule update --recursive + - '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86' + - cd C:\ +-- ps: Start-FileDownload 'https://github.com/zhaozg/openssl-win32/blob/1.0.2/misc/luv.dll?raw=true' 'C:\luv.dll' ++#- ps: Start-FileDownload 'https://github.com/zhaozg/openssl-win32/blob/1.0.2/misc/luv.dll?raw=true' -FileName 'C:\luv.dll' + #- git clone https://github.com/zhaozg/openssl-win32.git C:\openssl-win32 + - git clone http://luajit.org/git/luajit-2.0.git C:\luajit-2.0 + build_script: +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/auxiliar.c luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/auxiliar.c +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/auxiliar.c 2019-02-13 11:31:40.330635015 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/auxiliar.c 2019-02-13 11:53:29.051738872 +0100 +@@ -7,6 +7,10 @@ + + #include "auxiliar.h" + ++#if LUA_VERSION_NUM<503 ++#include "c-api/compat-5.3.h" ++#endif ++ + /*=========================================================================*\ + * Exported functions + \*=========================================================================*/ +@@ -143,7 +147,7 @@ void *auxiliar_getgroupudata(lua_State * + * otherwise + \*-------------------------------------------------------------------------*/ + void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { +- return luaL_checkudata(L, objidx, classname); ++ return luaL_testudata(L, objidx, classname); + } + + /*-------------------------------------------------------------------------*\ +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/readme.md luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/readme.md +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/readme.md 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/readme.md 2019-02-13 11:53:29.051738872 +0100 +@@ -0,0 +1,65 @@ ++# lua-auxiliar ++ ++## Introduce ++ ++The origin auxiliar is part of [luasocket](https://github.com/diegonehab/luasocket), it's a general purpose class implemention lib for userdata with metatable. ++ ++``` ++/*=========================================================================*\ ++* Auxiliar routines for class hierarchy manipulation ++* LuaSocket toolkit (but completely independent of other LuaSocket modules) ++* ++* A LuaSocket class is a name associated with Lua metatables. A LuaSocket ++* group is a name associated with a class. A class can belong to any number ++* of groups. This module provides the functionality to: ++* ++* - create new classes ++* - add classes to groups ++* - set the class of objects ++* - check if an object belongs to a given class or group ++* - get the userdata associated to objects ++* - print objects in a pretty way ++* ++* LuaSocket class names follow the convention <module>{<class>}. Modules ++* can define any number of classes and groups. The module tcp.c, for ++* example, defines the classes tcp{master}, tcp{client} and tcp{server} and ++* the groups tcp{client,server} and tcp{any}. Module functions can then ++* perform type-checking on their arguments by either class or group. ++* ++* LuaSocket metatables define the __index metamethod as being a table. This ++* table has one field for each method supported by the class, and a field ++* "class" with the class name. ++* ++* The mapping from class name to the corresponding metatable and the ++* reverse mapping are done using lauxlib. ++\*=========================================================================*/ ++``` ++ ++## Update ++ ++I do minimual change, and add a few APIs for [lui](https://github.com/zhaozg/lui) and [lua-openssl](https://github.com/zhaozg/lua-openssl). ++TODO more ++ ++## License ++```text ++LuaSocket 3.0 license ++Copyright ? 2004-2018 Diego Nehab ++ ++Permission is hereby granted, free of charge, to any person obtaining a ++copy of this software and associated documentation files (the "Software"), ++to deal in the Software without restriction, including without limitation ++the rights to use, copy, modify, merge, publish, distribute, sublicense, ++and/or sell copies of the Software, and to permit persons to whom the ++Software is furnished to do so, subject to the following conditions: ++ ++The above copyright notice and this permission notice shall be included in ++all copies or substantial portions of the Software. ++ ++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ++AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++DEALINGS IN THE SOFTWARE. ++``` +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/subsidiar.c luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/subsidiar.c +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/subsidiar.c 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/subsidiar.c 2019-02-13 11:53:29.051738872 +0100 +@@ -0,0 +1,22 @@ ++#include "auxiliar.h" ++#include "subsidiar.h" ++ ++int auxiliar_enumerate(lua_State *L, int tidx, const LuaL_Enumeration *lenums) ++{ ++ int n = tidx < 0 ? tidx-2 : tidx; ++ const LuaL_Enumeration *e = lenums; ++ while( e->name!=NULL ) ++ { ++ lua_pushstring(L, e->name); ++ lua_pushinteger(L, e->val); ++ lua_rawset(L, n); ++ e++; ++ } ++ return 1; ++} ++ ++int auxiliar_checkoption(lua_State*L, int objidx, const char* def, const char* const slist[], const int ival[]) ++{ ++ int at = luaL_checkoption(L, objidx, def, slist); ++ return ival[at]; ++} +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/subsidiar.h luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/subsidiar.h +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/auxiliar/subsidiar.h 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/auxiliar/subsidiar.h 2019-02-13 11:53:29.051738872 +0100 +@@ -0,0 +1,51 @@ ++#ifndef SUBSIDIAR_H ++#define SUBSIDIAR_H ++ ++#include "lua.h" ++#include "lauxlib.h" ++ ++/* subsidiary part for auxiliar libirary */ ++ ++#define AUXILIAR_SET(L, tidx, lvar, cval, ltype) \ ++ do { \ ++ int n = tidx < 0 ? tidx-1 : tidx; \ ++ lua_push##ltype(L, (cval)); \ ++ lua_setfield(L, n, lvar); \ ++ } while(0) ++ ++#define AUXLIAR_GET(L, tidx, lvar, cvar, ltype) \ ++ do { \ ++ lua_getfield(L, tidx, lvar); \ ++ cvar = lua_to##ltype(L, -1); \ ++ lua_pop(L, 1); \ ++ } while(0) ++ ++#define AUXILIAR_SETLSTR(L, tidx, lvar, cval, len) \ ++ do { \ ++ int n = tidx < 0 ? tidx-1 : tidx; \ ++ lua_pushlstring(L, (const char*)(cval),len); \ ++ lua_setfield(L, n, lvar); \ ++ } while(0) ++ ++#define AUXILIAR_GETLSTR(L, tidx, lvar, cvar, len) \ ++ do { \ ++ lua_getfield(L, tidx, lvar); \ ++ cvar = lua_tolstring(L, -1, &len); \ ++ lua_setfield(L, n, lvar); \ ++ } while(0) ++ ++typedef struct ++{ ++ const char* name; ++ int val; ++} LuaL_Enumeration; ++ ++int auxiliar_enumerate(lua_State *L, int tidx, const LuaL_Enumeration *lenum); ++int auxiliar_checkoption(lua_State*L, ++ int objidx, ++ const char *def, ++ const char *const slist[], ++ const int ival[]); ++ ++#endif ++ +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.c luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.c +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.c 2019-02-13 11:31:40.330635015 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.c 2019-02-13 11:53:29.078405237 +0100 +@@ -3,6 +3,7 @@ + #include <string.h> + #include <ctype.h> + #include <errno.h> ++#include <stdio.h> + #include "compat-5.3.h" + + /* don't compile it again if it already is included via compat53.h */ +@@ -14,6 +15,75 @@ + /* definitions for Lua 5.1 only */ + #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 + ++#ifndef COMPAT53_FOPEN_NO_LOCK ++# if defined(_MSC_VER) ++# define COMPAT53_FOPEN_NO_LOCK 1 ++# else /* otherwise */ ++# define COMPAT53_FOPEN_NO_LOCK 0 ++# endif /* VC++ only so far */ ++#endif /* No-lock fopen_s usage if possible */ ++ ++#if defined(_MSC_VER) && COMPAT53_FOPEN_NO_LOCK ++# include <share.h> ++#endif /* VC++ _fsopen for share-allowed file read */ ++ ++#ifndef COMPAT53_HAVE_STRERROR_R ++# if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || \ ++ (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6)) ++# define COMPAT53_HAVE_STRERROR_R 1 ++# else /* none of the defines matched: define to 0 */ ++# define COMPAT53_HAVE_STRERROR_R 0 ++# endif /* have strerror_r of some form */ ++#endif /* strerror_r */ ++ ++#ifndef COMPAT53_HAVE_STRERROR_S ++# if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && \ ++ defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__) ++# define COMPAT53_HAVE_STRERROR_S 1 ++# else /* not VC++ or C11 */ ++# define COMPAT53_HAVE_STRERROR_S 0 ++# endif /* strerror_s from VC++ or C11 */ ++#endif /* strerror_s */ ++ ++#ifndef COMPAT53_LUA_FILE_BUFFER_SIZE ++# define COMPAT53_LUA_FILE_BUFFER_SIZE 4096 ++#endif /* Lua File Buffer Size */ ++ ++ ++static char* compat53_strerror (int en, char* buff, size_t sz) { ++#if COMPAT53_HAVE_STRERROR_R ++ /* use strerror_r here, because it's available on these specific platforms */ ++ if (sz > 0) { ++ buff[0] = '\0'; ++ /* we don't care whether the GNU version or the XSI version is used: */ ++ if (strerror_r(en, buff, sz)) { ++ /* Yes, we really DO want to ignore the return value! ++ * GCC makes that extra hard, not even a (void) cast will do. */ ++ } ++ if (buff[0] == '\0') { ++ /* Buffer is unchanged, so we probably have called GNU strerror_r which ++ * returned a static constant string. Chances are that strerror will ++ * return the same static constant string and therefore be thread-safe. */ ++ return strerror(en); ++ } ++ } ++ return buff; /* sz is 0 *or* strerror_r wrote into the buffer */ ++#elif COMPAT53_HAVE_STRERROR_S ++ /* for MSVC and other C11 implementations, use strerror_s since it's ++ * provided by default by the libraries */ ++ strerror_s(buff, sz, en); ++ return buff; ++#else ++ /* fallback, but strerror is not guaranteed to be threadsafe due to modifying ++ * errno itself and some impls not locking a static buffer for it ... but most ++ * known systems have threadsafe errno: this might only change if the locale ++ * is changed out from under someone while this function is being called */ ++ (void)buff; ++ (void)sz; ++ return strerror(en); ++#endif ++} ++ + + COMPAT53_API int lua_absindex (lua_State *L, int i) { + if (i < 0 && i > LUA_REGISTRYINDEX) +@@ -100,15 +170,17 @@ COMPAT53_API void lua_copy (lua_State *L + + COMPAT53_API void lua_len (lua_State *L, int i) { + switch (lua_type(L, i)) { +- case LUA_TSTRING: /* fall through */ ++ case LUA_TSTRING: ++ lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); ++ break; + case LUA_TTABLE: + if (!luaL_callmeta(L, i, "__len")) +- lua_pushnumber(L, (int)lua_objlen(L, i)); ++ lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); + break; + case LUA_TUSERDATA: + if (luaL_callmeta(L, i, "__len")) + break; +- /* maybe fall through */ ++ /* FALLTHROUGH */ + default: + luaL_error(L, "attempt to get length of a %s value", + lua_typename(L, lua_type(L, i))); +@@ -132,15 +204,6 @@ COMPAT53_API void lua_rawsetp (lua_State + } + + +-COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { +- lua_Integer n = lua_tointeger(L, i); +- if (isnum != NULL) { +- *isnum = (n != 0 || lua_isnumber(L, i)); +-} +- return n; +-} +- +- + COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { + lua_Number n = lua_tonumber(L, i); + if (isnum != NULL) { +@@ -183,14 +246,15 @@ COMPAT53_API int luaL_getsubtable (lua_S + } + + +-COMPAT53_API int luaL_len (lua_State *L, int i) { +- int res = 0, isnum = 0; ++COMPAT53_API lua_Integer luaL_len (lua_State *L, int i) { ++ lua_Integer res = 0; ++ int isnum = 0; + luaL_checkstack(L, 1, "not enough stack slots"); + lua_len(L, i); +- res = (int)lua_tointegerx(L, -1, &isnum); ++ res = lua_tointegerx(L, -1, &isnum); + lua_pop(L, 1); + if (!isnum) +- luaL_error(L, "object length is not a number"); ++ luaL_error(L, "object length is not an integer"); + return res; + } + +@@ -233,34 +297,6 @@ COMPAT53_API void *luaL_testudata (lua_S + } + + +-COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { +- if (!luaL_callmeta(L, idx, "__tostring")) { +- int t = lua_type(L, idx); +- switch (t) { +- case LUA_TNIL: +- lua_pushliteral(L, "nil"); +- break; +- case LUA_TSTRING: +- case LUA_TNUMBER: +- lua_pushvalue(L, idx); +- break; +- case LUA_TBOOLEAN: +- if (lua_toboolean(L, idx)) +- lua_pushliteral(L, "true"); +- else +- lua_pushliteral(L, "false"); +- break; +- default: +- lua_pushfstring(L, "%s: %p", lua_typename(L, t), +- lua_topointer(L, idx)); +- break; +- } +- } +- return lua_tolstring(L, -1, len); +-} +- +- +-#if !defined(COMPAT53_IS_LUAJIT) + static int compat53_countlevels (lua_State *L) { + lua_Debug ar; + int li = 1, le = 1; +@@ -361,26 +397,221 @@ COMPAT53_API void luaL_traceback (lua_St + + + COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { ++ const char *serr = NULL; + int en = errno; /* calls to Lua API may change this value */ ++ char buf[512] = { 0 }; + if (stat) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); ++ serr = compat53_strerror(en, buf, sizeof(buf)); + if (fname) +- lua_pushfstring(L, "%s: %s", fname, strerror(en)); ++ lua_pushfstring(L, "%s: %s", fname, serr); + else +- lua_pushstring(L, strerror(en)); ++ lua_pushstring(L, serr); + lua_pushnumber(L, (lua_Number)en); + return 3; + } + } + + ++static int compat53_checkmode (lua_State *L, const char *mode, const char *modename, int err) { ++ if (mode && strchr(mode, modename[0]) == NULL) { ++ lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode); ++ return err; ++ } ++ return LUA_OK; ++} ++ ++ ++typedef struct { ++ lua_Reader reader; ++ void *ud; ++ int has_peeked_data; ++ const char *peeked_data; ++ size_t peeked_data_size; ++} compat53_reader_data; ++ ++ ++static const char *compat53_reader (lua_State *L, void *ud, size_t *size) { ++ compat53_reader_data *data = (compat53_reader_data *)ud; ++ if (data->has_peeked_data) { ++ data->has_peeked_data = 0; ++ *size = data->peeked_data_size; ++ return data->peeked_data; ++ } else ++ return data->reader(L, data->ud, size); ++} ++ ++ ++COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) { ++ int status = LUA_OK; ++ compat53_reader_data compat53_data = { reader, data, 1, 0, 0 }; ++ compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); ++ if (compat53_data.peeked_data && compat53_data.peeked_data_size && ++ compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ ++ status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); ++ else ++ status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); ++ if (status != LUA_OK) ++ return status; ++ /* we need to call the original 5.1 version of lua_load! */ ++#undef lua_load ++ return lua_load(L, compat53_reader, &compat53_data, source); ++#define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) ++} ++ ++ ++typedef struct { ++ int n; /* number of pre-read characters */ ++ FILE *f; /* file being read */ ++ char buff[COMPAT53_LUA_FILE_BUFFER_SIZE]; /* area for reading file */ ++} compat53_LoadF; ++ ++ ++static const char *compat53_getF (lua_State *L, void *ud, size_t *size) { ++ compat53_LoadF *lf = (compat53_LoadF *)ud; ++ (void)L; /* not used */ ++ if (lf->n > 0) { /* are there pre-read characters to be read? */ ++ *size = lf->n; /* return them (chars already in buffer) */ ++ lf->n = 0; /* no more pre-read characters */ ++ } ++ else { /* read a block from file */ ++ /* 'fread' can return > 0 *and* set the EOF flag. If next call to ++ 'compat53_getF' called 'fread', it might still wait for user input. ++ The next check avoids this problem. */ ++ if (feof(lf->f)) return NULL; ++ *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */ ++ } ++ return lf->buff; ++} ++ ++ ++static int compat53_errfile (lua_State *L, const char *what, int fnameindex) { ++ char buf[512] = {0}; ++ const char *serr = compat53_strerror(errno, buf, sizeof(buf)); ++ const char *filename = lua_tostring(L, fnameindex) + 1; ++ lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); ++ lua_remove(L, fnameindex); ++ return LUA_ERRFILE; ++} ++ ++ ++static int compat53_skipBOM (compat53_LoadF *lf) { ++ const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */ ++ int c; ++ lf->n = 0; ++ do { ++ c = getc(lf->f); ++ if (c == EOF || c != *(const unsigned char *)p++) return c; ++ lf->buff[lf->n++] = (char)c; /* to be read by the parser */ ++ } while (*p != '\0'); ++ lf->n = 0; /* prefix matched; discard it */ ++ return getc(lf->f); /* return next character */ ++} ++ ++ ++/* ++** reads the first character of file 'f' and skips an optional BOM mark ++** in its beginning plus its first line if it starts with '#'. Returns ++** true if it skipped the first line. In any case, '*cp' has the ++** first "valid" character of the file (after the optional BOM and ++** a first-line comment). ++*/ ++static int compat53_skipcomment (compat53_LoadF *lf, int *cp) { ++ int c = *cp = compat53_skipBOM(lf); ++ if (c == '#') { /* first line is a comment (Unix exec. file)? */ ++ do { /* skip first line */ ++ c = getc(lf->f); ++ } while (c != EOF && c != '\n'); ++ *cp = getc(lf->f); /* skip end-of-line, if present */ ++ return 1; /* there was a comment */ ++ } ++ else return 0; /* no comment */ ++} ++ ++ ++COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) { ++ compat53_LoadF lf; ++ int status, readstatus; ++ int c; ++ int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ ++ if (filename == NULL) { ++ lua_pushliteral(L, "=stdin"); ++ lf.f = stdin; ++ } ++ else { ++ lua_pushfstring(L, "@%s", filename); ++#if defined(_MSC_VER) ++ /* This code is here to stop a deprecation error that stops builds ++ * if a certain macro is defined. While normally not caring would ++ * be best, some header-only libraries and builds can't afford to ++ * dictate this to the user. A quick check shows that fopen_s this ++ * goes back to VS 2005, and _fsopen goes back to VS 2003 .NET, ++ * possibly even before that so we don't need to do any version ++ * number checks, since this has been there since forever. */ ++ ++ /* TO USER: if you want the behavior of typical fopen_s/fopen, ++ * which does lock the file on VC++, define the macro used below to 0 */ ++#if COMPAT53_FOPEN_NO_LOCK ++ lf.f = _fsopen(filename, "r", _SH_DENYNO); /* do not lock the file in any way */ ++ if (lf.f == NULL) ++ return compat53_errfile(L, "open", fnameindex); ++#else /* use default locking version */ ++ if (fopen_s(&lf.f, filename, "r") != 0) ++ return compat53_errfile(L, "open", fnameindex); ++#endif /* Locking vs. No-locking fopen variants */ ++#else ++ lf.f = fopen(filename, "r"); /* default stdlib doesn't forcefully lock files here */ ++ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex); ++#endif ++ } ++ if (compat53_skipcomment(&lf, &c)) /* read initial portion */ ++ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ ++ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ ++#if defined(_MSC_VER) ++ if (freopen_s(&lf.f, filename, "rb", lf.f) != 0) ++ return compat53_errfile(L, "reopen", fnameindex); ++#else ++ lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ ++ if (lf.f == NULL) return compat53_errfile(L, "reopen", fnameindex); ++#endif ++ compat53_skipcomment(&lf, &c); /* re-read initial portion */ ++ } ++ if (c != EOF) ++ lf.buff[lf.n++] = (char)c; /* 'c' is the first character of the stream */ ++ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode); ++ readstatus = ferror(lf.f); ++ if (filename) fclose(lf.f); /* close file (even in case of errors) */ ++ if (readstatus) { ++ lua_settop(L, fnameindex); /* ignore results from 'lua_load' */ ++ return compat53_errfile(L, "read", fnameindex); ++ } ++ lua_remove(L, fnameindex); ++ return status; ++} ++ ++ ++COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) { ++ int status = LUA_OK; ++ if (sz > 0 && buff[0] == LUA_SIGNATURE[0]) { ++ status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); ++ } ++ else { ++ status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); ++ } ++ if (status != LUA_OK) ++ return status; ++ return luaL_loadbuffer(L, buff, sz, name); ++} ++ ++ + #if !defined(l_inspectstat) && \ + (defined(unix) || defined(__unix) || defined(__unix__) || \ +- defined(__TOS_AIX__) || defined(_SYSTYPE_BSD)) ++ defined(__TOS_AIX__) || defined(_SYSTYPE_BSD) || \ ++ (defined(__APPLE__) && defined(__MACH__))) + /* some form of unix; check feature macros in unistd.h for details */ + # include <unistd.h> + /* check posix version; the relevant include files and macros probably +@@ -414,7 +645,6 @@ COMPAT53_API int luaL_execresult (lua_St + return 3; + } + } +-#endif /* not COMPAT53_IS_LUAJIT */ + + + COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) { +@@ -501,6 +731,22 @@ COMPAT53_API int lua_isinteger (lua_Stat + } + + ++COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { ++ int ok = 0; ++ lua_Number n = lua_tonumberx(L, i, &ok); ++ if (ok) { ++ if (n == (lua_Integer)n) { ++ if (isnum) ++ *isnum = 1; ++ return (lua_Integer)n; ++ } ++ } ++ if (isnum) ++ *isnum = 0; ++ return 0; ++} ++ ++ + static void compat53_reverse (lua_State *L, int a, int b) { + for (; a < b; ++a, --b) { + lua_pushvalue(L, a); +@@ -537,7 +783,7 @@ COMPAT53_API void lua_seti (lua_State *L + + + #if !defined(lua_str2number) +-# define lua_str2number(s, p) strtod(s, p) ++# define lua_str2number(s, p) strtod((s), (p)) + #endif + + COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) { +@@ -555,6 +801,40 @@ COMPAT53_API size_t lua_stringtonumber ( + } + + ++COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { ++ if (!luaL_callmeta(L, idx, "__tostring")) { ++ int t = lua_type(L, idx), tt = 0; ++ char const* name = NULL; ++ switch (t) { ++ case LUA_TNIL: ++ lua_pushliteral(L, "nil"); ++ break; ++ case LUA_TSTRING: ++ case LUA_TNUMBER: ++ lua_pushvalue(L, idx); ++ break; ++ case LUA_TBOOLEAN: ++ if (lua_toboolean(L, idx)) ++ lua_pushliteral(L, "true"); ++ else ++ lua_pushliteral(L, "false"); ++ break; ++ default: ++ tt = luaL_getmetafield(L, idx, "__name"); ++ name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t); ++ lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx)); ++ if (tt != LUA_TNIL) ++ lua_replace(L, -2); ++ break; ++ } ++ } else { ++ if (!lua_isstring(L, -1)) ++ luaL_error(L, "'__tostring' must return a string"); ++ } ++ return lua_tolstring(L, -1, len); ++} ++ ++ + COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, + lua_CFunction openf, int glb) { + luaL_checkstack(L, 3, "not enough stack slots available"); +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.h luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.h +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.h 2019-02-13 11:31:40.330635015 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/c-api/compat-5.3.h 2019-02-13 11:53:29.078405237 +0100 +@@ -4,16 +4,18 @@ + #include <stddef.h> + #include <limits.h> + #include <string.h> +-#if defined( __cplusplus ) && !defined( COMPAT53_LUA_CPP ) ++#if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) + extern "C" { + #endif + #include <lua.h> + #include <lauxlib.h> +-#if defined( __cplusplus ) && !defined( COMPAT53_LUA_CPP ) ++#include <lualib.h> ++#if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) + } + #endif + + ++#undef COMPAT53_INCLUDE_SOURCE + #if defined(COMPAT53_PREFIX) + /* - change the symbol names of functions to avoid linker conflicts + * - compat-5.3.c needs to be compiled (and linked) separately +@@ -21,13 +23,11 @@ extern "C" { + # if !defined(COMPAT53_API) + # define COMPAT53_API extern + # endif +-# undef COMPAT53_INCLUDE_SOURCE + #else /* COMPAT53_PREFIX */ + /* - make all functions static and include the source. +- * - don't mess with the symbol names of functions + * - compat-5.3.c doesn't need to be compiled (and linked) separately + */ +-# define COMPAT53_PREFIX lua ++# define COMPAT53_PREFIX compat53 + # undef COMPAT53_API + # if defined(__GNUC__) || defined(__clang__) + # define COMPAT53_API __attribute__((__unused__)) static +@@ -51,29 +51,54 @@ extern "C" { + * lua_upvaluejoin + * lua_version + * lua_yieldk +- * luaL_loadbufferx +- * luaL_loadfilex + */ + +-/* PUC-Rio Lua uses lconfig_h as include guard for luaconf.h, +- * LuaJIT uses luaconf_h. If you use PUC-Rio's include files +- * but LuaJIT's library, you will need to define the macro +- * COMPAT53_IS_LUAJIT yourself! */ +-#if !defined(COMPAT53_IS_LUAJIT) && defined(luaconf_h) +-# define COMPAT53_IS_LUAJIT +-#endif +- +-#define LUA_OK 0 +-#define LUA_OPADD 0 +-#define LUA_OPSUB 1 +-#define LUA_OPMUL 2 +-#define LUA_OPDIV 3 +-#define LUA_OPMOD 4 +-#define LUA_OPPOW 5 +-#define LUA_OPUNM 6 +-#define LUA_OPEQ 0 +-#define LUA_OPLT 1 +-#define LUA_OPLE 2 ++#ifndef LUA_OK ++# define LUA_OK 0 ++#endif ++#ifndef LUA_OPADD ++# define LUA_OPADD 0 ++#endif ++#ifndef LUA_OPSUB ++# define LUA_OPSUB 1 ++#endif ++#ifndef LUA_OPMUL ++# define LUA_OPMUL 2 ++#endif ++#ifndef LUA_OPDIV ++# define LUA_OPDIV 3 ++#endif ++#ifndef LUA_OPMOD ++# define LUA_OPMOD 4 ++#endif ++#ifndef LUA_OPPOW ++# define LUA_OPPOW 5 ++#endif ++#ifndef LUA_OPUNM ++# define LUA_OPUNM 6 ++#endif ++#ifndef LUA_OPEQ ++# define LUA_OPEQ 0 ++#endif ++#ifndef LUA_OPLT ++# define LUA_OPLT 1 ++#endif ++#ifndef LUA_OPLE ++# define LUA_OPLE 2 ++#endif ++ ++/* LuaJIT/Lua 5.1 does not have the updated ++ * error codes for thread status/function returns (but some patched versions do) ++ * define it only if it's not found ++ */ ++#if !defined(LUA_ERRGCMM) ++/* Use + 2 because in some versions of Lua (Lua 5.1) ++ * LUA_ERRFILE is defined as (LUA_ERRERR+1) ++ * so we need to avoid it (LuaJIT might have something at this ++ * integer value too) ++ */ ++# define LUA_ERRGCMM (LUA_ERRERR + 2) ++#endif /* LUA_ERRGCMM define */ + + typedef size_t lua_Unsigned; + +@@ -86,6 +111,14 @@ typedef struct luaL_Buffer_53 { + } luaL_Buffer_53; + #define luaL_Buffer luaL_Buffer_53 + ++/* In PUC-Rio 5.1, userdata is a simple FILE* ++ * In LuaJIT, it's a struct where the first member is a FILE* ++ * We can't support the `closef` member ++ */ ++typedef struct luaL_Stream { ++ FILE *f; ++} luaL_Stream; ++ + #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) + COMPAT53_API int lua_absindex (lua_State *L, int i); + +@@ -99,20 +132,30 @@ COMPAT53_API int lua_compare (lua_State + COMPAT53_API void lua_copy (lua_State *L, int from, int to); + + #define lua_getuservalue(L, i) \ +- (lua_getfenv(L, i), lua_type(L, -1)) ++ (lua_getfenv((L), (i)), lua_type((L), -1)) + #define lua_setuservalue(L, i) \ +- (luaL_checktype(L, -1, LUA_TTABLE), lua_setfenv(L, i)) ++ (luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i))) + + #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) + COMPAT53_API void lua_len (lua_State *L, int i); + +-#define luaL_newlibtable(L, l) \ +- (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) +-#define luaL_newlib(L, l) \ +- (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) ++#define lua_pushstring(L, s) \ ++ (lua_pushstring((L), (s)), lua_tostring((L), -1)) ++ ++#define lua_pushlstring(L, s, len) \ ++ ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) ++ ++#ifndef luaL_newlibtable ++# define luaL_newlibtable(L, l) \ ++ (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) ++#endif ++#ifndef luaL_newlib ++# define luaL_newlib(L, l) \ ++ (luaL_newlibtable((L), (l)), luaL_register((L), NULL, (l))) ++#endif + + #define lua_pushglobaltable(L) \ +- lua_pushvalue(L, LUA_GLOBALSINDEX) ++ lua_pushvalue((L), LUA_GLOBALSINDEX) + + #define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp) + COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p); +@@ -120,10 +163,9 @@ COMPAT53_API int lua_rawgetp (lua_State + #define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp) + COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); + +-#define lua_rawlen(L, i) lua_objlen(L, i) ++#define lua_rawlen(L, i) lua_objlen((L), (i)) + +-#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx) +-COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); ++#define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) + + #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) + COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); +@@ -131,6 +173,15 @@ COMPAT53_API lua_Number lua_tonumberx (l + #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) + COMPAT53_API void luaL_checkversion (lua_State *L); + ++#define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) ++COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode); ++ ++#define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex) ++COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode); ++ ++#define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx) ++COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); ++ + #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) + COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); + +@@ -138,7 +189,7 @@ COMPAT53_API void luaL_checkstack (lua_S + COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); + + #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) +-COMPAT53_API int luaL_len (lua_State *L, int i); ++COMPAT53_API lua_Integer luaL_len (lua_State *L, int i); + + #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) + COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); +@@ -149,10 +200,6 @@ COMPAT53_API void luaL_setmetatable (lua + #define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata) + COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname); + +-#define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) +-COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); +- +-#if !defined(COMPAT53_IS_LUAJIT) + #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) + COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); + +@@ -161,12 +208,14 @@ COMPAT53_API int luaL_fileresult (lua_St + + #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) + COMPAT53_API int luaL_execresult (lua_State *L, int stat); +-#endif /* COMPAT53_IS_LUAJIT */ + + #define lua_callk(L, na, nr, ctx, cont) \ +- ((void)(ctx), (void)(cont), lua_call(L, na, nr)) ++ ((void)(ctx), (void)(cont), lua_call((L), (na), (nr))) + #define lua_pcallk(L, na, nr, err, ctx, cont) \ +- ((void)(ctx), (void)(cont), lua_pcall(L, na, nr, err)) ++ ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err))) ++ ++#define lua_resume(L, from, nargs) \ ++ ((void)(from), lua_resume((L), (nargs))) + + #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53) + COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B); +@@ -185,15 +234,15 @@ COMPAT53_API void luaL_pushresult (luaL_ + + #undef luaL_buffinitsize + #define luaL_buffinitsize(L, B, s) \ +- (luaL_buffinit(L, B), luaL_prepbuffsize(B, s)) ++ (luaL_buffinit((L), (B)), luaL_prepbuffsize((B), (s))) + + #undef luaL_prepbuffer + #define luaL_prepbuffer(B) \ +- luaL_prepbuffsize(B, LUAL_BUFFERSIZE) ++ luaL_prepbuffsize((B), LUAL_BUFFERSIZE) + + #undef luaL_addchar + #define luaL_addchar(B, c) \ +- ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize(B, 1)), \ ++ ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize((B), 1)), \ + ((B)->ptr[(B)->nelems++] = (c))) + + #undef luaL_addsize +@@ -202,23 +251,23 @@ COMPAT53_API void luaL_pushresult (luaL_ + + #undef luaL_addstring + #define luaL_addstring(B, s) \ +- luaL_addlstring(B, s, strlen(s)) ++ luaL_addlstring((B), (s), strlen((s))) + + #undef luaL_pushresultsize + #define luaL_pushresultsize(B, s) \ +- (luaL_addsize(B, s), luaL_pushresult(B)) ++ (luaL_addsize((B), (s)), luaL_pushresult((B))) + + #if defined(LUA_COMPAT_APIINTCASTS) + #define lua_pushunsigned(L, n) \ +- lua_pushinteger(L, (lua_Integer)(n)) ++ lua_pushinteger((L), (lua_Integer)(n)) + #define lua_tounsignedx(L, i, is) \ +- ((lua_Unsigned)lua_tointegerx(L, i, is)) ++ ((lua_Unsigned)lua_tointegerx((L), (i), (is))) + #define lua_tounsigned(L, i) \ +- lua_tounsignedx(L, i, NULL) ++ lua_tounsignedx((L), (i), NULL) + #define luaL_checkunsigned(L, a) \ +- ((lua_Unsigned)luaL_checkinteger(L, a)) ++ ((lua_Unsigned)luaL_checkinteger((L), (a))) + #define luaL_optunsigned(L, a, d) \ +- ((lua_Unsigned)luaL_optinteger(L, a, (lua_Integer)(d))) ++ ((lua_Unsigned)luaL_optinteger((L), (a), (lua_Integer)(d))) + #endif + + #endif /* Lua 5.1 only */ +@@ -233,13 +282,13 @@ typedef int lua_KContext; + typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); + + #define lua_dump(L, w, d, s) \ +- ((void)(s), lua_dump(L, w, d)) ++ ((void)(s), lua_dump((L), (w), (d))) + + #define lua_getfield(L, i, k) \ +- (lua_getfield(L, i, k), lua_type(L, -1)) ++ (lua_getfield((L), (i), (k)), lua_type((L), -1)) + + #define lua_gettable(L, i) \ +- (lua_gettable(L, i), lua_type(L, -1)) ++ (lua_gettable((L), (i)), lua_type((L), -1)) + + #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) + COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); +@@ -247,14 +296,17 @@ COMPAT53_API int lua_geti (lua_State *L, + #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) + COMPAT53_API int lua_isinteger (lua_State *L, int index); + ++#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53) ++COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); ++ + #define lua_numbertointeger(n, p) \ + ((*(p) = (lua_Integer)(n)), 1) + + #define lua_rawget(L, i) \ +- (lua_rawget(L, i), lua_type(L, -1)) ++ (lua_rawget((L), (i)), lua_type((L), -1)) + + #define lua_rawgeti(L, i, n) \ +- (lua_rawgeti(L, i, n), lua_type(L, -1)) ++ (lua_rawgeti((L), (i), (n)), lua_type((L), -1)) + + #define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate) + COMPAT53_API void lua_rotate (lua_State *L, int idx, int n); +@@ -265,11 +317,14 @@ COMPAT53_API void lua_seti (lua_State *L + #define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber) + COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s); + ++#define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) ++COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); ++ + #define luaL_getmetafield(L, o, e) \ +- (luaL_getmetafield(L, o, e) ? lua_type(L, -1) : LUA_TNIL) ++ (luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL) + + #define luaL_newmetatable(L, tn) \ +- (luaL_newmetatable(L, tn) ? (lua_pushstring(L, tn), lua_setfield(L, -2, "__name"), 1) : 0) ++ (luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0) + + #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53) + COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, +@@ -290,13 +345,16 @@ COMPAT53_API void luaL_requiref (lua_Sta + */ + + #define lua_getglobal(L, n) \ +- (lua_getglobal(L, n), lua_type(L, -1)) ++ (lua_getglobal((L), (n)), lua_type((L), -1)) + + #define lua_getuservalue(L, i) \ +- (lua_getuservalue(L, i), lua_type(L, -1)) ++ (lua_getuservalue((L), (i)), lua_type((L), -1)) ++ ++#define lua_pushlstring(L, s, len) \ ++ (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) + + #define lua_rawgetp(L, i, p) \ +- (lua_rawgetp(L, i, p), lua_type(L, -1)) ++ (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) + + #define LUA_KFUNCTION(_name) \ + static int (_name)(lua_State *L, int status, lua_KContext ctx); \ +@@ -308,30 +366,30 @@ COMPAT53_API void luaL_requiref (lua_Sta + static int (_name)(lua_State *L, int status, lua_KContext ctx) + + #define lua_pcallk(L, na, nr, err, ctx, cont) \ +- lua_pcallk(L, na, nr, err, ctx, cont ## _52) ++ lua_pcallk((L), (na), (nr), (err), (ctx), cont ## _52) + + #define lua_callk(L, na, nr, ctx, cont) \ +- lua_callk(L, na, nr, ctx, cont ## _52) ++ lua_callk((L), (na), (nr), (ctx), cont ## _52) + + #define lua_yieldk(L, nr, ctx, cont) \ +- lua_yieldk(L, nr, ctx, cont ## _52) ++ lua_yieldk((L), (nr), (ctx), cont ## _52) + + #ifdef lua_call + # undef lua_call + # define lua_call(L, na, nr) \ +- (lua_callk)(L, na, nr, 0, NULL) ++ (lua_callk)((L), (na), (nr), 0, NULL) + #endif + + #ifdef lua_pcall + # undef lua_pcall + # define lua_pcall(L, na, nr, err) \ +- (lua_pcallk)(L, na, nr, err, 0, NULL) ++ (lua_pcallk)((L), (na), (nr), (err), 0, NULL) + #endif + + #ifdef lua_yield + # undef lua_yield + # define lua_yield(L, nr) \ +- (lua_yieldk)(L, nr, 0, NULL) ++ (lua_yieldk)((L), (nr), 0, NULL) + #endif + + #endif /* Lua 5.2 only */ +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/compat53/init.lua luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/compat53/init.lua +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/compat53/init.lua 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/compat53/init.lua 2019-02-13 11:53:29.078405237 +0100 +@@ -0,0 +1,373 @@ ++local lua_version = _VERSION:sub(-3) ++ ++ ++if lua_version < "5.3" then ++ ++ local _G, pairs, require, select, type = ++ _G, pairs, require, select, type ++ local debug, io = debug, io ++ local unpack = lua_version == "5.1" and unpack or table.unpack ++ ++ local M = require("compat53.module") ++ ++ -- select the most powerful getmetatable function available ++ local gmt = type(debug) == "table" and debug.getmetatable or ++ getmetatable or function() return false end ++ -- metatable for file objects from Lua's standard io library ++ local file_meta = gmt(io.stdout) ++ ++ ++ -- make '*' optional for file:read and file:lines ++ if type(file_meta) == "table" and type(file_meta.__index) == "table" then ++ ++ local function addasterisk(fmt) ++ if type(fmt) == "string" and fmt:sub(1, 1) ~= "*" then ++ return "*"..fmt ++ else ++ return fmt ++ end ++ end ++ ++ local file_lines = file_meta.__index.lines ++ file_meta.__index.lines = function(self, ...) ++ local n = select('#', ...) ++ for i = 1, n do ++ local a = select(i, ...) ++ local b = addasterisk(a) ++ -- as an optimization we only allocate a table for the ++ -- modified format arguments when we have a '*' somewhere ++ if a ~= b then ++ local args = { ... } ++ args[i] = b ++ for j = i+1, n do ++ args[j] = addasterisk(args[j]) ++ end ++ return file_lines(self, unpack(args, 1, n)) ++ end ++ end ++ return file_lines(self, ...) ++ end ++ ++ local file_read = file_meta.__index.read ++ file_meta.__index.read = function(self, ...) ++ local n = select('#', ...) ++ for i = 1, n do ++ local a = select(i, ...) ++ local b = addasterisk(a) ++ -- as an optimization we only allocate a table for the ++ -- modified format arguments when we have a '*' somewhere ++ if a ~= b then ++ local args = { ... } ++ args[i] = b ++ for j = i+1, n do ++ args[j] = addasterisk(args[j]) ++ end ++ return file_read(self, unpack(args, 1, n)) ++ end ++ end ++ return file_read(self, ...) ++ end ++ ++ end -- got a valid metatable for file objects ++ ++ ++ -- changes for Lua 5.1 only ++ if lua_version == "5.1" then ++ ++ -- cache globals ++ local error, pcall, rawset, setmetatable, tostring, xpcall = ++ error, pcall, rawset, setmetatable, tostring, xpcall ++ local coroutine, package, string = coroutine, package, string ++ local coroutine_resume = coroutine.resume ++ local coroutine_running = coroutine.running ++ local coroutine_status = coroutine.status ++ local coroutine_yield = coroutine.yield ++ local io_type = io.type ++ ++ ++ -- detect LuaJIT (including LUAJIT_ENABLE_LUA52COMPAT compilation flag) ++ local is_luajit = (string.dump(function() end) or ""):sub(1, 3) == "\027LJ" ++ local is_luajit52 = is_luajit and ++ #setmetatable({}, { __len = function() return 1 end }) == 1 ++ ++ ++ -- make package.searchers available as an alias for package.loaders ++ local p_index = { searchers = package.loaders } ++ setmetatable(package, { ++ __index = p_index, ++ __newindex = function(p, k, v) ++ if k == "searchers" then ++ rawset(p, "loaders", v) ++ p_index.searchers = v ++ else ++ rawset(p, k, v) ++ end ++ end ++ }) ++ ++ ++ if type(file_meta) == "table" and type(file_meta.__index) == "table" then ++ if not is_luajit then ++ local function helper(_, var_1, ...) ++ if var_1 == nil then ++ if (...) ~= nil then ++ error((...), 2) ++ end ++ end ++ return var_1, ... ++ end ++ ++ local function lines_iterator(st) ++ return helper(st, st.f:read(unpack(st, 1, st.n))) ++ end ++ ++ local file_write = file_meta.__index.write ++ file_meta.__index.write = function(self, ...) ++ local res, msg, errno = file_write(self, ...) ++ if res then ++ return self ++ else ++ return nil, msg, errno ++ end ++ end ++ ++ file_meta.__index.lines = function(self, ...) ++ if io_type(self) == "closed file" then ++ error("attempt to use a closed file", 2) ++ end ++ local st = { f=self, n=select('#', ...), ... } ++ for i = 1, st.n do ++ local t = type(st[i]) ++ if t == "string" then ++ local fmt = st[i]:match("^*?([aln])") ++ if not fmt then ++ error("bad argument #"..(i+1).." to 'for iterator' (invalid format)", 2) ++ end ++ st[i] = "*"..fmt ++ elseif t ~= "number" then ++ error("bad argument #"..(i+1).." to 'for iterator' (invalid format)", 2) ++ end ++ end ++ return lines_iterator, st ++ end ++ end -- not luajit ++ end -- file_meta valid ++ ++ ++ -- the (x)pcall implementations start a new coroutine internally ++ -- to allow yielding even in Lua 5.1. to allow for accurate ++ -- stack traces we keep track of the nested coroutine activations ++ -- in the weak tables below: ++ local weak_meta = { __mode = "kv" } ++ -- maps the internal pcall coroutines to the user coroutine that ++ -- *should* be running if pcall didn't use coroutines internally ++ local pcall_mainOf = setmetatable({}, weak_meta) ++ -- table that maps each running coroutine started by pcall to ++ -- the coroutine that resumed it (user coroutine *or* pcall ++ -- coroutine!) ++ local pcall_previous = setmetatable({}, weak_meta) ++ -- reverse of `pcall_mainOf`. maps a user coroutine to the ++ -- currently active pcall coroutine started within it ++ local pcall_callOf = setmetatable({}, weak_meta) ++ -- similar to `pcall_mainOf` but is used only while executing ++ -- the error handler of xpcall (thus no nesting is necessary!) ++ local xpcall_running = setmetatable({}, weak_meta) ++ ++ -- handle debug functions ++ if type(debug) == "table" then ++ local debug_getinfo = debug.getinfo ++ local debug_traceback = debug.traceback ++ ++ if not is_luajit then ++ local function calculate_trace_level(co, level) ++ if level ~= nil then ++ for out = 1, 1/0 do ++ local info = (co==nil) and debug_getinfo(out, "") or debug_getinfo(co, out, "") ++ if info == nil then ++ local max = out-1 ++ if level <= max then ++ return level ++ end ++ return nil, level-max ++ end ++ end ++ end ++ return 1 ++ end ++ ++ local stack_pattern = "\nstack traceback:" ++ local stack_replace = "" ++ function debug.traceback(co, msg, level) ++ local lvl ++ local nilmsg ++ if type(co) ~= "thread" then ++ co, msg, level = coroutine_running(), co, msg ++ end ++ if msg == nil then ++ msg = "" ++ nilmsg = true ++ elseif type(msg) ~= "string" then ++ return msg ++ end ++ if co == nil then ++ msg = debug_traceback(msg, level or 1) ++ else ++ local xpco = xpcall_running[co] ++ if xpco ~= nil then ++ lvl, level = calculate_trace_level(xpco, level) ++ if lvl then ++ msg = debug_traceback(xpco, msg, lvl) ++ else ++ msg = msg..stack_pattern ++ end ++ lvl, level = calculate_trace_level(co, level) ++ if lvl then ++ local trace = debug_traceback(co, "", lvl) ++ msg = msg..trace:gsub(stack_pattern, stack_replace) ++ end ++ else ++ co = pcall_callOf[co] or co ++ lvl, level = calculate_trace_level(co, level) ++ if lvl then ++ msg = debug_traceback(co, msg, lvl) ++ else ++ msg = msg..stack_pattern ++ end ++ end ++ co = pcall_previous[co] ++ while co ~= nil do ++ lvl, level = calculate_trace_level(co, level) ++ if lvl then ++ local trace = debug_traceback(co, "", lvl) ++ msg = msg..trace:gsub(stack_pattern, stack_replace) ++ end ++ co = pcall_previous[co] ++ end ++ end ++ if nilmsg then ++ msg = msg:gsub("^\n", "") ++ end ++ msg = msg:gsub("\n\t%(tail call%): %?", "\000") ++ msg = msg:gsub("\n\t%.%.%.\n", "\001\n") ++ msg = msg:gsub("\n\t%.%.%.$", "\001") ++ msg = msg:gsub("(%z+)\001(%z+)", function(some, other) ++ return "\n\t(..."..#some+#other.."+ tail call(s)...)" ++ end) ++ msg = msg:gsub("\001(%z+)", function(zeros) ++ return "\n\t(..."..#zeros.."+ tail call(s)...)" ++ end) ++ msg = msg:gsub("(%z+)\001", function(zeros) ++ return "\n\t(..."..#zeros.."+ tail call(s)...)" ++ end) ++ msg = msg:gsub("%z+", function(zeros) ++ return "\n\t(..."..#zeros.." tail call(s)...)" ++ end) ++ msg = msg:gsub("\001", function() ++ return "\n\t..." ++ end) ++ return msg ++ end ++ end -- is not luajit ++ end -- debug table available ++ ++ ++ if not is_luajit52 then ++ local coroutine_running52 = M.coroutine.running ++ function M.coroutine.running() ++ local co, ismain = coroutine_running52() ++ if ismain then ++ return co, true ++ else ++ return pcall_mainOf[co] or co, false ++ end ++ end ++ end ++ ++ if not is_luajit then ++ local function pcall_results(current, call, success, ...) ++ if coroutine_status(call) == "suspended" then ++ return pcall_results(current, call, coroutine_resume(call, coroutine_yield(...))) ++ end ++ if pcall_previous then ++ pcall_previous[call] = nil ++ local main = pcall_mainOf[call] ++ if main == current then current = nil end ++ pcall_callOf[main] = current ++ end ++ pcall_mainOf[call] = nil ++ return success, ... ++ end ++ ++ local function pcall_exec(current, call, ...) ++ local main = pcall_mainOf[current] or current ++ pcall_mainOf[call] = main ++ if pcall_previous then ++ pcall_previous[call] = current ++ pcall_callOf[main] = call ++ end ++ return pcall_results(current, call, coroutine_resume(call, ...)) ++ end ++ ++ local coroutine_create52 = M.coroutine.create ++ ++ local function pcall_coroutine(func) ++ if type(func) ~= "function" then ++ local callable = func ++ func = function (...) return callable(...) end ++ end ++ return coroutine_create52(func) ++ end ++ ++ function M.pcall(func, ...) ++ local current = coroutine_running() ++ if not current then return pcall(func, ...) end ++ return pcall_exec(current, pcall_coroutine(func), ...) ++ end ++ ++ local function xpcall_catch(current, call, msgh, success, ...) ++ if not success then ++ xpcall_running[current] = call ++ local ok, result = pcall(msgh, ...) ++ xpcall_running[current] = nil ++ if not ok then ++ return false, "error in error handling ("..tostring(result)..")" ++ end ++ return false, result ++ end ++ return true, ... ++ end ++ ++ function M.xpcall(f, msgh, ...) ++ local current = coroutine_running() ++ if not current then ++ local args, n = { ... }, select('#', ...) ++ return xpcall(function() return f(unpack(args, 1, n)) end, msgh) ++ end ++ local call = pcall_coroutine(f) ++ return xpcall_catch(current, call, msgh, pcall_exec(current, call, ...)) ++ end ++ end -- not luajit ++ ++ end -- lua 5.1 ++ ++ ++ -- handle exporting to global scope ++ local function extend_table(from, to) ++ if from ~= to then ++ for k,v in pairs(from) do ++ if type(v) == "table" and ++ type(to[k]) == "table" and ++ v ~= to[k] then ++ extend_table(v, to[k]) ++ else ++ to[k] = v ++ end ++ end ++ end ++ end ++ ++ extend_table(M, _G) ++ ++end -- lua < 5.3 ++ ++-- vi: set expandtab softtabstop=3 shiftwidth=3 : +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/compat53/module.lua luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/compat53/module.lua +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/compat53/module.lua 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/compat53/module.lua 2019-02-13 11:53:29.078405237 +0100 +@@ -0,0 +1,827 @@ ++local _G, _VERSION = _G, _VERSION ++local lua_version = _VERSION:sub(-3) ++ ++ ++local M = _G ++ ++if lua_version < "5.3" then ++ ++ -- cache globals in upvalues ++ local error, ipairs, pairs, pcall, require, select, setmetatable, type = ++ error, ipairs, pairs, pcall, require, select, setmetatable, type ++ local debug, io, math, package, string, table = ++ debug, io, math, package, string, table ++ local io_lines = io.lines ++ local io_read = io.read ++ local unpack = lua_version == "5.1" and unpack or table.unpack ++ ++ -- create module table ++ M = {} ++ local M_meta = { ++ __index = _G, ++ -- __newindex is set@the end ++ } ++ setmetatable(M, M_meta) ++ ++ -- create subtables ++ M.io = setmetatable({}, { __index = io }) ++ M.math = setmetatable({}, { __index = math }) ++ M.string = setmetatable({}, { __index = string }) ++ M.table = setmetatable({}, { __index = table }) ++ M.utf8 = {} ++ ++ ++ -- select the most powerful getmetatable function available ++ local gmt = type(debug) == "table" and debug.getmetatable or ++ getmetatable or function() return false end ++ ++ -- type checking functions ++ local checkinteger -- forward declararation ++ ++ local function argcheck(cond, i, f, extra) ++ if not cond then ++ error("bad argument #"..i.." to '"..f.."' ("..extra..")", 0) ++ end ++ end ++ ++ ++ -- load utf8 library ++ local utf8_ok, utf8lib = pcall(require, "compat53.utf8") ++ if utf8_ok then ++ if lua_version == "5.1" then ++ utf8lib.charpattern = "[%z\1-\127\194-\244][\128-\191]*" ++ end ++ for k,v in pairs(utf8lib) do ++ M.utf8[k] = v ++ end ++ package.loaded["utf8"] = M.utf8 ++ end ++ ++ ++ -- load table library ++ local table_ok, tablib = pcall(require, "compat53.table") ++ if table_ok then ++ for k,v in pairs(tablib) do ++ M.table[k] = v ++ end ++ end ++ ++ ++ -- load string packing functions ++ local str_ok, strlib = pcall(require, "compat53.string") ++ if str_ok then ++ for k,v in pairs(strlib) do ++ M.string[k] = v ++ end ++ end ++ ++ ++ -- try Roberto's struct module for string packing/unpacking if ++ -- compat53.string is unavailable ++ if not str_ok then ++ local struct_ok, struct = pcall(require, "struct") ++ if struct_ok then ++ M.string.pack = struct.pack ++ M.string.packsize = struct.size ++ M.string.unpack = struct.unpack ++ end ++ end ++ ++ ++ -- update math library ++ do ++ local maxint, minint = 1 ++ ++ while maxint+1 > maxint and 2*maxint > maxint do ++ maxint = maxint * 2 ++ end ++ if 2*maxint <= maxint then ++ maxint = 2*maxint-1 ++ minint = -maxint-1 ++ else ++ maxint = maxint ++ minint = -maxint ++ end ++ M.math.maxinteger = maxint ++ M.math.mininteger = minint ++ ++ function M.math.tointeger(n) ++ if type(n) == "number" and n <= maxint and n >= minint and n % 1 == 0 then ++ return n ++ end ++ return nil ++ end ++ ++ function M.math.type(n) ++ if type(n) == "number" then ++ if n <= maxint and n >= minint and n % 1 == 0 then ++ return "integer" ++ else ++ return "float" ++ end ++ else ++ return nil ++ end ++ end ++ ++ function checkinteger(x, i, f) ++ local t = type(x) ++ if t ~= "number" then ++ error("bad argument #"..i.." to '"..f.. ++ "' (number expected, got "..t..")", 0) ++ elseif x > maxint or x < minint or x % 1 ~= 0 then ++ error("bad argument #"..i.." to '"..f.. ++ "' (number has no integer representation)", 0) ++ else ++ return x ++ end ++ end ++ ++ function M.math.ult(m, n) ++ m = checkinteger(m, "1", "math.ult") ++ n = checkinteger(n, "2", "math.ult") ++ if m >= 0 and n < 0 then ++ return true ++ elseif m < 0 and n >= 0 then ++ return false ++ else ++ return m < n ++ end ++ end ++ end ++ ++ ++ -- assert should allow non-string error objects ++ function M.assert(cond, ...) ++ if cond then ++ return cond, ... ++ elseif select('#', ...) > 0 then ++ error((...), 0) ++ else ++ error("assertion failed!", 0) ++ end ++ end ++ ++ ++ -- ipairs should respect __index metamethod ++ do ++ local function ipairs_iterator(st, var) ++ var = var + 1 ++ local val = st[var] ++ if val ~= nil then ++ return var, st[var] ++ end ++ end ++ function M.ipairs(t) ++ if gmt(t) ~= nil then -- t has metatable ++ return ipairs_iterator, t, 0 ++ else ++ return ipairs(t) ++ end ++ end ++ end ++ ++ ++ -- make '*' optional for io.read and io.lines ++ do ++ local function addasterisk(fmt) ++ if type(fmt) == "string" and fmt:sub(1, 1) ~= "*" then ++ return "*"..fmt ++ else ++ return fmt ++ end ++ end ++ ++ function M.io.read(...) ++ local n = select('#', ...) ++ for i = 1, n do ++ local a = select(i, ...) ++ local b = addasterisk(a) ++ -- as an optimization we only allocate a table for the ++ -- modified format arguments when we have a '*' somewhere. ++ if a ~= b then ++ local args = { ... } ++ args[i] = b ++ for j = i+1, n do ++ args[j] = addasterisk(args[j]) ++ end ++ return io_read(unpack(args, 1, n)) ++ end ++ end ++ return io_read(...) ++ end ++ ++ -- PUC-Rio Lua 5.1 uses a different implementation for io.lines! ++ function M.io.lines(...) ++ local n = select('#', ...) ++ for i = 2, n do ++ local a = select(i, ...) ++ local b = addasterisk(a) ++ -- as an optimization we only allocate a table for the ++ -- modified format arguments when we have a '*' somewhere. ++ if a ~= b then ++ local args = { ... } ++ args[i] = b ++ for j = i+1, n do ++ args[j] = addasterisk(args[j]) ++ end ++ return io_lines(unpack(args, 1, n)) ++ end ++ end ++ return io_lines(...) ++ end ++ end ++ ++ ++ -- update table library (if C module not available) ++ if not table_ok then ++ local table_concat = table.concat ++ local table_insert = table.insert ++ local table_remove = table.remove ++ local table_sort = table.sort ++ ++ function M.table.concat(list, sep, i, j) ++ local mt = gmt(list) ++ if type(mt) == "table" and type(mt.__len) == "function" then ++ local src = list ++ list, i, j = {}, i or 1, j or mt.__len(src) ++ for k = i, j do ++ list[k] = src[k] ++ end ++ end ++ return table_concat(list, sep, i, j) ++ end ++ ++ function M.table.insert(list, ...) ++ local mt = gmt(list) ++ local has_mt = type(mt) == "table" ++ local has_len = has_mt and type(mt.__len) == "function" ++ if has_mt and (has_len or mt.__index or mt.__newindex) then ++ local e = (has_len and mt.__len(list) or #list)+1 ++ local nargs, pos, value = select('#', ...), ... ++ if nargs == 1 then ++ pos, value = e, pos ++ elseif nargs == 2 then ++ pos = checkinteger(pos, "2", "table.insert") ++ argcheck(1 <= pos and pos <= e, "2", "table.insert", ++ "position out of bounds" ) ++ else ++ error("wrong number of arguments to 'insert'", 0) ++ end ++ for i = e-1, pos, -1 do ++ list[i+1] = list[i] ++ end ++ list[pos] = value ++ else ++ return table_insert(list, ...) ++ end ++ end ++ ++ function M.table.move(a1, f, e, t, a2) ++ a2 = a2 or a1 ++ f = checkinteger(f, "2", "table.move") ++ argcheck(f > 0, "2", "table.move", ++ "initial position must be positive") ++ e = checkinteger(e, "3", "table.move") ++ t = checkinteger(t, "4", "table.move") ++ if e >= f then ++ local m, n, d = 0, e-f, 1 ++ if t > f then m, n, d = n, m, -1 end ++ for i = m, n, d do ++ a2[t+i] = a1[f+i] ++ end ++ end ++ return a2 ++ end ++ ++ function M.table.remove(list, pos) ++ local mt = gmt(list) ++ local has_mt = type(mt) == "table" ++ local has_len = has_mt and type(mt.__len) == "function" ++ if has_mt and (has_len or mt.__index or mt.__newindex) then ++ local e = (has_len and mt.__len(list) or #list) ++ pos = pos ~= nil and checkinteger(pos, "2", "table.remove") or e ++ if pos ~= e then ++ argcheck(1 <= pos and pos <= e+1, "2", "table.remove", ++ "position out of bounds" ) ++ end ++ local result = list[pos] ++ while pos < e do ++ list[pos] = list[pos+1] ++ pos = pos + 1 ++ end ++ list[pos] = nil ++ return result ++ else ++ return table_remove(list, pos) ++ end ++ end ++ ++ do ++ local function pivot(list, cmp, a, b) ++ local m = b - a ++ if m > 2 then ++ local c = a + (m-m%2)/2 ++ local x, y, z = list[a], list[b], list[c] ++ if not cmp(x, y) then ++ x, y, a, b = y, x, b, a ++ end ++ if not cmp(y, z) then ++ y, b = z, c ++ end ++ if not cmp(x, y) then ++ y, b = x, a ++ end ++ return b, y ++ else ++ return b, list[b] ++ end ++ end ++ ++ local function lt_cmp(a, b) ++ return a < b ++ end ++ ++ local function qsort(list, cmp, b, e) ++ if b < e then ++ local i, j, k, val = b, e, pivot(list, cmp, b, e) ++ while i < j do ++ while i < j and cmp(list[i], val) do ++ i = i + 1 ++ end ++ while i < j and not cmp(list[j], val) do ++ j = j - 1 ++ end ++ if i < j then ++ list[i], list[j] = list[j], list[i] ++ if i == k then k = j end -- update pivot position ++ i, j = i+1, j-1 ++ end ++ end ++ if i ~= k and not cmp(list[i], val) then ++ list[i], list[k] = val, list[i] ++ k = i -- update pivot position ++ end ++ qsort(list, cmp, b, i == k and i-1 or i) ++ return qsort(list, cmp, i+1, e) ++ end ++ end ++ ++ function M.table.sort(list, cmp) ++ local mt = gmt(list) ++ local has_mt = type(mt) == "table" ++ local has_len = has_mt and type(mt.__len) == "function" ++ if has_len then ++ cmp = cmp or lt_cmp ++ local len = mt.__len(list) ++ return qsort(list, cmp, 1, len) ++ else ++ return table_sort(list, cmp) ++ end ++ end ++ end ++ ++ local function unpack_helper(list, i, j, ...) ++ if j < i then ++ return ... ++ else ++ return unpack_helper(list, i, j-1, list[j], ...) ++ end ++ end ++ function M.table.unpack(list, i, j) ++ local mt = gmt(list) ++ local has_mt = type(mt) == "table" ++ local has_len = has_mt and type(mt.__len) == "function" ++ if has_mt and (has_len or mt.__index) then ++ i, j = i or 1, j or (has_len and mt.__len(list)) or #list ++ return unpack_helper(list, i, j) ++ else ++ return unpack(list, i, j) ++ end ++ end ++ end -- update table library ++ ++ ++ -- bring Lua 5.1 (and LuaJIT) up to speed with Lua 5.2 ++ if lua_version == "5.1" then ++ -- detect LuaJIT (including LUAJIT_ENABLE_LUA52COMPAT compilation flag) ++ local is_luajit = (string.dump(function() end) or ""):sub(1, 3) == "\027LJ" ++ local is_luajit52 = is_luajit and ++ #setmetatable({}, { __len = function() return 1 end }) == 1 ++ ++ -- cache globals in upvalues ++ local load, loadfile, loadstring, setfenv, xpcall = ++ load, loadfile, loadstring, setfenv, xpcall ++ local coroutine, os = coroutine, os ++ local coroutine_create = coroutine.create ++ local coroutine_resume = coroutine.resume ++ local coroutine_running = coroutine.running ++ local coroutine_status = coroutine.status ++ local coroutine_yield = coroutine.yield ++ local io_input = io.input ++ local io_open = io.open ++ local io_output = io.output ++ local io_write = io.write ++ local math_log = math.log ++ local os_execute = os.execute ++ local string_find = string.find ++ local string_format = string.format ++ local string_gmatch = string.gmatch ++ local string_gsub = string.gsub ++ local string_match = string.match ++ local string_rep = string.rep ++ local table_concat = table.concat ++ ++ -- create subtables ++ M.coroutine = setmetatable({}, { __index = coroutine }) ++ M.os = setmetatable({}, { __index = os }) ++ M.package = setmetatable({}, { __index = package }) ++ ++ -- handle debug functions ++ if type(debug) == "table" then ++ local debug_setfenv = debug.setfenv ++ local debug_getfenv = debug.getfenv ++ local debug_setmetatable = debug.setmetatable ++ ++ M.debug = setmetatable({}, { __index = debug }) ++ ++ if not is_luajit52 then ++ function M.debug.setuservalue(obj, value) ++ if type(obj) ~= "userdata" then ++ error("bad argument #1 to 'setuservalue' (userdata expected, got ".. ++ type(obj)..")", 2) ++ end ++ if value == nil then value = _G end ++ if type(value) ~= "table" then ++ error("bad argument #2 to 'setuservalue' (table expected, got ".. ++ type(value)..")", 2) ++ end ++ return debug_setfenv(obj, value) ++ end ++ ++ function M.debug.getuservalue(obj) ++ if type(obj) ~= "userdata" then ++ return nil ++ else ++ local v = debug_getfenv(obj) ++ if v == _G or v == package then ++ return nil ++ end ++ return v ++ end ++ end ++ ++ function M.debug.setmetatable(value, tab) ++ debug_setmetatable(value, tab) ++ return value ++ end ++ end -- not luajit with compat52 enabled ++ end -- debug table available ++ ++ ++ if not is_luajit52 then ++ function M.pairs(t) ++ local mt = gmt(t) ++ if type(mt) == "table" and type(mt.__pairs) == "function" then ++ return mt.__pairs(t) ++ else ++ return pairs(t) ++ end ++ end ++ end ++ ++ ++ if not is_luajit then ++ local function check_mode(mode, prefix) ++ local has = { text = false, binary = false } ++ for i = 1,#mode do ++ local c = mode:sub(i, i) ++ if c == "t" then has.text = true end ++ if c == "b" then has.binary = true end ++ end ++ local t = prefix:sub(1, 1) == "\27" and "binary" or "text" ++ if not has[t] then ++ return "attempt to load a "..t.." chunk (mode is '"..mode.."')" ++ end ++ end ++ ++ function M.load(ld, source, mode, env) ++ mode = mode or "bt" ++ local chunk, msg ++ if type( ld ) == "string" then ++ if mode ~= "bt" then ++ local merr = check_mode(mode, ld) ++ if merr then return nil, merr end ++ end ++ chunk, msg = loadstring(ld, source) ++ else ++ local ld_type = type(ld) ++ if ld_type ~= "function" then ++ error("bad argument #1 to 'load' (function expected, got ".. ++ ld_type..")", 2) ++ end ++ if mode ~= "bt" then ++ local checked, merr = false, nil ++ local function checked_ld() ++ if checked then ++ return ld() ++ else ++ checked = true ++ local v = ld() ++ merr = check_mode(mode, v or "") ++ if merr then return nil end ++ return v ++ end ++ end ++ chunk, msg = load(checked_ld, source) ++ if merr then return nil, merr end ++ else ++ chunk, msg = load(ld, source) ++ end ++ end ++ if not chunk then ++ return chunk, msg ++ end ++ if env ~= nil then ++ setfenv(chunk, env) ++ end ++ return chunk ++ end ++ ++ M.loadstring = M.load ++ ++ function M.loadfile(file, mode, env) ++ mode = mode or "bt" ++ if mode ~= "bt" then ++ local f = io_open(file, "rb") ++ if f then ++ local prefix = f:read(1) ++ f:close() ++ if prefix then ++ local merr = check_mode(mode, prefix) ++ if merr then return nil, merr end ++ end ++ end ++ end ++ local chunk, msg = loadfile(file) ++ if not chunk then ++ return chunk, msg ++ end ++ if env ~= nil then ++ setfenv(chunk, env) ++ end ++ return chunk ++ end ++ end -- not luajit ++ ++ ++ if not is_luajit52 then ++ function M.rawlen(v) ++ local t = type(v) ++ if t ~= "string" and t ~= "table" then ++ error("bad argument #1 to 'rawlen' (table or string expected)", 2) ++ end ++ return #v ++ end ++ end ++ ++ ++ if not is_luajit then ++ function M.xpcall(f, msgh, ...) ++ local args, n = { ... }, select('#', ...) ++ return xpcall(function() return f(unpack(args, 1, n)) end, msgh) ++ end ++ end ++ ++ ++ if not is_luajit52 then ++ function M.os.execute(cmd) ++ local code = os_execute(cmd) ++ -- Lua 5.1 does not report exit by signal. ++ if code == 0 then ++ return true, "exit", code ++ else ++ if package.config:sub(1, 1) == '/' then ++ code = code/256 -- only correct on Linux! ++ end ++ return nil, "exit", code ++ end ++ end ++ end ++ ++ ++ if not table_ok and not is_luajit52 then ++ M.table.pack = function(...) ++ return { n = select('#', ...), ... } ++ end ++ end ++ ++ ++ local main_coroutine = coroutine_create(function() end) ++ ++ function M.coroutine.create(func) ++ local success, result = pcall(coroutine_create, func) ++ if not success then ++ if type(func) ~= "function" then ++ error("bad argument #1 (function expected)", 0) ++ end ++ result = coroutine_create(function(...) return func(...) end) ++ end ++ return result ++ end ++ ++ if not is_luajit52 then ++ function M.coroutine.running() ++ local co = coroutine_running() ++ if co then ++ return co, false ++ else ++ return main_coroutine, true ++ end ++ end ++ end ++ ++ function M.coroutine.yield(...) ++ local co, flag = coroutine_running() ++ if co and not flag then ++ return coroutine_yield(...) ++ else ++ error("attempt to yield from outside a coroutine", 0) ++ end ++ end ++ ++ if not is_luajit then ++ function M.coroutine.resume(co, ...) ++ if co == main_coroutine then ++ return false, "cannot resume non-suspended coroutine" ++ else ++ return coroutine_resume(co, ...) ++ end ++ end ++ ++ function M.coroutine.status(co) ++ local notmain = coroutine_running() ++ if co == main_coroutine then ++ return notmain and "normal" or "running" ++ else ++ return coroutine_status(co) ++ end ++ end ++ end -- not luajit ++ ++ ++ if not is_luajit then ++ M.math.log = function(x, base) ++ if base ~= nil then ++ return math_log(x)/math_log(base) ++ else ++ return math_log(x) ++ end ++ end ++ end ++ ++ ++ if not is_luajit then ++ function M.package.searchpath(name, path, sep, rep) ++ sep = (sep or "."):gsub("(%p)", "%%%1") ++ rep = (rep or package.config:sub(1, 1)):gsub("(%%)", "%%%1") ++ local pname = name:gsub(sep, rep):gsub("(%%)", "%%%1") ++ local msg = {} ++ for subpath in path:gmatch("[^;]+") do ++ local fpath = subpath:gsub("%?", pname) ++ local f = io_open(fpath, "r") ++ if f then ++ f:close() ++ return fpath ++ end ++ msg[#msg+1] = "\n\tno file '" .. fpath .. "'" ++ end ++ return nil, table_concat(msg) ++ end ++ end ++ ++ ++ local function fix_pattern(pattern) ++ return (string_gsub(pattern, "%z", "%%z")) ++ end ++ ++ function M.string.find(s, pattern, ...) ++ return string_find(s, fix_pattern(pattern), ...) ++ end ++ ++ function M.string.gmatch(s, pattern) ++ return string_gmatch(s, fix_pattern(pattern)) ++ end ++ ++ function M.string.gsub(s, pattern, ...) ++ return string_gsub(s, fix_pattern(pattern), ...) ++ end ++ ++ function M.string.match(s, pattern, ...) ++ return string_match(s, fix_pattern(pattern), ...) ++ end ++ ++ if not is_luajit then ++ function M.string.rep(s, n, sep) ++ if sep ~= nil and sep ~= "" and n >= 2 then ++ return s .. string_rep(sep..s, n-1) ++ else ++ return string_rep(s, n) ++ end ++ end ++ end ++ ++ if not is_luajit then ++ do ++ local addqt = { ++ ["\n"] = "\\\n", ++ ["\\"] = "\\\\", ++ ["\""] = "\\\"" ++ } ++ ++ local function addquoted(c, d) ++ return (addqt[c] or string_format(d~="" and "\\%03d" or "\\%d", c:byte()))..d ++ end ++ ++ function M.string.format(fmt, ...) ++ local args, n = { ... }, select('#', ...) ++ local i = 0 ++ local function adjust_fmt(lead, mods, kind) ++ if #lead % 2 == 0 then ++ i = i + 1 ++ if kind == "s" then ++ args[i] = _G.tostring(args[i]) ++ elseif kind == "q" then ++ args[i] = '"'..string_gsub(args[i], "([%z%c\\\"\n])(%d?)", addquoted)..'"' ++ return lead.."%"..mods.."s" ++ end ++ end ++ end ++ fmt = string_gsub(fmt, "(%%*)%%([%d%.%-%+%# ]*)(%a)", adjust_fmt) ++ return string_format(fmt, unpack(args, 1, n)) ++ end ++ end ++ end ++ ++ ++ function M.io.write(...) ++ local res, msg, errno = io_write(...) ++ if res then ++ return io_output() ++ else ++ return nil, msg, errno ++ end ++ end ++ ++ if not is_luajit then ++ local function helper(st, var_1, ...) ++ if var_1 == nil then ++ if st.doclose then st.f:close() end ++ if (...) ~= nil then ++ error((...), 2) ++ end ++ end ++ return var_1, ... ++ end ++ ++ local function lines_iterator(st) ++ return helper(st, st.f:read(unpack(st, 1, st.n))) ++ end ++ ++ function M.io.lines(fname, ...) ++ local doclose, file, msg ++ if fname ~= nil then ++ doclose, file, msg = true, io_open(fname, "r") ++ if not file then error(msg, 2) end ++ else ++ doclose, file = false, io_input() ++ end ++ local st = { f=file, doclose=doclose, n=select('#', ...), ... } ++ for i = 1, st.n do ++ local t = type(st[i]) ++ if t == "string" then ++ local fmt = st[i]:match("^%*?([aln])") ++ if not fmt then ++ error("bad argument #"..(i+1).." to 'for iterator' (invalid format)", 2) ++ end ++ st[i] = "*"..fmt ++ elseif t ~= "number" then ++ error("bad argument #"..(i+1).." to 'for iterator' (invalid format)", 2) ++ end ++ end ++ return lines_iterator, st ++ end ++ end -- not luajit ++ ++ end -- lua 5.1 ++ ++ -- further write should be forwarded to _G ++ M_meta.__newindex = _G ++ ++end -- lua < 5.3 ++ ++ ++-- return module table ++return M ++ ++-- vi: set expandtab softtabstop=3 shiftwidth=3 : +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/LICENSE luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/LICENSE +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/LICENSE 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/LICENSE 2019-02-13 11:53:29.078405237 +0100 +@@ -0,0 +1,20 @@ ++The MIT License (MIT) ++ ++Copyright (c) 2015 Kepler Project. ++ ++Permission is hereby granted, free of charge, to any person obtaining a copy of ++this software and associated documentation files (the "Software"), to deal in ++the Software without restriction, including without limitation the rights to ++use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ++the Software, and to permit persons to whom the Software is furnished to do so, ++subject to the following conditions: ++ ++The above copyright notice and this permission notice shall be included in all ++copies or substantial portions of the Software. ++ ++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ++FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ++COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ++IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/lprefix.h luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/lprefix.h +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/lprefix.h 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/lprefix.h 2019-02-13 11:53:29.078405237 +0100 +@@ -0,0 +1,175 @@ ++/* ++** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ ++** Definitions for Lua code that must come before any other header file ++** See Copyright Notice in lua.h ++*/ ++ ++#ifndef lprefix_h ++#define lprefix_h ++ ++ ++/* ++** Allows POSIX/XSI stuff ++*/ ++#if !defined(LUA_USE_C89) /* { */ ++ ++#if !defined(_XOPEN_SOURCE) ++#define _XOPEN_SOURCE 600 ++#elif _XOPEN_SOURCE == 0 ++#undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ ++#endif ++ ++/* ++** Allows manipulation of large files in gcc and some other compilers ++*/ ++#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) ++#define _LARGEFILE_SOURCE 1 ++#define _FILE_OFFSET_BITS 64 ++#endif ++ ++#endif /* } */ ++ ++ ++/* ++** Windows stuff ++*/ ++#if defined(_WIN32) /* { */ ++ ++#if !defined(_CRT_SECURE_NO_WARNINGS) ++#define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ ++#endif ++ ++#endif /* } */ ++ ++ ++/* COMPAT53 adaptation */ ++#include "c-api/compat-5.3.h" ++ ++#undef LUAMOD_API ++#define LUAMOD_API extern ++ ++ ++#ifdef lutf8lib_c ++# define luaopen_utf8 luaopen_compat53_utf8 ++/* we don't support the %U format string of lua_pushfstring! ++ * code below adapted from the Lua 5.3 sources: ++ */ ++static const char *compat53_utf8_escape (lua_State* L, long x) { ++ if (x < 0x80) { /* ASCII */ ++ char c = (char)x; ++ lua_pushlstring(L, &c, 1); ++ } else { ++ char buff[8] = { 0 }; ++ unsigned int mfb = 0x3f; ++ int n = 1; ++ do { ++ buff[8 - (n++)] = (char)(0x80|(x & 0x3f)); ++ x >>= 6; ++ mfb >>= 1; ++ } while (x > mfb); ++ buff[8-n] = (char)((~mfb << 1) | x); ++ lua_pushlstring(L, buff+8-n, n); ++ } ++ return lua_tostring(L, -1); ++} ++# define lua_pushfstring(L, fmt, l) \ ++ compat53_utf8_escape(L, l) ++#endif ++ ++ ++#ifdef ltablib_c ++# define luaopen_table luaopen_compat53_table ++# ifndef LUA_MAXINTEGER ++/* conservative estimate: */ ++# define LUA_MAXINTEGER INT_MAX ++# endif ++#endif /* ltablib_c */ ++ ++ ++#ifdef lstrlib_c ++#include <locale.h> ++#include <lualib.h> ++/* move the string library open function out of the way (we only take ++ * the string packing functions)! ++ */ ++# define luaopen_string luaopen_string_XXX ++/* used in string.format implementation, which we don't use: */ ++# ifndef LUA_INTEGER_FRMLEN ++# define LUA_INTEGER_FRMLEN "" ++# define LUA_NUMBER_FRMLEN "" ++# endif ++# ifndef LUA_MININTEGER ++# define LUA_MININTEGER 0 ++# endif ++# ifndef LUA_INTEGER_FMT ++# define LUA_INTEGER_FMT "%d" ++# endif ++# ifndef LUAI_UACINT ++# define LUAI_UACINT lua_Integer ++# endif ++/* different Lua 5.3 versions have conflicting variants of this macro ++ * in luaconf.h, there's a fallback implementation in lstrlib.c, and ++ * the macro isn't used for string (un)packing anyway! ++ * */ ++# undef lua_number2strx ++# if LUA_VERSION_NUM < 503 ++/* lstrlib assumes that lua_Integer and lua_Unsigned have the same ++ * size, so we use the unsigned equivalent of ptrdiff_t! */ ++# define lua_Unsigned size_t ++# endif ++# ifndef l_mathlim ++# ifdef LUA_NUMBER_DOUBLE ++# define l_mathlim(n) (DBL_##n) ++# else ++# define l_mathlim(n) (FLT_##n) ++# endif ++# endif ++# ifndef l_mathop ++# ifdef LUA_NUMBER_DOUBLE ++# define l_mathop(op) op ++# else ++# define l_mathop(op) op##f ++# endif ++# endif ++# ifndef lua_getlocaledecpoint ++# define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) ++# endif ++# ifndef l_sprintf ++# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ++# define l_sprintf(s,sz,f,i) (snprintf(s, sz, f, i)) ++# else ++# define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s, f, i)) ++# endif ++# endif ++ ++static int str_pack (lua_State *L); ++static int str_packsize (lua_State *L); ++static int str_unpack (lua_State *L); ++LUAMOD_API int luaopen_compat53_string (lua_State *L) { ++ luaL_Reg const funcs[] = { ++ { "pack", str_pack }, ++ { "packsize", str_packsize }, ++ { "unpack", str_unpack }, ++ { NULL, NULL } ++ }; ++ luaL_newlib(L, funcs); ++ return 1; ++} ++/* fake CLANG feature detection on other compilers */ ++# ifndef __has_attribute ++# define __has_attribute(x) 0 ++# endif ++/* make luaopen_string(_XXX) static, so it (and all other referenced ++ * string functions) won't be included in the resulting dll ++ * (hopefully). ++ */ ++# undef LUAMOD_API ++# if defined(__GNUC__) || __has_attribute(__unused__) ++# define LUAMOD_API __attribute__((__unused__)) static ++# else ++# define LUAMOD_API static ++# endif ++#endif /* lstrlib.c */ ++ ++#endif ++ +diff -purN luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/lstrlib.c luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/lstrlib.c +--- luvi-src-v2.7.6.orig/deps/lua-openssl/deps/lua-compat/lstrlib.c 1970-01-01 01:00:00.000000000 +0100 ++++ luvi-src-v2.7.6/deps/lua-openssl/deps/lua-compat/lstrlib.c 2019-02-13 11:53:29.078405237 +0100 +@@ -0,0 +1,1584 @@ ++/* ++** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $ ++** Standard library for string operations and pattern-matching ++** See Copyright Notice in lua.h ++*/ ++ ++#define lstrlib_c ++#define LUA_LIB ++ ++#include "lprefix.h" ++ ++ ++#include <ctype.h> ++#include <float.h> ++#include <limits.h> ++#include <locale.h> ++#include <stddef.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++ ++#include "lua.h" ++ ++#include "lauxlib.h" ++#include "lualib.h" ++ ++ ++/* ++** maximum number of captures that a pattern can do during ++** pattern-matching. This limit is arbitrary, but must fit in ++** an unsigned char. ++*/ ++#if !defined(LUA_MAXCAPTURES) ++#define LUA_MAXCAPTURES 32 ++#endif ++ ++ ++/* macro to 'unsign' a character */ ++#define uchar(c) ((unsigned char)(c)) ++ ++ ++/* ++** Some sizes are better limited to fit in 'int', but must also fit in ++** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.) ++*/ ++#define MAX_SIZET ((size_t)(~(size_t)0)) ++ ++#define MAXSIZE \ ++ (sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX)) ++ ++ ++ ++ ++static int str_len (lua_State *L) { ++ size_t l; ++ luaL_checklstring(L, 1, &l); ++ lua_pushinteger(L, (lua_Integer)l); ++ return 1; ++} ++ ++ ++/* translate a relative string position: negative means back from end */ ++static lua_Integer posrelat (lua_Integer pos, size_t len) { ++ if (pos >= 0) return pos; ++ else if (0u - (size_t)pos > len) return 0; ++ else return (lua_Integer)len + pos + 1; ++} ++ ++ ++static int str_sub (lua_State *L) { ++ size_t l; ++ const char *s = luaL_checklstring(L, 1, &l); ++ lua_Integer start = posrelat(luaL_checkinteger(L, 2), l); ++ lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l); ++ if (start < 1) start = 1; ++ if (end > (lua_Integer)l) end = l; ++ if (start <= end) ++ lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1); ++ else lua_pushliteral(L, ""); ++ return 1; ++} ++ ++ ++static int str_reverse (lua_State *L) { ++ size_t l, i; ++ luaL_Buffer b; ++ const char *s = luaL_checklstring(L, 1, &l); ++ char *p = luaL_buffinitsize(L, &b, l); ++ for (i = 0; i < l; i++) ++ p[i] = s[l - i - 1]; ++ luaL_pushresultsize(&b, l); ++ return 1; ++} ++ ++ ++static int str_lower (lua_State *L) { ++ size_t l; ++ size_t i; ++ luaL_Buffer b; ++ const char *s = luaL_checklstring(L, 1, &l); ++ char *p = luaL_buffinitsize(L, &b, l); ++ for (i=0; i<l; i++) ++ p[i] = tolower(uchar(s[i])); ++ luaL_pushresultsize(&b, l); ++ return 1; ++} ++ ++ ++static int str_upper (lua_State *L) { ++ size_t l; ++ size_t i; ++ luaL_Buffer b; ++ const char *s = luaL_checklstring(L, 1, &l); ++ char *p = luaL_buffinitsize(L, &b, l); ++ for (i=0; i<l; i++) ++ p[i] = toupper(uchar(s[i])); ++ luaL_pushresultsize(&b, l); ++ return 1; ++} ++ ++ ++static int str_rep (lua_State *L) { ++ size_t l, lsep; ++ const char *s = luaL_checklstring(L, 1, &l); ++ lua_Integer n = luaL_checkinteger(L, 2); ++ const char *sep = luaL_optlstring(L, 3, "", &lsep); ++ if (n <= 0) lua_pushliteral(L, ""); ++ else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */ ++ return luaL_error(L, "resulting string too large"); ++ else { ++ size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep; ++ luaL_Buffer b; ++ char *p = luaL_buffinitsize(L, &b, totallen); ++ while (n-- > 1) { /* first n-1 copies (followed by separator) */ ++ memcpy(p, s, l * sizeof(char)); p += l; ++ if (lsep > 0) { /* empty 'memcpy' is not that cheap */ ++ memcpy(p, sep, lsep * sizeof(char)); ++ p += lsep; ++ } ++ } ++ memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */ ++ luaL_pushresultsize(&b, totallen); ++ } ++ return 1; ++} ++ ++ ++static int str_byte (lua_State *L) { ++ size_t l; ++ const char *s = luaL_checklstring(L, 1, &l); ++ lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l); ++ lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l); ++ int n, i; ++ if (posi < 1) posi = 1; ++ if (pose > (lua_Integer)l) pose = l; ++ if (posi > pose) return 0; /* empty interval; return no values */ ++ if (pose - posi >= INT_MAX) /* arithmetic overflow? */ ++ return luaL_error(L, "string slice too long"); ++ n = (int)(pose - posi) + 1; ++ luaL_checkstack(L, n, "string slice too long"); ++ for (i=0; i<n; i++) ++ lua_pushinteger(L, uchar(s[posi+i-1])); ++ return n; ++} ++ ++ ++static int str_char (lua_State *L) { ++ int n = lua_gettop(L); /* number of arguments */ ++ int i; ++ luaL_Buffer b; ++ char *p = luaL_buffinitsize(L, &b, n); ++ for (i=1; i<=n; i++) { ++ lua_Integer c = luaL_checkinteger(L, i); ++ luaL_argcheck(L, uchar(c) == c, i, "value out of range"); ++ p[i - 1] = uchar(c); ++ } ++ luaL_pushresultsize(&b, n); ++ return 1; ++} ++ ++ ++static int writer (lua_State *L, const void *b, size_t size, void *B) { ++ (void)L; ++ luaL_addlstring((luaL_Buffer *) B, (const char *)b, size); ++ return 0; ++} ++ ++ ++static int str_dump (lua_State *L) { ++ luaL_Buffer b; ++ int strip = lua_toboolean(L, 2); ++ luaL_checktype(L, 1, LUA_TFUNCTION); ++ lua_settop(L, 1); ++ luaL_buffinit(L,&b); ++ if (lua_dump(L, writer, &b, strip) != 0) ++ return luaL_error(L, "unable to dump given function"); ++ luaL_pushresult(&b); ++ return 1; ++} ++ ++ ++ ++/* ++** {====================================================== ++** PATTERN MATCHING ++** ======================================================= ++*/ ++ ++ ++#define CAP_UNFINISHED (-1) ++#define CAP_POSITION (-2) ++ ++ ++typedef struct MatchState { ++ const char *src_init; /* init of source string */ ++ const char *src_end; /* end ('\0') of source string */ ++ const char *p_end; /* end ('\0') of pattern */ ++ lua_State *L; ++ int matchdepth; /* control for recursive depth (to avoid C stack overflow) */ ++ unsigned char level; /* total number of captures (finished or unfinished) */ ++ struct { ++ const char *init; ++ ptrdiff_t len; ++ } capture[LUA_MAXCAPTURES]; ++} MatchState; ++ ++ ++/* recursive function */ ++static const char *match (MatchState *ms, const char *s, const char *p); ++ ++ ++/* maximum recursion depth for 'match' */ ++#if !defined(MAXCCALLS) ++#define MAXCCALLS 200 ++#endif ++ ++ ++#define L_ESC '%' ++#define SPECIALS "^$*+?.([%-" ++ ++ ++static int check_capture (MatchState *ms, int l) { ++ l -= '1'; ++ if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) ++ return luaL_error(ms->L, "invalid capture index %%%d", l + 1); ++ return l; ++} ++ ++ ++static int capture_to_close (MatchState *ms) { ++ int level = ms->level; ++ for (level--; level>=0; level--) ++ if (ms->capture[level].len == CAP_UNFINISHED) return level; ++ return luaL_error(ms->L, "invalid pattern capture"); ++} ++ ++ ++static const char *classend (MatchState *ms, const char *p) { ++ switch (*p++) { ++ case L_ESC: { ++ if (p == ms->p_end) ++ luaL_error(ms->L, "malformed pattern (ends with '%%')"); ++ return p+1; ++ } ++ case '[': { ++ if (*p == '^') p++; ++ do { /* look for a ']' */ ++ if (p == ms->p_end) ++ luaL_error(ms->L, "malformed pattern (missing ']')"); ++ if (*(p++) == L_ESC && p < ms->p_end) ++ p++; /* skip escapes (e.g. '%]') */ ++ } while (*p != ']'); ++ return p+1; ++ } ++ default: { ++ return p; ++ } ++ } ++} ++ ++ ++static int match_class (int c, int cl) { ++ int res; ++ switch (tolower(cl)) { ++ case 'a' : res = isalpha(c); break; ++ case 'c' : res = iscntrl(c); break; ++ case 'd' : res = isdigit(c); break; ++ case 'g' : res = isgraph(c); break; ++ case 'l' : res = islower(c); break; ++ case 'p' : res = ispunct(c); break; ++ case 's' : res = isspace(c); break; ++ case 'u' : res = isupper(c); break; ++ case 'w' : res = isalnum(c); break; ++ case 'x' : res = isxdigit(c); break; ++ case 'z' : res = (c == 0); break; /* deprecated option */ ++ default: return (cl == c); ++ } ++ return (islower(cl) ? res : !res); ++} ++ ++ ++static int matchbracketclass (int c, const char *p, const char *ec) { ++ int sig = 1; ++ if (*(p+1) == '^') { ++ sig = 0; ++ p++; /* skip the '^' */ ++ } ++ while (++p < ec) { ++ if (*p == L_ESC) { ++ p++; ++ if (match_class(c, uchar(*p))) ++ return sig; ++ } ++ else if ((*(p+1) == '-') && (p+2 < ec)) { ++ p+=2; ++ if (uchar(*(p-2)) <= c && c <= uchar(*p)) ++ return sig; ++ } ++ else if (uchar(*p) == c) return sig; ++ } ++ return !sig; ++} ++ ++ ++static int singlematch (MatchState *ms, const char *s, const char *p, ++ const char *ep) { ++ if (s >= ms->src_end) ++ return 0; ++ else { ++ int c = uchar(*s); ++ switch (*p) { ++ case '.': return 1; /* matches any char */ ++ case L_ESC: return match_class(c, uchar(*(p+1))); ++ case '[': return matchbracketclass(c, p, ep-1); ++ default: return (uchar(*p) == c); ++ } ++ } ++} ++ ++ ++static const char *matchbalance (MatchState *ms, const char *s, ++ const char *p) { ++ if (p >= ms->p_end - 1) ++ luaL_error(ms->L, "malformed pattern (missing arguments to '%%b')"); ++ if (*s != *p) return NULL; ++ else { ++ int b = *p; ++ int e = *(p+1); ++ int cont = 1; ++ while (++s < ms->src_end) { ++ if (*s == e) { ++ if (--cont == 0) return s+1; ++ } ++ else if (*s == b) cont++; ++ } ++ } ++ return NULL; /* string ends out of balance */ ++} ++ ++ ++static const char *max_expand (MatchState *ms, const char *s, ++ const char *p, const char *ep) { ++ ptrdiff_t i = 0; /* counts maximum expand for item */ ++ while (singlematch(ms, s + i, p, ep)) ++ i++; ++ /* keeps trying to match with the maximum repetitions */ ++ while (i>=0) { ++ const char *res = match(ms, (s+i), ep+1); ++ if (res) return res; ++ i--; /* else didn't match; reduce 1 repetition to try again */ ++ } ++ return NULL; ++} ++ ++ ++static const char *min_expand (MatchState *ms, const char *s, ++ const char *p, const char *ep) { ++ for (;;) { ++ const char *res = match(ms, s, ep+1); ++ if (res != NULL) ++ return res; ++ else if (singlematch(ms, s, p, ep)) ++ s++; /* try with one more repetition */ ++ else return NULL; ++ } ++} ++ ++ ++static const char *start_capture (MatchState *ms, const char *s, ++ const char *p, int what) { ++ const char *res; ++ int level = ms->level; ++ if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); ++ ms->capture[level].init = s; ++ ms->capture[level].len = what; ++ ms->level = level+1; ++ if ((res=match(ms, s, p)) == NULL) /* match failed? */ ++ ms->level--; /* undo capture */ ++ return res; ++} ++ ++ ++static const char *end_capture (MatchState *ms, const char *s, ++ const char *p) { ++ int l = capture_to_close(ms); ++ const char *res; ++ ms->capture[l].len = s - ms->capture[l].init; /* close capture */ ++ if ((res = match(ms, s, p)) == NULL) /* match failed? */ ++ ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ ++ return res; ++} ++ ++ ++static const char *match_capture (MatchState *ms, const char *s, int l) { ++ size_t len; ++ l = check_capture(ms, l); ++ len = ms->capture[l].len; ++ if ((size_t)(ms->src_end-s) >= len && ++ memcmp(ms->capture[l].init, s, len) == 0) ++ return s+len; ++ else return NULL; ++} ++ ++ ++static const char *match (MatchState *ms, const char *s, const char *p) { ++ if (ms->matchdepth-- == 0) ++ luaL_error(ms->L, "pattern too complex"); ++ init: /* using goto's to optimize tail recursion */ ++ if (p != ms->p_end) { /* end of pattern? */ ++ switch (*p) { ++ case '(': { /* start capture */ ++ if (*(p + 1) == ')') /* position capture? */ ++ s = start_capture(ms, s, p + 2, CAP_POSITION); ++ else ++ s = start_capture(ms, s, p + 1, CAP_UNFINISHED); ++ break; ++ } ++ case ')': { /* end capture */ ++ s = end_capture(ms, s, p + 1); ++ break; ++ } ++ case '$': { ++ if ((p + 1) != ms->p_end) /* is the '$' the last char in pattern? */ ++ goto dflt; /* no; go to default */ ++ s = (s == ms->src_end) ? s : NULL; /* check end of string */ ++ break; ++ } ++ case L_ESC: { /* escaped sequences not in the format class[*+?-]? */ ++ switch (*(p + 1)) { ++ case 'b': { /* balanced string? */ ++ s = matchbalance(ms, s, p + 2); ++ if (s != NULL) { ++ p += 4; goto init; /* return match(ms, s, p + 4); */ ++ } /* else fail (s == NULL) */ ++ break; ++ } ++ case 'f': { /* frontier? */ ++ const char *ep; char previous; ++ p += 2; ++ if (*p != '[') ++ luaL_error(ms->L, "missing '[' after '%%f' in pattern"); ++ ep = classend(ms, p); /* points to what is next */ ++ previous = (s == ms->src_init) ? '\0' : *(s - 1); ++ if (!matchbracketclass(uchar(previous), p, ep - 1) && ++ matchbracketclass(uchar(*s), p, ep - 1)) { ++ p = ep; goto init; /* return match(ms, s, ep); */ ++ } ++ s = NULL; /* match failed */ ++ break; ++ } ++ case '0': case '1': case '2': case '3': ++ case '4': case '5': case '6': case '7': ++ case '8': case '9': { /* capture results (%0-%9)? */ ++ s = match_capture(ms, s, uchar(*(p + 1))); ++ if (s != NULL) { ++ p += 2; goto init; /* return match(ms, s, p + 2) */ ++ } ++ break; ++ } ++ default: goto dflt; ++ } ++ break; ++ } ++ default: dflt: { /* pattern class plus optional suffix */ ++ const char *ep = classend(ms, p); /* points to optional suffix */ ++ /* does not match at least once? */ ++ if (!singlematch(ms, s, p, ep)) { ++ if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */ ++ p = ep + 1; goto init; /* return match(ms, s, ep + 1); */ ++ } ++ else /* '+' or no suffix */ ++ s = NULL; /* fail */ ++ } ++ else { /* matched once */ ++ switch (*ep) { /* handle optional suffix */ ++ case '?': { /* optional */ ++ const char *res; ++ if ((res = match(ms, s + 1, ep + 1)) != NULL) ++ s = res; ++ else { ++ p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */ ++ } ++ break; ++ } ++ case '+': /* 1 or more repetitions */ ++ s++; /* 1 match already done */ ++ /* FALLTHROUGH */ ++ case '*': /* 0 or more repetitions */ ++ s = max_expand(ms, s, p, ep); ++ break; ++ case '-': /* 0 or more repetitions (minimum) */ ++ s = min_expand(ms, s, p, ep); ++ break; ++ default: /* no suffix */ ++ s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.20.1
Part of the diff is not shown here. View the raw message.
PATCH 1/1 package/luvi: add patch to fix build issue with OpenSSL 1.1.1a
Hello,
Quoted 15 lines · On Wed, 13 Feb 2019 23:08:11 +0100 J?rg Krause <[email protected]>…
Bump the bundled lua-openssl version to 0.7.4 for compatibility with OpenSSL 1.1.1a.
Note, that luvi 2.7.6 is the latest version providing a release tarball.
Runtime tested on Banana Pro, note that version string for lua-openssl does not match the tag name (0.7.4):
``` luvi v2.7.6 zlib: 1.2.11 libuv: 1.25.0 ssl: OpenSSL 1.1.1a 20 Nov 2018, lua-openssl 0.7.3 ```
Quoted 8 lines
Fixes:
http://autobuild.buildroot.net/results/e87994a3dc987f5aa101a5e721ac927e21453373
http://autobuild.buildroot.net/results/ea725ad90cfcd3c5e242268a593dcabd7297fe70
http://autobuild.buildroot.net/results/f2fb9eea0044e4a5f674742d29ea95af49cf5a45
http://autobuild.buildroot.net/results/de4daa1b930f907f06640dc98a708016217ddea5
.. and many more.Signed-off-by J?rg Krause <[email protected]>
This is really a huge patch.
Why is luvi using a bundled lua-openssl version instead of some external lua-openssl package ?
I see that the change has been applied upstream
(https://github.com/luvit/luvi/commit/0d5959a33cde81ed49314bd6c56f6906a83d2fa1),
which is good.
Thanks,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 package/luvi: add patch to fix build issue with OpenSSL 1.1.1a
Hi Thomas,
Quoted 27 lines · Thomas Petazzoni
Hello,
Quoted 22 lines · On Wed, 13 Feb 2019 23:08:11 +0100 J?rg Krause <[email protected]>…
Bump the bundled lua-openssl version to 0.7.4 for compatibility with OpenSSL 1.1.1a.
Note, that luvi 2.7.6 is the latest version providing a release tarball.
Runtime tested on Banana Pro, note that version string for lua-openssl does not match the tag name (0.7.4):
``` luvi v2.7.6 zlib: 1.2.11 libuv: 1.25.0 ssl: OpenSSL 1.1.1a 20 Nov 2018, lua-openssl 0.7.3 ```Fixes:
http://autobuild.buildroot.net/results/e87994a3dc987f5aa101a5e721ac927e21453373
http://autobuild.buildroot.net/results/ea725ad90cfcd3c5e242268a593dcabd7297fe70
http://autobuild.buildroot.net/results/f2fb9eea0044e4a5f674742d29ea95af49cf5a45
http://autobuild.buildroot.net/results/de4daa1b930f907f06640dc98a708016217ddea5
.. and many more.
Quoted 3 lines
Quoted 1 line
Signed-off-by J?rg Krause <[email protected]>This is really a huge patch.
Yes, unfortunately!
Quoted 2 lines
Why is luvi using a bundled lua-openssl version instead of some external lua-openssl package ?
I spent some time trying to make lua-openssl an external package. It is certainly feasible to get luvi to work to use an external lua-openssl package, but it requires some changes in lua-openssl first, as installing header files in staging, naming convention for the shared library, etc.
Right now, it was easier for me, to just bump the bundled lua-openssl version.
Quoted 3 lines
I see that the change has been applied upstream
(https://github.com/luvit/luvi/commit/0d5959a33cde81ed49314bd6c56f6906a83d2fa1),
which is good.
Yes, there was a commit [1] on the master branch before, which bumped lua-openssl to version 0.7.3. However, this version does not build with OpenSSL 1.1.1.
Unfortunately, the luvi maintainers are not able to create new releases right now. Hopefully, someone of the maintainers with push rights will have the time soon to do so.
[1] https://github.com/luvit/luvi/commit/a981c704b960e52974ec5746a25b86de40b2cb67
Best regards
J?rg
PATCH 1/1 package/luvi: add patch to fix build issue with OpenSSL 1.1.1a
In reply to Thomas PetazzoniQuoted 29 lines · Thomas Petazzoni
Hello,
Quoted 15 lines · On Wed, 13 Feb 2019 23:08:11 +0100 J?rg Krause <[email protected]>…
Bump the bundled lua-openssl version to 0.7.4 for compatibility with OpenSSL 1.1.1a.
Note, that luvi 2.7.6 is the latest version providing a release tarball.
Runtime tested on Banana Pro, note that version string for lua-openssl does not match the tag name (0.7.4):
``` luvi v2.7.6 zlib: 1.2.11 libuv: 1.25.0 ssl: OpenSSL 1.1.1a 20 Nov 2018, lua-openssl 0.7.3 ```Quoted 8 lines
Fixes:
http://autobuild.buildroot.net/results/e87994a3dc987f5aa101a5e721ac927e21453373
http://autobuild.buildroot.net/results/ea725ad90cfcd3c5e242268a593dcabd7297fe70
http://autobuild.buildroot.net/results/f2fb9eea0044e4a5f674742d29ea95af49cf5a45
http://autobuild.buildroot.net/results/de4daa1b930f907f06640dc98a708016217ddea5
.. and many more.Signed-off-by J?rg Krause <[email protected]>
Quoted 8 lines
This is really a huge patch.
Why is luvi using a bundled lua-openssl version instead of some external lua-openssl package ?
I see that the change has been applied upstream
(https://github.com/luvit/luvi/commit/0d5959a33cde81ed49314bd6c56f6906a83d2fa1),
which is good.
Fortunately, the maintainers of luvi released version 2.9.0 which includes the updated lua-openssl to fix the build issues with OpenSSL 1.1.1a.
Therefore, this patch is superseded.
J?rg