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

Skip to content

Commit 042b128

Browse files
committed
Issue #9203: Computed gotos are now enabled by default on supported
compilers (which are detected by the configure script). They can still be disable selectively by specifying --without-computed-gotos.
1 parent d835cf1 commit 042b128

5 files changed

Lines changed: 126 additions & 25 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 2?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #9203: Computed gotos are now enabled by default on supported
16+
compilers (which are detected by the configure script). They can still
17+
be disable selectively by specifying --without-computed-gotos.
18+
1519
- Issue #9425: Create PyErr_WarnFormat() function, similar to PyErr_WarnEx()
1620
but use PyUnicode_FromFormatV() to format the warning message.
1721

Python/ceval.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,11 +840,24 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
840840
-fno-crossjumping).
841841
*/
842842

843-
#if defined(USE_COMPUTED_GOTOS) && defined(DYNAMIC_EXECUTION_PROFILE)
843+
#ifdef DYNAMIC_EXECUTION_PROFILE
844844
#undef USE_COMPUTED_GOTOS
845+
#define USE_COMPUTED_GOTOS 0
846+
#endif
847+
848+
#ifdef HAVE_COMPUTED_GOTOS
849+
#ifndef USE_COMPUTED_GOTOS
850+
#define USE_COMPUTED_GOTOS 1
851+
#endif
852+
#else
853+
#if defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS
854+
#error "Computed gotos are not supported on this compiler."
855+
#endif
856+
#undef USE_COMPUTED_GOTOS
857+
#define USE_COMPUTED_GOTOS 0
845858
#endif
846859

847-
#ifdef USE_COMPUTED_GOTOS
860+
#if USE_COMPUTED_GOTOS
848861
/* Import the static jump table */
849862
#include "opcode_targets.h"
850863

@@ -990,7 +1003,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
9901003
9911004
*/
9921005

993-
#if defined(DYNAMIC_EXECUTION_PROFILE) || defined(USE_COMPUTED_GOTOS)
1006+
#if defined(DYNAMIC_EXECUTION_PROFILE) || USE_COMPUTED_GOTOS
9941007
#define PREDICT(op) if (0) goto PRED_##op
9951008
#define PREDICTED(op) PRED_##op:
9961009
#define PREDICTED_WITH_ARG(op) PRED_##op:
@@ -2838,7 +2851,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
28382851
oparg = oparg<<16 | NEXTARG();
28392852
goto dispatch_opcode;
28402853

2841-
#ifdef USE_COMPUTED_GOTOS
2854+
#if USE_COMPUTED_GOTOS
28422855
_unknown_opcode:
28432856
#endif
28442857
default:

configure

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 82090 .
2+
# From configure.in Revision: 83580 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.65 for python 3.2.
55
#
@@ -1421,8 +1421,9 @@ Optional Packages:
14211421
--with-libm=STRING math library
14221422
--with-libc=STRING C library
14231423
--with-wide-unicode Use 4-byte Unicode characters (default is 2 bytes)
1424-
--with-computed-gotos Use computed gotos / threaded dispatch in evaluation
1425-
loop (not available on all compilers)
1424+
--with(out)-computed-gotos
1425+
Use computed gotos in evaluation loop (enabled by
1426+
default on supported compilers)
14261427
14271428
Some influential environment variables:
14281429
CC C compiler command
@@ -1929,11 +1930,11 @@ else
19291930
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
19301931
/* end confdefs.h. */
19311932
$ac_includes_default
1932-
enum { N = $2 / 2 - 1 };
19331933
int
19341934
main ()
19351935
{
1936-
static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
1936+
static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
1937+
0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
19371938
test_array [0] = 0
19381939
19391940
;
@@ -1944,11 +1945,11 @@ if ac_fn_c_try_compile "$LINENO"; then :
19441945
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
19451946
/* end confdefs.h. */
19461947
$ac_includes_default
1947-
enum { N = $2 / 2 - 1 };
19481948
int
19491949
main ()
19501950
{
1951-
static int test_array [1 - 2 * !(($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
1951+
static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
1952+
($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
19521953
< ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))];
19531954
test_array [0] = 0
19541955
@@ -9121,7 +9122,7 @@ fi
91219122
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_doc_strings" >&5
91229123
$as_echo "$with_doc_strings" >&6; }
91239124
9124-
# Check for Python-specific malloc support
9125+
# Check if eval loop should use timestamp counter profiling
91259126
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tsc" >&5
91269127
$as_echo_n "checking for --with-tsc... " >&6; }
91279128
@@ -13502,28 +13503,78 @@ $as_echo "#define HAVE_BROKEN_MBSTOWCS 1" >>confdefs.h
1350213503
1350313504
fi
1350413505
13506+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports computed gotos" >&5
13507+
$as_echo_n "checking whether $CC supports computed gotos... " >&6; }
13508+
if test "${ac_cv_computed_gotos+set}" = set; then :
13509+
$as_echo_n "(cached) " >&6
13510+
else
13511+
if test "$cross_compiling" = yes; then :
13512+
ac_cv_computed_gotos=no
13513+
else
13514+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13515+
/* end confdefs.h. */
13516+
13517+
int main(int argc, char **argv)
13518+
{
13519+
static void *targets[1] = { &&LABEL1 };
13520+
goto LABEL2;
13521+
LABEL1:
13522+
return 0;
13523+
LABEL2:
13524+
goto *targets[0];
13525+
return 1;
13526+
}
13527+
13528+
_ACEOF
13529+
if ac_fn_c_try_run "$LINENO"; then :
13530+
ac_cv_computed_gotos=yes
13531+
else
13532+
ac_cv_computed_gotos=no
13533+
fi
13534+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
13535+
conftest.$ac_objext conftest.beam conftest.$ac_ext
13536+
fi
13537+
13538+
fi
13539+
13540+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_computed_gotos" >&5
13541+
$as_echo "$ac_cv_computed_gotos" >&6; }
13542+
if test "$ac_cv_computed_gotos" = yes
13543+
then
13544+
13545+
$as_echo "#define HAVE_COMPUTED_GOTOS 1" >>confdefs.h
13546+
13547+
fi
13548+
1350513549
# Check for --with-computed-gotos
1350613550
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-computed-gotos" >&5
1350713551
$as_echo_n "checking for --with-computed-gotos... " >&6; }
1350813552
1350913553
# Check whether --with-computed-gotos was given.
1351013554
if test "${with_computed_gotos+set}" = set; then :
1351113555
withval=$with_computed_gotos;
13512-
if test "$withval" != no
13556+
if test "$withval" = yes
1351313557
then
1351413558
1351513559
$as_echo "#define USE_COMPUTED_GOTOS 1" >>confdefs.h
1351613560
1351713561
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1351813562
$as_echo "yes" >&6; }
13519-
else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
13520-
$as_echo "no" >&6; }
1352113563
fi
13522-
else
13564+
if test "$withval" = no
13565+
then
13566+
13567+
$as_echo "#define USE_COMPUTED_GOTOS 0" >>confdefs.h
13568+
1352313569
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
1352413570
$as_echo "no" >&6; }
1352513571
fi
1352613572
13573+
else
13574+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no value specified" >&5
13575+
$as_echo "no value specified" >&6; }
13576+
fi
13577+
1352713578
1352813579
1352913580
@@ -14086,8 +14137,8 @@ esac
1408614137
1408714138
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1408814139
# Files that config.status was made for.
14089-
config_files="$ac_config_files"
14090-
config_headers="$ac_config_headers"
14140+
config_files="`echo $ac_config_files`"
14141+
config_headers="`echo $ac_config_headers`"
1409114142
1409214143
_ACEOF
1409314144

configure.in

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,20 +4124,50 @@ then
41244124
wide chars that would be converted.])
41254125
fi
41264126

4127+
AC_MSG_CHECKING(whether $CC supports computed gotos)
4128+
AC_CACHE_VAL(ac_cv_computed_gotos,
4129+
AC_RUN_IFELSE([AC_LANG_SOURCE([[[
4130+
int main(int argc, char **argv)
4131+
{
4132+
static void *targets[1] = { &&LABEL1 };
4133+
goto LABEL2;
4134+
LABEL1:
4135+
return 0;
4136+
LABEL2:
4137+
goto *targets[0];
4138+
return 1;
4139+
}
4140+
]]])],
4141+
[ac_cv_computed_gotos=yes],
4142+
[ac_cv_computed_gotos=no],
4143+
[ac_cv_computed_gotos=no]))
4144+
AC_MSG_RESULT($ac_cv_computed_gotos)
4145+
if test "$ac_cv_computed_gotos" = yes
4146+
then
4147+
AC_DEFINE(HAVE_COMPUTED_GOTOS, 1,
4148+
[Define if the C compiler supports computed gotos.])
4149+
fi
4150+
41274151
# Check for --with-computed-gotos
41284152
AC_MSG_CHECKING(for --with-computed-gotos)
41294153
AC_ARG_WITH(computed-gotos,
4130-
AS_HELP_STRING([--with-computed-gotos],
4131-
[Use computed gotos / threaded dispatch in evaluation loop (not available on all compilers)]),
4154+
AS_HELP_STRING([--with(out)-computed-gotos],
4155+
[Use computed gotos in evaluation loop (enabled by default on supported compilers)]),
41324156
[
4133-
if test "$withval" != no
4157+
if test "$withval" = yes
41344158
then
41354159
AC_DEFINE(USE_COMPUTED_GOTOS, 1,
41364160
[Define if you want to use computed gotos in ceval.c.])
41374161
AC_MSG_RESULT(yes)
4138-
else AC_MSG_RESULT(no)
4139-
fi],
4140-
[AC_MSG_RESULT(no)])
4162+
fi
4163+
if test "$withval" = no
4164+
then
4165+
AC_DEFINE(USE_COMPUTED_GOTOS, 0,
4166+
[Define if you want to use computed gotos in ceval.c.])
4167+
AC_MSG_RESULT(no)
4168+
fi
4169+
],
4170+
[AC_MSG_RESULT(no value specified)])
41414171

41424172

41434173

pyconfig.h.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
/* Define to 1 if you have the `clock' function. */
105105
#undef HAVE_CLOCK
106106

107+
/* Define if the C compiler supports computed gotos. */
108+
#undef HAVE_COMPUTED_GOTOS
109+
107110
/* Define to 1 if you have the `confstr' function. */
108111
#undef HAVE_CONFSTR
109112

@@ -1037,7 +1040,7 @@
10371040
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
10381041
#undef TM_IN_SYS_TIME
10391042

1040-
/* Define if you want to use computed gotos in ceval.c. */
1043+
/* Define to 0 if you don't want to use computed gotos in ceval.c. */
10411044
#undef USE_COMPUTED_GOTOS
10421045

10431046
/* Enable extensions on AIX 3, Interix. */

0 commit comments

Comments
 (0)