mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Not sure I want these compat changes but hopefully I'll get all the tests to pass one day.
This commit is contained in:
parent
232abab96a
commit
a6d209fbec
|
@ -15,6 +15,25 @@
|
||||||
/* definitions for Lua 5.1 only */
|
/* definitions for Lua 5.1 only */
|
||||||
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
|
#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
|
#ifndef COMPAT53_LUA_FILE_BUFFER_SIZE
|
||||||
#define COMPAT53_LUA_FILE_BUFFER_SIZE 4096
|
#define COMPAT53_LUA_FILE_BUFFER_SIZE 4096
|
||||||
#endif // Lua File Buffer Size
|
#endif // Lua File Buffer Size
|
||||||
|
@ -350,16 +369,18 @@ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1,
|
||||||
COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
||||||
const char* s = NULL;
|
const char* s = NULL;
|
||||||
int en = errno; /* calls to Lua API may change this value */
|
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) {
|
if (stat) {
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lua_pushnil(L);
|
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 */
|
/* use strerror_r here, because it's available on these specific platforms */
|
||||||
char buf[512] = {0};
|
#if defined(COMPAT53_HAVE_STRERROR_R_XSI)
|
||||||
#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || (defined(_XOPEN_SOURCE) || _XOPEN_SOURCE >= 600)) && (!defined(_GNU_SOURCE) || !_GNU_SOURCE)
|
|
||||||
/* XSI Compliant */
|
/* XSI Compliant */
|
||||||
strerror_r(en, buf, 512);
|
strerror_r(en, buf, 512);
|
||||||
s = buf;
|
s = buf;
|
||||||
|
@ -367,19 +388,18 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
||||||
/* GNU-specific which returns const char* */
|
/* GNU-specific which returns const char* */
|
||||||
s = strerror_r(en, buf, 512);
|
s = strerror_r(en, buf, 512);
|
||||||
#endif
|
#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
|
/* for MSVC and other C11 implementations, use strerror_s
|
||||||
* since it's provided by default by the libraries
|
* since it's provided by default by the libraries
|
||||||
*/
|
*/
|
||||||
char buf[512] = {0};
|
|
||||||
strerror_s(buf, 512, en);
|
strerror_s(buf, 512, en);
|
||||||
s = buf;
|
s = buf;
|
||||||
#else
|
#else
|
||||||
/* fallback, but
|
/* fallback, but
|
||||||
* strerror is not guaranteed to be threadsafe due to modifying
|
* strerror is not guaranteed to be threadsafe due to modifying
|
||||||
* errno itself and some impls not locking a static buffer for it
|
* 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
|
* ... but most known systems have threadsafe errno: this might only change
|
||||||
* the train now
|
* if the locale is changed out from under someone while this function is being called
|
||||||
*/
|
*/
|
||||||
s = strerror(en);
|
s = strerror(en);
|
||||||
#endif
|
#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;
|
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);
|
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) {
|
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) {
|
COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
int err;
|
|
||||||
int c;
|
int c;
|
||||||
int status = LUA_OK;
|
int status = LUA_OK;
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
int err = 0;
|
||||||
err = fopen_s(&fp, filename, "rb");
|
err = fopen_s(&fp, filename, "rb");
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
|
@ -103,7 +103,7 @@ namespace sol {
|
||||||
private:
|
private:
|
||||||
template <bool b>
|
template <bool b>
|
||||||
call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, detail::protected_handler<b, handler_t>& h) const {
|
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>
|
template<std::size_t... I, bool b, typename... Ret>
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace sol {
|
||||||
class basic_function : public base_t {
|
class basic_function : public base_t {
|
||||||
private:
|
private:
|
||||||
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount) const {
|
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>
|
template<std::size_t... I, typename... Ret>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user