$NetBSD: patch-ba,v 1.2 2002/10/18 08:08:33 wiz Exp $ There is a problem in ext/charconv/jconv.c which may cause gosh hang, due to the wrong state management. Specifically, it happens if you specify "iso-2022-jp" as the output code, instead of "iso2022jp" or "iso2022-jp". --shiro *** ext/charconv/jconv.c 17 Jun 2002 05:41:04 -0000 1.9 --- ext/charconv/jconv.c 26 Sep 2002 05:22:59 -0000 *************** *** 1294,1299 **** --- 1294,1305 ---- /* case (5) */ #ifdef HAVE_ICONV_H + /* NB: although iconv manages states, we need to keep track of whether + * we're sure in default status (JIS_ASCII) or not (we use JIS_UNKNOWN for it). + * It's because jconv_iconv_reset will be called twice if there is any + * reset sequence; the first call should emit the sequence, but the second + * call shoudn't. + */ static size_t jconv_iconv(ScmConvInfo *info, const char **iptr, size_t *iroom, char **optr, size_t *oroom) { *************** *** 1302,1307 **** --- 1308,1314 ---- fprintf(stderr, "jconv_iconv %s->%s\n", info->fromCode, info->toCode); #endif r = iconv(info->handle, (char **)iptr, iroom, optr, oroom); + info->ostate = JIS_UNKNOWN; if (r == (size_t)-1) { if (errno == EINVAL) return INPUT_NOT_ENOUGH; if (errno == E2BIG) return OUTPUT_NOT_ENOUGH; *************** *** 1315,1325 **** static size_t jconv_iconv_reset(ScmConvInfo *info, char *optr, size_t oroom) { size_t oroom_prev = oroom; ! size_t r = iconv(info->handle, NULL, 0, &optr, &oroom); if (r == (size_t)-1) { if (errno == E2BIG) return OUTPUT_NOT_ENOUGH; Scm_Panic("jconv_iconv_reset: unknown error number %d\n", errno); } return oroom_prev - oroom; } #endif /*HAVE_ICONV_H*/ --- 1322,1335 ---- static size_t jconv_iconv_reset(ScmConvInfo *info, char *optr, size_t oroom) { size_t oroom_prev = oroom; ! size_t r; ! if (info->ostate == JIS_ASCII) return 0; ! r = iconv(info->handle, NULL, 0, &optr, &oroom); if (r == (size_t)-1) { if (errno == E2BIG) return OUTPUT_NOT_ENOUGH; Scm_Panic("jconv_iconv_reset: unknown error number %d\n", errno); } + info->ostate = JIS_ASCII; return oroom_prev - oroom; } #endif /*HAVE_ICONV_H*/