Not sure I want these compat changes but hopefully I'll get all the tests to pass one day.

This commit is contained in:
ThePhD 2017-09-10 04:02:50 -04:00
parent 232abab96a
commit a6d209fbec
3 changed files with 33 additions and 13 deletions

View File

@ -15,6 +15,25 @@
/* definitions for Lua 5.1 only */
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
#if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6))
#ifndef COMPAT53_HAVE_STRERROR_R
#define COMPAT53_HAVE_STRERROR_R
#endif // have strerror_r
#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || (defined(_XOPEN_SOURCE) || _XOPEN_SOURCE >= 600)) && (!defined(_GNU_SOURCE) || !_GNU_SOURCE)
#ifndef COMPAT53_HAVE_STRERROR_R_XSI
#define COMPAT53_HAVE_STRERROR_R_XSI
#endif // XSI-Compliant strerror_r
#else
#ifndef COMPAT53_HAVE_STRERROR_R_GNU
#define COMPAT53_HAVE_STRERROR_R_GNU
#endif // GNU variant strerror_r
#endif // XSI/Posix vs. GNU strerror_r
#elif defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || defined(__STDC_LIB_EXT1__)
#ifndef COMPAT53_HAVE_STRERROR_S
#define COMPAT53_HAVE_STRERROR_S
#endif // GNU variant strerror_r
#endif // strerror_r vs. strerror_s vs. strerror usage
#ifndef COMPAT53_LUA_FILE_BUFFER_SIZE
#define COMPAT53_LUA_FILE_BUFFER_SIZE 4096
#endif // Lua File Buffer Size
@ -350,36 +369,37 @@ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1,
COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
const char* s = NULL;
int en = errno; /* calls to Lua API may change this value */
#if defined(COMPAT53_HAVE_STRERROR_R) || defined(COMPAT53_HAVE_STRERROR_S)
char buf[512] = { 0 };
#endif // buffer for threadsafe variants of strerror if possible
if (stat) {
lua_pushboolean(L, 1);
return 1;
}
else {
lua_pushnil(L);
#if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6))
#if defined(COMPAT53_HAVE_STRERROR_R)
/* use strerror_r here, because it's available on these specific platforms */
char buf[512] = {0};
#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || (defined(_XOPEN_SOURCE) || _XOPEN_SOURCE >= 600)) && (!defined(_GNU_SOURCE) || !_GNU_SOURCE)
#if defined(COMPAT53_HAVE_STRERROR_R_XSI)
/* XSI Compliant */
strerror_r(en, buf, 512);
s = buf;
#else
/* GNU-specific which returns const char* */
/* GNU-specific which returns const char* */
s = strerror_r(en, buf, 512);
#endif
#elif defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
#elif defined(COMPAT53_HAVE_STRERROR_S)
/* for MSVC and other C11 implementations, use strerror_s
* since it's provided by default by the libraries
*/
char buf[512] = {0};
*/
strerror_s(buf, 512, en);
s = buf;
#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 it works in 99% of cases, so I don't need the reason to stop
* the train now
* ... 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
*/
s = strerror(en);
#endif
@ -393,7 +413,7 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
}
static const char* compat53_f_parser_handler (lua_State *L, void *data, size_t *size) {
static const char* compat53_f_parser_handler (lua_State *, void *data, size_t *size) {
struct compat53_f_parser_buffer *p = (struct compat53_f_parser_buffer*)data;
size_t readcount = fread(p->buffer + p->start, sizeof(*p->buffer), sizeof(p->buffer), p->file);
if (ferror(p->file) != 0 || feof(p->file) != 0) {
@ -417,10 +437,10 @@ static int checkmode (lua_State *L, const char *mode, const char *modename, int
COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) {
FILE* fp;
int err;
int c;
int status = LUA_OK;
#if defined(_MSC_VER)
int err = 0;
err = fopen_s(&fp, filename, "rb");
if (err != 0) {
fclose(fp);

View File

@ -103,7 +103,7 @@ namespace sol {
private:
template <bool b>
call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, detail::protected_handler<b, handler_t>& h) const {
return static_cast<call_status>(lua_pcallk(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stackindex, 0, nullptr));
return static_cast<call_status>(lua_pcall(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stackindex));
}
template<std::size_t... I, bool b, typename... Ret>

View File

@ -33,7 +33,7 @@ namespace sol {
class basic_function : public base_t {
private:
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount) const {
lua_callk(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), 0, nullptr);
lua_call(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount));
}
template<std::size_t... I, typename... Ret>