From 87f9377cc84e32e178b037885484446948e66335 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 18 Nov 2024 12:19:50 -0400 Subject: [PATCH 1/4] Fix quoted const on Windows --- ext/iconv/config.w32 | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index 31423dd121e33..967ecaaea1da9 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 if iconv extension is enabled"); AC_DEFINE("HAVE_LIBICONV", 1, "Define if libiconv is available"); + AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const.", false); AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "The iconv function is called iconv() in libiconv"); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "Which iconv implementation to use"); ADD_FLAG("CFLAGS_ICONV", "/D PHP_ICONV_EXPORTS "); From 6510199b095d15dcf52a5ca889315d54e031cd0c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Fri, 22 Nov 2024 11:27:03 -0400 Subject: [PATCH 2/4] Put iconv constiness into CFLAGS Avoids AC_DEFINE weirdness on Windows. --- ext/iconv/config.m4 | 23 +++++++++++++++++++++++ ext/iconv/config.w32 | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 3cf400fe96231..912173835cde7 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -113,6 +113,17 @@ int main(void) { AC_MSG_RESULT(yes, cross-compiling) ]) + 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 + +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_MSG_CHECKING([if iconv supports //IGNORE]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include @@ -147,10 +158,22 @@ int main(void) { LDFLAGS="$save_LDFLAGS" CFLAGS="$save_CFLAGS" +<<<<<<< HEAD PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) PHP_SUBST(ICONV_SHARED_LIBADD) PHP_INSTALL_HEADERS([ext/iconv/]) else AC_MSG_ERROR(Please reinstall the iconv library.) fi +======= + AC_DEFINE([HAVE_ICONV], [1], + [Define to 1 if the PHP extension 'iconv' is available.]) + + PHP_NEW_EXTENSION([iconv], + [iconv.c], + [$ext_shared],, + [-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]) +>>>>>>> db8c5c88d1e (Put iconv constiness into CFLAGS) fi diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index 967ecaaea1da9..0a36ccd19bf25 100644 --- a/ext/iconv/config.w32 +++ b/ext/iconv/config.w32 @@ -11,10 +11,10 @@ if (PHP_ICONV != "no") { AC_DEFINE("HAVE_ICONV", 1, "Define if iconv extension is enabled"); AC_DEFINE("HAVE_LIBICONV", 1, "Define if libiconv is available"); - AC_DEFINE("ICONV_CONST", "", "Define to const if iconv's input is const.", false); AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "The iconv function is called iconv() in libiconv"); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "Which iconv implementation to use"); 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"); } From e584d5f808324e4c2b7c2d686d0de012ce6c64e8 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 16 Oct 2025 14:44:38 -0300 Subject: [PATCH 3/4] Move Windows non-constiness define to iconv.c Suggestion from @petk --- ext/iconv/config.m4 | 14 +------------- ext/iconv/config.w32 | 1 - ext/iconv/iconv.c | 10 +++++----- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 912173835cde7..ace7cc0be20ee 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -158,22 +158,10 @@ int main(void) { LDFLAGS="$save_LDFLAGS" CFLAGS="$save_CFLAGS" -<<<<<<< HEAD - PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DICONV_CONST=$php_cv_iconv_const]) PHP_SUBST(ICONV_SHARED_LIBADD) PHP_INSTALL_HEADERS([ext/iconv/]) else AC_MSG_ERROR(Please reinstall the iconv library.) fi -======= - AC_DEFINE([HAVE_ICONV], [1], - [Define to 1 if the PHP extension 'iconv' is available.]) - - PHP_NEW_EXTENSION([iconv], - [iconv.c], - [$ext_shared],, - [-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]) ->>>>>>> db8c5c88d1e (Put iconv constiness into CFLAGS) fi diff --git a/ext/iconv/config.w32 b/ext/iconv/config.w32 index 0a36ccd19bf25..31423dd121e33 100644 --- a/ext/iconv/config.w32 +++ b/ext/iconv/config.w32 @@ -14,7 +14,6 @@ if (PHP_ICONV != "no") { AC_DEFINE("ICONV_ALIASED_LIBICONV", 1, "The iconv function is called iconv() in libiconv"); AC_DEFINE("PHP_ICONV_IMPL", "\"libiconv\"", "Which iconv implementation to use"); 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"); } diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 8ac3bc9b3c480..ae93e0573e20f 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -44,11 +44,11 @@ #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 +/* iconv can have different constiness for src on some platforms; + * this is explained in config.m4. On Windows, it's always non-const, + * but it can be awkward to set that on the command line. Do it here. + */ +#ifndef ICONV_CONST #define ICONV_CONST #endif From 8462a6836cb77bcd18332665b69a5dfe2c3887b5 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 20 Oct 2025 13:22:20 -0300 Subject: [PATCH 4/4] Improve output of iconv const check Prints non-const (through a small hack, since AC_MSG_RESULT implies things about its output) --- ext/iconv/config.m4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index ace7cc0be20ee..23dae235d801a 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -122,7 +122,10 @@ int main(void) { 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=])]) + [php_cv_iconv_const=non-const])]) + dnl non-const is just used for display, set it back + AS_VAR_IF([php_cv_iconv_const], [non-const], + [php_cv_iconv_const=]) AC_MSG_CHECKING([if iconv supports //IGNORE]) AC_RUN_IFELSE([AC_LANG_SOURCE([[