package/php-lua: fix build with lua < 5.2

php-lua fails to build in buildroot 2025.08-rc3 on the following error:

in file included from [...]/usr/include/php/Zend/zend.h:32,
                 from [...]/usr/include/php/main/php.h:31,
                 from [...]/build/php-lua-2.0.7/lua.c:24:
[...]/build/php-lua-2.0.7/lua.c: In function ‘php_lua_write_property’:
[...]/build/php-lua-2.0.7/lua.c:247:37:
error: ‘val’ undeclared (first use in this function); did you mean
‘zval’?
  247 |         lua_pushlstring(L, ZSTR_VAL(val), ZSTR_LEN(val));
      |                                     ^~~
[...]/usr/include/php/Zend/zend_string.h:66:26:
note: in definition of macro ‘ZSTR_VAL’
   66 | #define ZSTR_VAL(zstr)  (zstr)->val
      |                          ^~~~
[...]/build/php-lua-2.0.7/lua.c:247:37:
note: each undeclared identifier is reported only once for each function
it appears in
  247 |         lua_pushlstring(L, ZSTR_VAL(val), ZSTR_LEN(val));
      |                                     ^~~
[...]/usr/include/php/Zend/zend_string.h:66:26:
note: in definition of macro ‘ZSTR_VAL’
   66 | #define ZSTR_VAL(zstr)  (zstr)->val
      |                          ^~~~
make[2]: *** [Makefile:214: lua.lo] Error 1

The issue triggers only if lua interpreter version is lower than 5.2. In
this case,  php_lua_write_property calls ZSTR_VAL on the wrong variable.

Fix php-lua build by calling ZSTR_VAL on the correct variable.

Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/11271124501 (TestPhpLuaLuajit)

Suggested-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
[Romain: add link to failing TestPhpLuaLuajit]
Signed-off-by: Romain Naour <romain.naour@smile.fr>
(cherry picked from commit a1daf153bf)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
Alexis Lothoré
2025-09-09 09:24:19 +02:00
committed by Thomas Perale
parent 1428a6387d
commit d4e1e1055b

View File

@@ -0,0 +1,38 @@
From 7bf334832ad36d1f2976406d680b35a168ffaa91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexis=20Lothor=C3=A9?= <alexis.lothore@bootlin.com>
Date: Mon, 8 Sep 2025 17:20:12 +0200
Subject: [PATCH] lua.c: fix ZSTR_VAL usage when using lua < 5.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When using a lua interpreter with a version lower than 5.1, the
php_lua_write_property ends up calling the ZSTR_VAL with the wrong
variable (it is expected to receive "member", a zend_string variable,
but it is "value" that is passed, which is a zval).
Fix php-lua compatibility with interpreters < 5.2 by passing the correct
variable
Upstream: upstream dead, custom patch
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
lua.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lua.c b/lua.c
index a40e5da442a4..5889bc7f83ea 100755
--- a/lua.c
+++ b/lua.c
@@ -244,7 +244,7 @@ static zval* php_lua_write_property(zend_object *object, zend_string *member, zv
lua_State *L = php_lua_obj_from_obj(object)->L;
#if (LUA_VERSION_NUM < 502)
- lua_pushlstring(L, ZSTR_VAL(val), ZSTR_LEN(val));
+ lua_pushlstring(L, ZSTR_VAL(member), ZSTR_LEN(member));
php_lua_send_zval_to_lua(L, value);
lua_settable(L, LUA_GLOBALSINDEX);
--
2.51.0