Skip to content

Commit d9bae1d

Browse files
authored
Move iconv const check into autoconf (8.3) (php#20247)
See phpGH-16847
1 parent 76e26c6 commit d9bae1d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

ext/iconv/config.m4

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ int main(void) {
113113
AC_MSG_RESULT(yes, cross-compiling)
114114
])
115115

116+
dnl iconv on some platforms (NetBSD pre-10, Solaris) may have a non-standard
117+
dnl const input parameter; libiconv may imitate this on those platforms.
118+
AC_CACHE_CHECK([if iconv input parameter is const (non-standard)], [php_cv_iconv_const],
119+
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
120+
#include <iconv.h>
121+
122+
size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, size_t *dstleft);
123+
])],
124+
[php_cv_iconv_const=const],
125+
[php_cv_iconv_const=non-const])])
126+
dnl non-const is just used for display, set it back
127+
AS_VAR_IF([php_cv_iconv_const], [non-const],
128+
[php_cv_iconv_const=])
129+
116130
AC_MSG_CHECKING([if iconv supports //IGNORE])
117131
AC_RUN_IFELSE([AC_LANG_SOURCE([[
118132
#include <iconv.h>
@@ -147,7 +161,7 @@ int main(void) {
147161
LDFLAGS="$save_LDFLAGS"
148162
CFLAGS="$save_CFLAGS"
149163

150-
PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
164+
PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DICONV_CONST=$php_cv_iconv_const])
151165
PHP_SUBST(ICONV_SHARED_LIBADD)
152166
PHP_INSTALL_HEADERS([ext/iconv/])
153167
else

ext/iconv/iconv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
#undef iconv
4545
#endif
4646

47-
#if defined(__NetBSD__)
48-
// unfortunately, netbsd has still the old non posix conformant signature
49-
// libiconv tends to match the eventual system's iconv too.
50-
#define ICONV_CONST const
51-
#else
47+
/* iconv can have different constiness for src on some platforms;
48+
* this is explained in config.m4. On Windows, it's always non-const,
49+
* but it can be awkward to set that on the command line. Do it here.
50+
*/
51+
#ifndef ICONV_CONST
5252
#define ICONV_CONST
5353
#endif
5454

0 commit comments

Comments
 (0)