]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154048: Fix building the iconv codec on illumos/Solaris (GH-154049)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 19 Jul 2026 06:23:26 +0000 (09:23 +0300)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 06:23:26 +0000 (06:23 +0000)
iconv()'s input-buffer argument is declared "const char **" on some systems
(illumos/Solaris, old GNU libiconv) rather than the POSIX "char **", so passing
a "char **" failed to compile.  Cast it through void*, which converts to either
without a warning.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Objects/unicodeobject.c

index 6562546ae2f9ccb81fcefc7d058be9c28618b68c..a4550c0f5f3363a4dbb1ceca503b4776974994e5 100644 (file)
@@ -8279,7 +8279,10 @@ _PyUnicode_DecodeIconv(const char *encoding,
         char *outptr = (char *)chunk;
         size_t outleft = sizeof(chunk);
 
-        size_t ret = iconv(cd, &inptr, &inleft, &outptr, &outleft);
+        /* Cast the input buffer through void*: iconv() declares its second
+           argument as "char **" on most systems but "const char **" on some
+           (e.g. illumos), and void* converts to either without a warning. */
+        size_t ret = iconv(cd, (void *)&inptr, &inleft, &outptr, &outleft);
         int err = errno;
         in = inptr;
 
@@ -8452,7 +8455,8 @@ _PyUnicode_EncodeIconv(const char *encoding, PyObject *unicode,
         size_t outleft = (size_t)(outend - out);
         /* When the whole string is converted, a final iconv() call with a
            NULL input flushes any pending shift sequence (e.g. ISO-2022). */
-        size_t ret = iconv(cd, flushing ? NULL : &inptr, &inleft, &out, &outleft);
+        /* See the note above on the void* cast of the iconv() input buffer. */
+        size_t ret = iconv(cd, flushing ? NULL : (void *)&inptr, &inleft, &out, &outleft);
         if (!flushing) {
             up = inptr;
         }