diff -u -r2.153 Objects/stringobject.c --- Objects/stringobject.c 30 Mar 2002 10:06:07 -0000 2.153 +++ Objects/stringobject.c 1 Apr 2002 18:01:55 -0000 @@ -16,6 +16,19 @@ static PyStringObject *characters[UCHAR_MAX + 1]; static PyStringObject *nullstring; +#if defined(HAVE_MBTOWC) && defined(HAVE_WCHAR_H) +# define PRINT_MULTIBYTE_STRING +# include +# include +# if defined(HAVE_ISWPRINT) +# define _isprint iswprint +# else +# define _isprint isprint +# endif +#endif + +static const char *hexchars = "0123456789abcdef"; + /* For both PyString_FromString() and PyString_FromStringAndSize(), the parameter `size' denotes number of characters to allocate, not counting any @@ -564,8 +577,14 @@ static int string_print(PyStringObject *op, FILE *fp, int flags) { +#ifndef PRINT_MULTIBYTE_STRING int i; char c; +#else + char *scur, *send; + wchar_t c; + int cr; +#endif int quote; /* XXX Ought to check for interrupts when writing long strings */ @@ -590,20 +609,36 @@ quote = '"'; fputc(quote, fp); +#ifndef PRINT_MULTIBYTE_STRING for (i = 0; i < op->ob_size; i++) { c = op->ob_sval[i]; +#else + for (scur = op->ob_sval, send = op->ob_sval + op->ob_size; + scur < send; scur += cr) { + if ((cr = mbtowc(&c, scur, send - scur)) <= 0) + goto non_printable; +#endif if (c == quote || c == '\\') - fprintf(fp, "\\%c", c); + fputc('\\', fp), fputc(c, fp); else if (c == '\t') - fprintf(fp, "\\t"); + fputs("\\t", fp); else if (c == '\n') - fprintf(fp, "\\n"); + fputs("\\n", fp); else if (c == '\r') - fprintf(fp, "\\r"); - else if (c < ' ' || c >= 0x7f) - fprintf(fp, "\\x%02x", c & 0xff); - else + fputs("\\r", fp); +#ifndef PRINT_MULTIBYTE_STRING + else if (' ' <= c && c < 0x7f) fputc(c, fp); + else + fprintf(fp, "\\x%02x", c & 0xff); +#else + else if (_isprint(c)) + fwrite(scur, cr, 1, fp); + else { +non_printable: cr = 1; /* unit to move cursor */ + fprintf(fp, "\\x%02x", *scur & 0xff); + } +#endif } fputc(quote, fp); return 0; @@ -623,8 +658,14 @@ return NULL; } else { +#ifndef PRINT_MULTIBYTE_STRING register int i; register char c; +#else + register char *scur, *send; + wchar_t c; + int cr; +#endif register char *p; int quote; @@ -635,11 +676,18 @@ p = PyString_AS_STRING(v); *p++ = quote; +#ifndef PRINT_MULTIBYTE_STRING for (i = 0; i < op->ob_size; i++) { /* There's at least enough room for a hex escape and a closing quote. */ assert(newsize - (p - PyString_AS_STRING(v)) >= 5); c = op->ob_sval[i]; +#else + for (scur = op->ob_sval, send = op->ob_sval + op->ob_size; + scur < send; scur += cr) { + if ((cr = mbtowc(&c, scur, send - scur)) <= 0) + goto non_printable; +#endif if (c == quote || c == '\\') *p++ = '\\', *p++ = c; else if (c == '\t') @@ -648,15 +696,20 @@ *p++ = '\\', *p++ = 'n'; else if (c == '\r') *p++ = '\\', *p++ = 'r'; - else if (c < ' ' || c >= 0x7f) { - /* For performance, we don't want to call - PyOS_snprintf here (extra layers of - function call). */ - sprintf(p, "\\x%02x", c & 0xff); - p += 4; - } - else +#ifndef PRINT_MULTIBYTE_STRING + else if (' ' <= c && c < 0x7f) *p++ = c; + else { +#else + else if (_isprint(c)) + memcpy(p, scur, cr), p += cr; + else { +non_printable: cr = 1; c = *scur; +#endif + *p++ = '\\'; *p++ = 'x'; + *p++ = hexchars[(c >> 4) & 0x0f]; + *p++ = hexchars[c & 0x0f]; + } } assert(newsize - (p - PyString_AS_STRING(v)) >= 1); *p++ = quote; diff -u -r1.302 configure.in --- configure.in 29 Mar 2002 16:28:31 -0000 1.302 +++ configure.in 1 Apr 2002 18:02:10 -0000 @@ -1484,7 +1484,8 @@ AC_CHECK_FUNCS(alarm chown chroot clock confstr ctermid ctermid_r execv \ flock fork fsync fdatasync fpathconf ftime ftruncate \ gai_strerror getgroups getlogin getpeername getpid getpwent getwd \ - hstrerror inet_pton kill killpg link lstat mkfifo mktime mremap \ + hstrerror inet_pton iswprint kill killpg link lstat \ + mbtowc mkfifo mktime mremap \ nice pathconf pause plock poll pthread_init \ putenv readlink \ select setegid seteuid setgid setgroups \ diff -u -r1.25 pyconfig.h.in --- pyconfig.h.in 27 Mar 2002 18:49:02 -0000 1.25 +++ pyconfig.h.in 1 Apr 2002 18:02:56 -0000 @@ -15,9 +15,15 @@ /* Define to empty if the keyword does not work. */ #undef const +/* Define to empty if the volatile keyword does not work. */ +#undef volatile + /* Define to `int' if doesn't define. */ #undef gid_t +/* Define if you have the getaddrinfo function. */ +#undef HAVE_GETADDRINFO + /* Define if your struct stat has st_blksize. */ #undef HAVE_ST_BLKSIZE @@ -456,6 +462,9 @@ /* Define if you have the inet_pton function. */ #undef HAVE_INET_PTON +/* Define if you have the iswprint function. */ +#undef HAVE_ISWPRINT + /* Define if you have the kill function. */ #undef HAVE_KILL @@ -467,6 +476,9 @@ /* Define if you have the lstat function. */ #undef HAVE_LSTAT + +/* Define if you have the mbtowc function. */ +#undef HAVE_MBTOWC /* Define if you have the memmove function. */ #undef HAVE_MEMMOVE