diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-27 15:32:33 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-27 15:32:33 -0300 |
| commit | 66d046833d39b6e33be4d3e10ce5c718d283caef (patch) | |
| tree | 0d7ce2673ed0702eb0a5d32b841a2d6209decf1e | |
| parent | 15fdbd26fe38f05c21fadca783cadafb61fc83b5 (diff) | |
| download | lua-66d046833d39b6e33be4d3e10ce5c718d283caef.tar.gz lua-66d046833d39b6e33be4d3e10ce5c718d283caef.tar.bz2 lua-66d046833d39b6e33be4d3e10ce5c718d283caef.zip | |
no need to check "bad conversion number->int;" in luaL_checkversion,
as now Lua does not use tricks for the conversion, but there is a
need to check the sizes of number types, as they can be different
in two modules
| -rw-r--r-- | lauxlib.c | 18 | ||||
| -rw-r--r-- | lauxlib.h | 12 |
2 files changed, 14 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.253 2013/06/14 20:46:40 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.254 2013/06/25 14:05:26 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -860,7 +860,6 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, | |||
| 860 | ** Returns with only the table at the stack. | 860 | ** Returns with only the table at the stack. |
| 861 | */ | 861 | */ |
| 862 | LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | 862 | LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { |
| 863 | luaL_checkversion(L); | ||
| 864 | luaL_checkstack(L, nup, "too many upvalues"); | 863 | luaL_checkstack(L, nup, "too many upvalues"); |
| 865 | for (; l->name != NULL; l++) { /* fill the table with given functions */ | 864 | for (; l->name != NULL; l++) { /* fill the table with given functions */ |
| 866 | int i; | 865 | int i; |
| @@ -955,20 +954,15 @@ LUALIB_API lua_State *luaL_newstate (void) { | |||
| 955 | } | 954 | } |
| 956 | 955 | ||
| 957 | 956 | ||
| 958 | LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { | 957 | LUALIB_API void luaL_checkversion_ (lua_State *L, int ver, size_t sz) { |
| 959 | const lua_Number *v = lua_version(L); | 958 | const lua_Number *v = lua_version(L); |
| 960 | if (v != lua_version(NULL)) | 959 | if (v != lua_version(NULL)) |
| 961 | luaL_error(L, "multiple Lua VMs detected"); | 960 | luaL_error(L, "multiple Lua VMs detected"); |
| 962 | else if (*v != ver) | 961 | else if (*v != ver) |
| 963 | luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", | 962 | luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f", |
| 964 | ver, *v); | 963 | ver, *v); |
| 965 | /* check conversions number -> integer types */ | 964 | /* check numeric types */ |
| 966 | lua_pushnumber(L, -(lua_Number)0x1234); | 965 | if (sz != LUAL_NUMSIZES) |
| 967 | lua_pushnumber(L, (lua_Number)0x4321); | 966 | luaL_error(L, "core and library have incompatible numeric types"); |
| 968 | if (lua_tointeger(L, -2) != -0x1234 || | ||
| 969 | lua_tounsigned(L, -1) != (lua_Unsigned)0x4321) | ||
| 970 | luaL_error(L, "bad conversion number->int;" | ||
| 971 | " must recompile Lua with proper settings"); | ||
| 972 | lua_pop(L, 2); | ||
| 973 | } | 967 | } |
| 974 | 968 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.120 2011/11/29 15:55:08 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.121 2013/06/25 14:05:26 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -26,8 +26,11 @@ typedef struct luaL_Reg { | |||
| 26 | } luaL_Reg; | 26 | } luaL_Reg; |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); | 29 | #define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number)) |
| 30 | #define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM) | 30 | |
| 31 | LUALIB_API void (luaL_checkversion_) (lua_State *L, int ver, size_t sz); | ||
| 32 | #define luaL_checkversion(L) \ | ||
| 33 | luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES) | ||
| 31 | 34 | ||
| 32 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); | 35 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); |
| 33 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); | 36 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); |
| @@ -108,7 +111,8 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
| 108 | #define luaL_newlibtable(L,l) \ | 111 | #define luaL_newlibtable(L,l) \ |
| 109 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) | 112 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) |
| 110 | 113 | ||
| 111 | #define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) | 114 | #define luaL_newlib(L,l) \ |
| 115 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) | ||
| 112 | 116 | ||
| 113 | #define luaL_argcheck(L, cond,numarg,extramsg) \ | 117 | #define luaL_argcheck(L, cond,numarg,extramsg) \ |
| 114 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) | 118 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) |
