Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5f0907

Browse files
committed
Back out #479898.
1 parent 049cd6b commit a5f0907

4 files changed

Lines changed: 24 additions & 90 deletions

File tree

Objects/stringobject.c

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ static PyStringObject *nullstring;
2626
static PyObject *interned;
2727

2828

29-
#if defined(HAVE_MBTOWC) && defined(HAVE_WCHAR_H) && defined(HAVE_WCTYPE_H)
30-
# define PRINT_MULTIBYTE_STRING
31-
# include <locale.h>
32-
# include <wchar.h>
33-
# include <wctype.h>
34-
# if defined(HAVE_ISWPRINT)
35-
# define _isprint iswprint
36-
# else
37-
# define _isprint isprint
38-
# endif
39-
#endif
40-
41-
static const char *hexchars = "0123456789abcdef";
42-
4329
/*
4430
For both PyString_FromString() and PyString_FromStringAndSize(), the
4531
parameter `size' denotes number of characters to allocate, not counting any
@@ -763,14 +749,8 @@ PyString_AsStringAndSize(register PyObject *obj,
763749
static int
764750
string_print(PyStringObject *op, FILE *fp, int flags)
765751
{
766-
#ifndef PRINT_MULTIBYTE_STRING
767752
int i;
768753
char c;
769-
#else
770-
char *scur, *send;
771-
wchar_t c;
772-
int cr;
773-
#endif
774754
int quote;
775755

776756
/* XXX Ought to check for interrupts when writing long strings */
@@ -796,36 +776,20 @@ string_print(PyStringObject *op, FILE *fp, int flags)
796776
quote = '"';
797777

798778
fputc(quote, fp);
799-
#ifndef PRINT_MULTIBYTE_STRING
800779
for (i = 0; i < op->ob_size; i++) {
801780
c = op->ob_sval[i];
802-
#else
803-
for (scur = op->ob_sval, send = op->ob_sval + op->ob_size;
804-
scur < send; scur += cr) {
805-
if ((cr = mbtowc(&c, scur, send - scur)) <= 0)
806-
goto non_printable;
807-
#endif
808781
if (c == quote || c == '\\')
809-
fputc('\\', fp), fputc(c, fp);
782+
fprintf(fp, "\\%c", c);
810783
else if (c == '\t')
811-
fputs("\\t", fp);
784+
fprintf(fp, "\\t");
812785
else if (c == '\n')
813-
fputs("\\n", fp);
786+
fprintf(fp, "\\n");
814787
else if (c == '\r')
815-
fputs("\\r", fp);
816-
#ifndef PRINT_MULTIBYTE_STRING
817-
else if (' ' <= c && c < 0x7f)
818-
fputc(c, fp);
788+
fprintf(fp, "\\r");
789+
else if (c < ' ' || c >= 0x7f)
790+
fprintf(fp, "\\x%02x", c & 0xff);
819791
else
820-
fprintf(fp, "\\x%02x", c & 0xff);
821-
#else
822-
else if (_isprint(c))
823-
fwrite(scur, cr, 1, fp);
824-
else {
825-
non_printable: cr = 1; /* unit to move cursor */
826-
fprintf(fp, "\\x%02x", *scur & 0xff);
827-
}
828-
#endif
792+
fputc(c, fp);
829793
}
830794
fputc(quote, fp);
831795
return 0;
@@ -846,14 +810,8 @@ PyString_Repr(PyObject *obj, int smartquotes)
846810
return NULL;
847811
}
848812
else {
849-
#ifndef PRINT_MULTIBYTE_STRING
850813
register int i;
851814
register char c;
852-
#else
853-
register char *scur, *send;
854-
wchar_t c;
855-
int cr;
856-
#endif
857815
register char *p;
858816
int quote;
859817

@@ -866,18 +824,11 @@ PyString_Repr(PyObject *obj, int smartquotes)
866824

867825
p = PyString_AS_STRING(v);
868826
*p++ = quote;
869-
#ifndef PRINT_MULTIBYTE_STRING
870827
for (i = 0; i < op->ob_size; i++) {
871828
/* There's at least enough room for a hex escape
872829
and a closing quote. */
873830
assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
874831
c = op->ob_sval[i];
875-
#else
876-
for (scur = op->ob_sval, send = op->ob_sval + op->ob_size;
877-
scur < send; scur += cr) {
878-
if ((cr = mbtowc(&c, scur, send - scur)) <= 0)
879-
goto non_printable;
880-
#endif
881832
if (c == quote || c == '\\')
882833
*p++ = '\\', *p++ = c;
883834
else if (c == '\t')
@@ -886,20 +837,15 @@ PyString_Repr(PyObject *obj, int smartquotes)
886837
*p++ = '\\', *p++ = 'n';
887838
else if (c == '\r')
888839
*p++ = '\\', *p++ = 'r';
889-
#ifndef PRINT_MULTIBYTE_STRING
890-
else if (' ' <= c && c < 0x7f)
891-
*p++ = c;
892-
else {
893-
#else
894-
else if (_isprint(c))
895-
memcpy(p, scur, cr), p += cr;
896-
else {
897-
non_printable: cr = 1; c = *scur;
898-
#endif
899-
*p++ = '\\'; *p++ = 'x';
900-
*p++ = hexchars[(c >> 4) & 0x0f];
901-
*p++ = hexchars[c & 0x0f];
840+
else if (c < ' ' || c >= 0x7f) {
841+
/* For performance, we don't want to call
842+
PyOS_snprintf here (extra layers of
843+
function call). */
844+
sprintf(p, "\\x%02x", c & 0xff);
845+
p += 4;
902846
}
847+
else
848+
*p++ = c;
903849
}
904850
assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
905851
*p++ = quote;

configure

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.355 .
2+
# From configure.in Revision: 1.356 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53.
55
#
@@ -901,7 +901,7 @@ esac
901901
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
902902
# absolute.
903903
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
904-
ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
904+
ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
905905
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
906906
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
907907
@@ -3888,15 +3888,14 @@ fi
38883888
38893889
38903890
3891-
38923891
38933892
38943893
for ac_header in dlfcn.h fcntl.h grp.h limits.h langinfo.h \
38953894
libintl.h locale.h ncurses.h poll.h pthread.h \
38963895
signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
38973896
sys/audioio.h sys/file.h sys/lock.h sys/mkdev.h sys/modem.h \
38983897
sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
3899-
sys/un.h sys/utsname.h sys/wait.h pty.h term.h wctype.h libutil.h \
3898+
sys/un.h sys/utsname.h sys/wait.h pty.h term.h libutil.h \
39003899
sys/resource.h netpacket/packet.h
39013900
do
39023901
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -11931,16 +11930,14 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
1193111930
1193211931
1193311932
11934-
11935-
1193611933
1193711934
1193811935
1193911936
for ac_func in alarm chown chroot clock confstr ctermid ctermid_r execv \
1194011937
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
1194111938
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
11942-
hstrerror inet_pton iswprint kill killpg lchown link lstat mbtowc mkfifo \
11943-
mknod mktime mremap nice pathconf pause plock poll pthread_init \
11939+
hstrerror inet_pton kill killpg lchown link lstat mkfifo mknod mktime \
11940+
mremap nice pathconf pause plock poll pthread_init \
1194411941
putenv readlink \
1194511942
select setegid seteuid setgid setgroups \
1194611943
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
@@ -17175,7 +17172,7 @@ esac
1717517172
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
1717617173
# absolute.
1717717174
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
17178-
ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
17175+
ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
1717917176
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
1718017177
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
1718117178

configure.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ libintl.h locale.h ncurses.h poll.h pthread.h \
618618
signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
619619
sys/audioio.h sys/file.h sys/lock.h sys/mkdev.h sys/modem.h \
620620
sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
621-
sys/un.h sys/utsname.h sys/wait.h pty.h term.h wctype.h libutil.h \
621+
sys/un.h sys/utsname.h sys/wait.h pty.h term.h libutil.h \
622622
sys/resource.h netpacket/packet.h)
623623
AC_HEADER_DIRENT
624624
AC_HEADER_MAJOR
@@ -1680,8 +1680,8 @@ AC_MSG_RESULT(MACHDEP_OBJS)
16801680
AC_CHECK_FUNCS(alarm chown chroot clock confstr ctermid ctermid_r execv \
16811681
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
16821682
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
1683-
hstrerror inet_pton iswprint kill killpg lchown link lstat mbtowc mkfifo \
1684-
mknod mktime mremap nice pathconf pause plock poll pthread_init \
1683+
hstrerror inet_pton kill killpg lchown link lstat mkfifo mknod mktime \
1684+
mremap nice pathconf pause plock poll pthread_init \
16851685
putenv readlink \
16861686
select setegid seteuid setgid setgroups \
16871687
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \

pyconfig.h.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@
199199
/* Define to 1 if you have the <inttypes.h> header file. */
200200
#undef HAVE_INTTYPES_H
201201

202-
/* Define to 1 if you have the `iswprint' function. */
203-
#undef HAVE_ISWPRINT
204-
205202
/* Define to 1 if you have the `kill' function. */
206203
#undef HAVE_KILL
207204

@@ -253,9 +250,6 @@
253250
/* Define this if you have the makedev macro. */
254251
#undef HAVE_MAKEDEV
255252

256-
/* Define to 1 if you have the `mbtowc' function. */
257-
#undef HAVE_MBTOWC
258-
259253
/* Define to 1 if you have the `memmove' function. */
260254
#undef HAVE_MEMMOVE
261255

@@ -595,9 +589,6 @@
595589
/* Define if the compiler provides a wchar.h header file. */
596590
#undef HAVE_WCHAR_H
597591

598-
/* Define to 1 if you have the <wctype.h> header file. */
599-
#undef HAVE_WCTYPE_H
600-
601592
/* Define to 1 if you have the `_getpty' function. */
602593
#undef HAVE__GETPTY
603594

0 commit comments

Comments
 (0)