diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2021-11-21 14:43:00 +0100 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2021-11-21 14:43:00 +0100 |
| commit | 1844472502fa8e56d90e861d45f85d8fd8957b48 (patch) | |
| tree | 37b98462ec1e55a65363f7de267fcf2005eba22b | |
| parent | e00fd0a415694dc15687593e355441af6dfa30bd (diff) | |
| download | lua-compat-5.3-fix-pushlstring.tar.gz lua-compat-5.3-fix-pushlstring.tar.bz2 lua-compat-5.3-fix-pushlstring.zip | |
Convert lua_pushlstring from a macro to a functionfix-pushlstring
This should avoid issues with multiple evaluations of the arguments,
which should be very rare, but could in principle happen.
Diffstat (limited to '')
| -rw-r--r-- | c-api/compat-5.3.c | 8 | ||||
| -rw-r--r-- | c-api/compat-5.3.h | 9 |
2 files changed, 11 insertions, 6 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index 42b0a4b..64592d6 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
| @@ -715,6 +715,14 @@ void luaL_pushresult (luaL_Buffer_53 *B) { | |||
| 715 | #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 | 715 | #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 |
| 716 | 716 | ||
| 717 | 717 | ||
| 718 | COMPAT53_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | ||
| 719 | #undef lua_pushlstring | ||
| 720 | lua_pushlstring(L, len > 0 ? s : "", len); | ||
| 721 | #define lua_pushlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _pushlstring_53) | ||
| 722 | return lua_tostring(L, -1); | ||
| 723 | } | ||
| 724 | |||
| 725 | |||
| 718 | COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) { | 726 | COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) { |
| 719 | index = lua_absindex(L, index); | 727 | index = lua_absindex(L, index); |
| 720 | lua_pushinteger(L, i); | 728 | lua_pushinteger(L, i); |
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index b730a4b..6f66dad 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
| @@ -142,9 +142,6 @@ COMPAT53_API void lua_len (lua_State *L, int i); | |||
| 142 | #define lua_pushstring(L, s) \ | 142 | #define lua_pushstring(L, s) \ |
| 143 | (lua_pushstring((L), (s)), lua_tostring((L), -1)) | 143 | (lua_pushstring((L), (s)), lua_tostring((L), -1)) |
| 144 | 144 | ||
| 145 | #define lua_pushlstring(L, s, len) \ | ||
| 146 | ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) | ||
| 147 | |||
| 148 | #ifndef luaL_newlibtable | 145 | #ifndef luaL_newlibtable |
| 149 | # define luaL_newlibtable(L, l) \ | 146 | # define luaL_newlibtable(L, l) \ |
| 150 | (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) | 147 | (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) |
| @@ -290,6 +287,9 @@ typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); | |||
| 290 | #define lua_gettable(L, i) \ | 287 | #define lua_gettable(L, i) \ |
| 291 | (lua_gettable((L), (i)), lua_type((L), -1)) | 288 | (lua_gettable((L), (i)), lua_type((L), -1)) |
| 292 | 289 | ||
| 290 | #define lua_pushlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _pushlstring_53) | ||
| 291 | COMPAT53_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len); | ||
| 292 | |||
| 293 | #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) | 293 | #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) |
| 294 | COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); | 294 | COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); |
| 295 | 295 | ||
| @@ -352,9 +352,6 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, | |||
| 352 | #define lua_getuservalue(L, i) \ | 352 | #define lua_getuservalue(L, i) \ |
| 353 | (lua_getuservalue((L), (i)), lua_type((L), -1)) | 353 | (lua_getuservalue((L), (i)), lua_type((L), -1)) |
| 354 | 354 | ||
| 355 | #define lua_pushlstring(L, s, len) \ | ||
| 356 | (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) | ||
| 357 | |||
| 358 | #define lua_rawgetp(L, i, p) \ | 355 | #define lua_rawgetp(L, i, p) \ |
| 359 | (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) | 356 | (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) |
| 360 | 357 | ||
