New macro 'pushvfstring'

Helps to ensure that 'luaO_pushvfstring' is being called correctly,
with an error check after closing the vararg list with 'va_end'.
This commit is contained in:
Roberto Ierusalimschy
2025-04-23 11:55:04 -03:00
parent 9b014d4bcd
commit e055905914
4 changed files with 13 additions and 16 deletions

View File

@@ -822,6 +822,15 @@ typedef struct Table {
/* size of buffer for 'luaO_utf8esc' function */
#define UTF8BUFFSZ 8
/* macro to call 'luaO_pushvfstring' correctly */
#define pushvfstring(L, argp, fmt, msg) \
{ va_start(argp, fmt); \
msg = luaO_pushvfstring(L, fmt, argp); \
va_end(argp); \
if (msg == NULL) luaD_throw(L, LUA_ERRMEM); /* only after 'va_end' */ }
LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);
LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x);
LUAI_FUNC lu_byte luaO_codeparam (unsigned int p);