aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-09 12:50:59 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-09 12:50:59 -0300
commita7b8b27dd39f45b9464ffc4226b0616c3ffe5ad7 (patch)
tree46c3a143f3b703023d884e769485080862a3c27d
parent511d53a826760dd11cd82947184583e2d094e2d2 (diff)
downloadlua-a7b8b27dd39f45b9464ffc4226b0616c3ffe5ad7.tar.gz
lua-a7b8b27dd39f45b9464ffc4226b0616c3ffe5ad7.tar.bz2
lua-a7b8b27dd39f45b9464ffc4226b0616c3ffe5ad7.zip
Uses of "likely" in macros active to all users
The use of 'l_likely' in auxlib macros 'luaL_argcheck' and 'luaL_argexpected' should not be restricted to Lua's own code. For that, 'l_likely' was renamed to 'luai_likely' to be exported to external code.
-rw-r--r--lauxlib.h9
-rw-r--r--luaconf.h18
2 files changed, 15 insertions, 12 deletions
diff --git a/lauxlib.h b/lauxlib.h
index 9058e262..72f70e7d 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -12,6 +12,7 @@
12#include <stddef.h> 12#include <stddef.h>
13#include <stdio.h> 13#include <stdio.h>
14 14
15#include "luaconf.h"
15#include "lua.h" 16#include "lua.h"
16 17
17 18
@@ -122,10 +123,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
122** =============================================================== 123** ===============================================================
123*/ 124*/
124 125
125#if !defined(l_likely)
126#define l_likely(x) x
127#endif
128
129 126
130#define luaL_newlibtable(L,l) \ 127#define luaL_newlibtable(L,l) \
131 lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 128 lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
@@ -134,10 +131,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
134 (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) 131 (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
135 132
136#define luaL_argcheck(L, cond,arg,extramsg) \ 133#define luaL_argcheck(L, cond,arg,extramsg) \
137 ((void)(l_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) 134 ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
138 135
139#define luaL_argexpected(L,cond,arg,tname) \ 136#define luaL_argexpected(L,cond,arg,tname) \
140 ((void)(l_likely(cond) || luaL_typeerror(L, (arg), (tname)))) 137 ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
141 138
142#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 139#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
143#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 140#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
diff --git a/luaconf.h b/luaconf.h
index ae73e2fd..38e14eda 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -665,20 +665,26 @@
665** macros to improve jump prediction, used mostly for error handling 665** macros to improve jump prediction, used mostly for error handling
666** and debug facilities. 666** and debug facilities.
667*/ 667*/
668#if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely) 668#if !defined(luai_likely)
669 669
670#include <stdio.h>
671#if defined(__GNUC__) 670#if defined(__GNUC__)
672#define l_likely(x) (__builtin_expect(((x) != 0), 1)) 671#define luai_likely(x) (__builtin_expect(((x) != 0), 1))
673#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) 672#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0))
674#else 673#else
675#define l_likely(x) (x) 674#define luai_likely(x) (x)
676#define l_unlikely(x) (x) 675#define luai_unlikely(x) (x)
677#endif 676#endif
678 677
679#endif 678#endif
680 679
681 680
681#if defined(LUA_CORE) || defined(LUA_LIB)
682/* shorter names for Lua's own use */
683#define l_likely(x) luai_likely(x)
684#define l_unlikely(x) luai_unlikely(x)
685#endif
686
687
682 688
683/* }================================================================== */ 689/* }================================================================== */
684 690