From 92add87977dd0d260a0ddad582c589e78e5e4925 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 18 Nov 2024 10:24:24 -0400 Subject: [PATCH 1/3] Move iconv const check into autoconf Some systems (older NetBSD pre-10, Solaris) may have a non-standard const parameter with iconv. Instead of hardcoding the OS check, move this to a feature check performed by autoconf. autoconf doesn't have a nicer way of checking this (well, except for AM_ICONV, which is part of gettext and we're presumably not using it), so we have to repeat the function signature and check for it with a mismatched signature. --- ext/iconv/config.m4 | 11 +++++++++++ ext/iconv/config.w32 | 1 + ext/iconv/iconv.c | 8 -------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 4d0dc36489833..4d255fd444290 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -83,6 +83,17 @@ int main(void) { AS_VAR_IF([php_cv_iconv_errno], [yes],, [AC_MSG_FAILURE([The iconv check failed, 'errno' is missing.])]) + AC_CACHE_CHECK([if iconv input parameter is const (non-standard)], [php_cv_iconv_const], + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#include + +size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, size_t *dstleft); + ])], + [php_cv_iconv_const=const], + [php_cv_iconv_const=])]) + AC_DEFINE_UNQUOTED([ICONV_CONST], [$php_cv_iconv_const], + [Define to const if iconv's input is const.]) + AC_CACHE_CHECK([if iconv supports //IGNORE], [php_cv_iconv_ignore], [AC_RUN_IFELSE([AC_LANG_SOURCE([ #include diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index d99c53fb93634..6aa2a4e49d262 100644 --- a/ext/iconv/config.w32 +++ b/ext/iconv/config.w32 @@ -11,6 +11,7 @@ if (PHP_ICONV != "no") { AC_DEFINE("HAVE_ICONV", 1, "Define to 1 if the PHP extension 'iconv' is available."); AC_DEFINE("HAVE_LIBICONV", 1, "Define to 1 if you have the 'libiconv' function."); + AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const."); AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "Define to 1 if 'iconv()' is aliased to 'libiconv()'."); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "The iconv implementation."); ADD_FLAG("CFLAGS_ICONV", "/D PHP_ICONV_EXPORTS "); diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 4241b7c2887fb..85eae71d74a69 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -43,14 +43,6 @@ #undef iconv #endif -#if defined(__NetBSD__) -// unfortunately, netbsd has still the old non posix conformant signature -// libiconv tends to match the eventual system's iconv too. -#define ICONV_CONST const -#else -#define ICONV_CONST -#endif - #include "zend_smart_str.h" #include "ext/standard/base64.h" #include "ext/standard/quot_print.h" From 63eb0812fe782f8f0c01717e68f07eeef84ab750 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 18 Nov 2024 12:19:50 -0400 Subject: [PATCH 2/3] Fix quoted const on Windows --- ext/iconv/config.w32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index 6aa2a4e49d262..ae1c10b8f3d7d 100644 --- a/ext/iconv/config.w32 +++ b/ext/iconv/config.w32 @@ -11,7 +11,7 @@ if (PHP_ICONV != "no") { AC_DEFINE("HAVE_ICONV", 1, "Define to 1 if the PHP extension 'iconv' is available."); AC_DEFINE("HAVE_LIBICONV", 1, "Define to 1 if you have the 'libiconv' function."); - AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const."); + AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const.", false); AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "Define to 1 if 'iconv()' is aliased to 'libiconv()'."); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "The iconv implementation."); ADD_FLAG("CFLAGS_ICONV", "/D PHP_ICONV_EXPORTS "); From 6de8fa7391220d91127e2f7dcd476cf5ed8fc9af Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Fri, 22 Nov 2024 11:27:03 -0400 Subject: [PATCH 3/3] Put iconv constiness into CFLAGS Avoids AC_DEFINE weirdness on Windows. --- ext/iconv/config.m4 | 6 +++--- ext/iconv/config.w32 | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 4d255fd444290..efe79be140242 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -83,6 +83,8 @@ int main(void) { AS_VAR_IF([php_cv_iconv_errno], [yes],, [AC_MSG_FAILURE([The iconv check failed, 'errno' is missing.])]) + dnl iconv on some platforms (NetBSD pre-10, Solaris) may have a non-standard + dnl const input parameter; libiconv may imitate this on those platforms. AC_CACHE_CHECK([if iconv input parameter is const (non-standard)], [php_cv_iconv_const], [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ #include @@ -91,8 +93,6 @@ size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, size_t * ])], [php_cv_iconv_const=const], [php_cv_iconv_const=])]) - AC_DEFINE_UNQUOTED([ICONV_CONST], [$php_cv_iconv_const], - [Define to const if iconv's input is const.]) AC_CACHE_CHECK([if iconv supports //IGNORE], [php_cv_iconv_ignore], [AC_RUN_IFELSE([AC_LANG_SOURCE([ @@ -131,7 +131,7 @@ int main(void) { PHP_NEW_EXTENSION([iconv], [iconv.c], [$ext_shared],, - [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DICONV_CONST=$php_cv_iconv_const]) PHP_SUBST([ICONV_SHARED_LIBADD]) PHP_INSTALL_HEADERS([ext/iconv], [php_iconv.h]) fi diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index ae1c10b8f3d7d..523adccb68295 100644 --- a/ext/iconv/config.w32 +++ b/ext/iconv/config.w32 @@ -11,10 +11,9 @@ if (PHP_ICONV != "no") { AC_DEFINE("HAVE_ICONV", 1, "Define to 1 if the PHP extension 'iconv' is available."); AC_DEFINE("HAVE_LIBICONV", 1, "Define to 1 if you have the 'libiconv' function."); - AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const.", false); AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "Define to 1 if 'iconv()' is aliased to 'libiconv()'."); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "The iconv implementation."); - ADD_FLAG("CFLAGS_ICONV", "/D PHP_ICONV_EXPORTS "); + ADD_FLAG("CFLAGS_ICONV", "/D PHP_ICONV_EXPORTS /D ICONV_CONST "); if (!PHP_ICONV_SHARED) { ADD_DEF_FILE("ext\\iconv\\php_iconv.def"); }