Skip to content

Commit 5b5c8bb

Browse files
committed
ext/iconv: Fix iconv warnings on NetBSD and Solaris/illumos
1 parent ab5170c commit 5b5c8bb

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

cmake/ext/iconv/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ project(
2828
LANGUAGES C
2929
)
3030

31+
include(CheckPrototypeDefinition)
3132
include(CheckSourceRuns)
3233
include(CheckSymbolExists)
3334
include(CMakeDependentOption)
@@ -279,6 +280,26 @@ if(TARGET Iconv::Iconv)
279280
else()
280281
message(CHECK_PASS "yes")
281282
endif()
283+
284+
# POSIX once had a bug in its specification and documented that iconv() has a
285+
# const input parameter. Therefore, some platforms, such as NetBSD < 10 and
286+
# Solaris/illumos, may have a non-standard iconv declaration. libiconv may
287+
# imitate this on those platforms.
288+
cmake_push_check_state(RESET)
289+
set(CMAKE_REQUIRED_LIBRARIES Iconv::Iconv)
290+
291+
check_prototype_definition(
292+
iconv
293+
"size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, size_t *dstleft)"
294+
"0"
295+
"iconv.h"
296+
PHP_EXT_ICONV_CONST
297+
)
298+
cmake_pop_check_state()
299+
300+
if(PHP_EXT_ICONV_CONST)
301+
target_compile_definitions(php_ext_iconv PRIVATE ICONV_CONST=const)
302+
endif()
282303
endif()
283304

284305
set(HAVE_ICONV TRUE)

patches/8.3/iconv.patch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From: Peter Kokot <peterkokot@gmail.com>
2+
Subject: ext/iconv: Fix iconv prototype
3+
4+
See:
5+
* https://github.com/php/php-src/issues/20089
6+
* https://github.com/php/php-src/pull/18933
7+
* https://github.com/php/php-src/pull/16847
8+
---
9+
ext/iconv/iconv.c | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
13+
index 8ac3bc9b3c4..f11b8d74c63 100644
14+
--- a/ext/iconv/iconv.c
15+
+++ b/ext/iconv/iconv.c
16+
@@ -44,6 +44,7 @@
17+
#undef iconv
18+
#endif
19+
20+
+#ifndef ICONV_CONST
21+
#if defined(__NetBSD__)
22+
// unfortunately, netbsd has still the old non posix conformant signature
23+
// libiconv tends to match the eventual system's iconv too.
24+
@@ -51,6 +52,7 @@
25+
#else
26+
#define ICONV_CONST
27+
#endif
28+
+#endif
29+
30+
#include "zend_smart_str.h"
31+
#include "ext/standard/base64.h"

patches/8.4/iconv.patch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From: Peter Kokot <peterkokot@gmail.com>
2+
Subject: ext/iconv: Fix iconv prototype
3+
4+
See:
5+
* https://github.com/php/php-src/issues/20089
6+
* https://github.com/php/php-src/pull/18933
7+
* https://github.com/php/php-src/pull/16847
8+
---
9+
ext/iconv/iconv.c | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
13+
index b61d253c5d4..53423e9ce49 100644
14+
--- a/ext/iconv/iconv.c
15+
+++ b/ext/iconv/iconv.c
16+
@@ -43,6 +43,7 @@
17+
#undef iconv
18+
#endif
19+
20+
+#ifndef ICONV_CONST
21+
#if defined(__NetBSD__)
22+
// unfortunately, netbsd has still the old non posix conformant signature
23+
// libiconv tends to match the eventual system's iconv too.
24+
@@ -50,6 +51,7 @@
25+
#else
26+
#define ICONV_CONST
27+
#endif
28+
+#endif
29+
30+
#include "zend_smart_str.h"
31+
#include "ext/standard/base64.h"

patches/8.5/iconv.patch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From: Peter Kokot <peterkokot@gmail.com>
2+
Subject: ext/iconv: Fix iconv prototype
3+
4+
See:
5+
* https://github.com/php/php-src/issues/20089
6+
* https://github.com/php/php-src/pull/18933
7+
* https://github.com/php/php-src/pull/16847
8+
---
9+
ext/iconv/iconv.c | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
13+
index 2b19b1e3c78..3837c4b853c 100644
14+
--- a/ext/iconv/iconv.c
15+
+++ b/ext/iconv/iconv.c
16+
@@ -43,6 +43,7 @@
17+
#undef iconv
18+
#endif
19+
20+
+#ifndef ICONV_CONST
21+
#if defined(__NetBSD__) || (defined(__sun) && defined(__SVR4))
22+
// unfortunately, netbsd has still the old non posix conformant signature
23+
// libiconv tends to match the eventual system's iconv too.
24+
@@ -50,6 +51,7 @@
25+
#else
26+
#define ICONV_CONST
27+
#endif
28+
+#endif
29+
30+
#include "zend_smart_str.h"
31+
#include "ext/standard/base64.h"

patches/8.6/iconv.patch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From: Peter Kokot <peterkokot@gmail.com>
2+
Subject: ext/iconv: Fix iconv prototype
3+
4+
See:
5+
* https://github.com/php/php-src/issues/20089
6+
* https://github.com/php/php-src/pull/18933
7+
* https://github.com/php/php-src/pull/16847
8+
---
9+
ext/iconv/iconv.c | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
13+
index 7bf0c6d2340..c7928850e94 100644
14+
--- a/ext/iconv/iconv.c
15+
+++ b/ext/iconv/iconv.c
16+
@@ -43,6 +43,7 @@
17+
#undef iconv
18+
#endif
19+
20+
+#ifndef ICONV_CONST
21+
#if defined(__NetBSD__) || (defined(__sun) && defined(__SVR4))
22+
// unfortunately, netbsd has still the old non posix conformant signature
23+
// libiconv tends to match the eventual system's iconv too.
24+
@@ -50,6 +51,7 @@
25+
#else
26+
#define ICONV_CONST
27+
#endif
28+
+#endif
29+
30+
#include "zend_smart_str.h"
31+
#include "ext/standard/base64.h"

0 commit comments

Comments
 (0)