Skip to content

Commit 33df37d

Browse files
gh-154048: Fix building the iconv codec on illumos/Solaris (GH-154049)
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>
1 parent 3c274d0 commit 33df37d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Objects/unicodeobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8279,7 +8279,10 @@ _PyUnicode_DecodeIconv(const char *encoding,
82798279
char *outptr = (char *)chunk;
82808280
size_t outleft = sizeof(chunk);
82818281

8282-
size_t ret = iconv(cd, &inptr, &inleft, &outptr, &outleft);
8282+
/* Cast the input buffer through void*: iconv() declares its second
8283+
argument as "char **" on most systems but "const char **" on some
8284+
(e.g. illumos), and void* converts to either without a warning. */
8285+
size_t ret = iconv(cd, (void *)&inptr, &inleft, &outptr, &outleft);
82838286
int err = errno;
82848287
in = inptr;
82858288

@@ -8452,7 +8455,8 @@ _PyUnicode_EncodeIconv(const char *encoding, PyObject *unicode,
84528455
size_t outleft = (size_t)(outend - out);
84538456
/* When the whole string is converted, a final iconv() call with a
84548457
NULL input flushes any pending shift sequence (e.g. ISO-2022). */
8455-
size_t ret = iconv(cd, flushing ? NULL : &inptr, &inleft, &out, &outleft);
8458+
/* See the note above on the void* cast of the iconv() input buffer. */
8459+
size_t ret = iconv(cd, flushing ? NULL : (void *)&inptr, &inleft, &out, &outleft);
84568460
if (!flushing) {
84578461
up = inptr;
84588462
}

0 commit comments

Comments
 (0)