From d9bae1d1f56ca64734182683077b938cb80280f9 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Wed, 29 Oct 2025 14:35:08 -0300 Subject: [PATCH] Move iconv const check into autoconf (8.3) (#20247) See GH-16847 --- ext/iconv/config.m4 | 16 +++++++++++++++- ext/iconv/iconv.c | 10 +++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 3cf400fe962..23dae235d80 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -113,6 +113,20 @@ 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=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([[ #include @@ -147,7 +161,7 @@ int main(void) { LDFLAGS="$save_LDFLAGS" CFLAGS="$save_CFLAGS" - 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 diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 8ac3bc9b3c4..ae93e0573e2 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