From d69789da1ccfa4db7c241de6b471d6b729f1561e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 24 Jan 2023 15:04:17 -0300 Subject: Fix absence of 'system' in iOS Despite claiming to be ISO, the C library in some Apple platforms does not implement 'system'. --- loslib.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/loslib.c b/loslib.c index 854dcf69..7eb05caf 100644 --- a/loslib.c +++ b/loslib.c @@ -138,12 +138,28 @@ /* }================================================================== */ +/* +** Despite claiming to be ISO, the C library in some Apple platforms +** does not implement 'system'. +*/ +#if !defined(l_system) && defined(__APPLE__) /* { */ +#include "TargetConditionals.h" +#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV +#define l_system(cmd) ((cmd) == NULL ? 0 : -1) +#endif +#endif /* } */ + +#if !defined(l_system) +#define l_system(cmd) system(cmd) /* default definition */ +#endif + + static int os_execute (lua_State *L) { const char *cmd = luaL_optstring(L, 1, NULL); int stat; errno = 0; - stat = system(cmd); + stat = l_system(cmd); if (cmd != NULL) return luaL_execresult(L, stat); else { -- cgit v1.2.3-55-g6feb From c888ae0aea030491f90b749260a156ce15635681 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 2 Feb 2023 13:37:11 -0300 Subject: Small changes in hash of pointers When converting from pointer to integer, use 'uintptr_t' if available; otherwise try 'uintmax_t', and use 'size_t' as last resource. --- llimits.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/llimits.h b/llimits.h index 52a32f92..251a2702 100644 --- a/llimits.h +++ b/llimits.h @@ -71,11 +71,24 @@ typedef signed char ls_byte; /* -** conversion of pointer to unsigned integer: -** this is for hashing only; there is no problem if the integer -** cannot hold the whole pointer value +** conversion of pointer to unsigned integer: this is for hashing only; +** there is no problem if the integer cannot hold the whole pointer +** value. (In strict ISO C this may cause undefined behavior, but no +** actual machine seems to bother.) */ -#define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX)) +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include +#if defined(UINTPTR_MAX) /* even in C99 this type is optional */ +#define L_P2I uintptr_t +#else /* no 'intptr'? */ +#define L_P2I uintmax_t /* use the largerst available integer */ +#endif +#else /* C89 option */ +#define L_P2I size_t +#endif + +#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX)) -- cgit v1.2.3-55-g6feb From cf08915d62e338c987b71c078b148490510e9fe7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 2 Feb 2023 13:43:41 -0300 Subject: New macro LUA_USE_IOS Do not try to detect automatically whether system is iOS; it is simpler and more reliable to let the programmer inform that. --- loslib.c | 17 +++++------------ luaconf.h | 6 ++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/loslib.c b/loslib.c index 7eb05caf..89ac06bc 100644 --- a/loslib.c +++ b/loslib.c @@ -138,21 +138,14 @@ /* }================================================================== */ -/* -** Despite claiming to be ISO, the C library in some Apple platforms -** does not implement 'system'. -*/ -#if !defined(l_system) && defined(__APPLE__) /* { */ -#include "TargetConditionals.h" -#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV -#define l_system(cmd) ((cmd) == NULL ? 0 : -1) -#endif -#endif /* } */ - #if !defined(l_system) +#if defined(LUA_USE_IOS) +/* Despite claiming to be ISO C, iOS does not implement 'system'. */ +#define l_system(cmd) ((cmd) == NULL ? 0 : -1) +#else #define l_system(cmd) system(cmd) /* default definition */ #endif - +#endif static int os_execute (lua_State *L) { diff --git a/luaconf.h b/luaconf.h index e4650fbc..137103ed 100644 --- a/luaconf.h +++ b/luaconf.h @@ -70,6 +70,12 @@ #endif +#if defined(LUA_USE_IOS) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN +#endif + + /* @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. */ -- cgit v1.2.3-55-g6feb