This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sysconfig gives misleading results for USE_COMPUTED_GOTOS
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, flox, meador.inge, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2011-10-21 14:41 by flox, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
issue13240.patch meador.inge, 2011-10-23 17:20 Patch v0 against tip (3.3.0a0) review
Messages (12)
msg146090 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-21 14:41
According to issue 9203 the computed gotos should be enabled by default since 3.2.
However, it is not visible from the interpreter.

Python 3.2.2 (default, Sep  7 2011, 10:55:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>> from sysconfig import get_config_var
>>> get_config_var('HAVE_COMPUTED_GOTOS')
1
>>> get_config_var('USE_COMPUTED_GOTOS')
0
msg146097 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-21 15:51
> According to issue 9203 the computed gotos should be enabled by default since 3.2.
> However, it is not visible from the interpreter.
> 
> Python 3.2.2 (default, Sep  7 2011, 10:55:43) 
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> >>> from sysconfig import get_config_var
> >>> get_config_var('HAVE_COMPUTED_GOTOS')
> 1
> >>> get_config_var('USE_COMPUTED_GOTOS')
> 0

This looks like the system Python compiled by Apple. What about a
hand-compiled Python?
msg146099 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-10-21 15:58
Just compiled 3.2 on Debian:

>>> sysconfig.get_config_var('USE_COMPUTED_GOTOS')
0
msg146100 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-21 16:02
> This looks like the system Python compiled by Apple. What about a
> hand-compiled Python?

Forget this. I get the same results here.

However, if you add a "#error" at the right place in ceval.c, you'll see that computed gotos are enabled. It seems more of a sysconfig bug or limitation. In pyconfig.h, I have the following:

$ \grep GOTO pyconfig.h
#define HAVE_COMPUTED_GOTOS 1
/* #undef USE_COMPUTED_GOTOS */

Which apparently sysconfig translates as USE_COMPUTED_GOTOS being equal to 0, which I think is wrong.
msg146105 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-21 17:03
Extract of configure.in:
-------------------------------------
# Check for --with-computed-gotos
AC_MSG_CHECKING(for --with-computed-gotos)
AC_ARG_WITH(computed-gotos,
            AS_HELP_STRING([--with(out)-computed-gotos],
                           [Use computed gotos in evaluation loop (enabled by default on supported compilers)]),
[
if test "$withval" = yes
then 
  AC_DEFINE(USE_COMPUTED_GOTOS, 1,
  [Define if you want to use computed gotos in ceval.c.]) 
  AC_MSG_RESULT(yes)
fi
if test "$withval" = no
then 
  AC_DEFINE(USE_COMPUTED_GOTOS, 0,
  [Define if you want to use computed gotos in ceval.c.]) 
  AC_MSG_RESULT(no)
fi
],
[AC_MSG_RESULT(no value specified)])
-------------------------------------

Extract of my config.log:
-------------------------------------
configure:13788: checking whether gcc -pthread supports computed gotos
configure:13811: gcc -pthread -o conftest    conftest.c -lpthread -ldl  -lutil >&5
configure:13811: $? = 0
configure:13811: ./conftest
configure:13811: $? = 0
configure:13822: result: yes
configure:13832: checking for --with-computed-gotos
configure:13856: result: no value specified
-------------------------------------

Extract of my pyconfig.h
-------------------------------------
/* Define if you want to use computed gotos in ceval.c. */
/* #undef USE_COMPUTED_GOTOS */
-------------------------------------

Computed goto are disabled (in my Python 3.3 on Linux with GCC), I checked by adding #error to ceval.c.
msg146106 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-21 17:13
> Extract of my pyconfig.h
> -------------------------------------
> /* Define if you want to use computed gotos in ceval.c. */
> /* #undef USE_COMPUTED_GOTOS */
> -------------------------------------

Ok, now read ceval.c:

#ifdef HAVE_COMPUTED_GOTOS
    #ifndef USE_COMPUTED_GOTOS
    #define USE_COMPUTED_GOTOS 1
    #endif
#else
    #if defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS
    #error "Computed gotos are not supported on this compiler."
    #endif
    #undef USE_COMPUTED_GOTOS
    #define USE_COMPUTED_GOTOS 0
#endif
msg146107 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-21 17:17
With the #error, I can confirm that computed gotos are enabled on OS X.

About sysconfig, we may change the code to set None if the value is "undef". I don't know the impact.


--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -404,7 +404,7 @@
         else:
             m = undef_rx.match(line)
             if m:
-                vars[m.group(1)] = 0
+                vars[m.group(1)] = None
     return vars
msg146108 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-21 17:19
> With the #error, I can confirm that computed gotos are enabled on OS X.
> 
> About sysconfig, we may change the code to set None if the value is "undef". I don't know the impact.

Actually, I think sysconfig does the right thing when it comes to all
the configure-generated HAVE_XXX variables (due to the peculiar way the
configure/pyconfig.h couple works).

It's just that USE_COMPUTED_GOTOS is a ternary variable (0/1/undefined),
so maybe we should accept as a limitation that sysconfig returns a
misleading result here.
msg146109 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-21 17:20
> Computed goto are disabled (in my Python 3.3 on Linux with GCC),
> I checked by adding #error to ceval.c.

Hum, I don't understand how, but I missed the #error failure. Computed goto *are enabled* by default.
msg146235 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-10-23 17:20
> Actually, I think sysconfig does the right thing when it comes to all
> the configure-generated HAVE_XXX variables

I agree.  The 'configure' script could be improved, though.  If we truly
want to enable this by default, then the defaulting should be moved to
configure.  This will give a more accurate portrayal in sysconfig.
Also, we can do the USE but !HAVE check in configure, which is better
anyway because the error is caught earlier.

I am thinking something like the attached.  Thoughts?

P.S. We could probably get rid of the HAVE macro all together by doing
all the work in the 'configure' script.
msg146376 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-10-25 15:54
> If we truly want to enable this by default, then the defaulting should be moved to
> configure.  This will give a more accurate portrayal in sysconfig.
This sounds good.  (I know little about configure/pyconfig.h, but making sysconfig more accurate is a valuable result.)

> P.S. We could probably get rid of the HAVE macro all together by doing
> all the work in the 'configure' script.
Would that be a breach of backward compatibility for sysconfig?
msg146408 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-10-26 03:15
>> P.S. We could probably get rid of the HAVE macro all together by doing
>> all the work in the 'configure' script.
> Would that be a breach of backward compatibility for sysconfig?

Yeah, I think so.  Best to leave it alone then.
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57449
2020-11-16 19:30:57iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.2, Python 3.3
2011-10-26 03:15:01meador.ingesetmessages: + msg146408
2011-10-25 15:54:53eric.araujosetmessages: + msg146376
2011-10-23 17:20:40meador.ingesetfiles: + issue13240.patch

nosy: + meador.inge
messages: + msg146235

keywords: + patch
2011-10-21 17:20:48vstinnersetmessages: + msg146109
2011-10-21 17:19:13pitrousetmessages: + msg146108
2011-10-21 17:17:10floxsetmessages: + msg146107
2011-10-21 17:13:46pitrousetmessages: + msg146106
2011-10-21 17:03:47vstinnersetnosy: + vstinner
messages: + msg146105
2011-10-21 16:02:14pitrousettype: performance -> behavior
messages: + msg146100
components: + Library (Lib), - Build
title: computed gotos not enabled? -> sysconfig gives misleading results for USE_COMPUTED_GOTOS
2011-10-21 15:58:57eric.araujosetnosy: + eric.araujo
messages: + msg146099
2011-10-21 15:51:45pitrousetmessages: + msg146097
2011-10-21 14:41:25floxcreate