Skip to content

sysconfig gives misleading results for USE_COMPUTED_GOTOS #57449

Open

Description

@florentx
mannequin
BPO 13240
Nosy @pitrou, @vstinner, @merwok, @florentx, @meadori
Files
  • issue13240.patch: Patch v0 against tip (3.3.0a0)
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-10-21.14:41:25.714>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = 'sysconfig gives misleading results for USE_COMPUTED_GOTOS'
    updated_at = <Date 2020-11-16.19:30:57.509>
    user = 'https://github.com/florentx'

    bugs.python.org fields:

    activity = <Date 2020-11-16.19:30:57.509>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2011-10-21.14:41:25.714>
    creator = 'flox'
    dependencies = []
    files = ['23503']
    hgrepos = []
    issue_num = 13240
    keywords = ['patch']
    message_count = 12.0
    messages = ['146090', '146097', '146099', '146100', '146105', '146106', '146107', '146108', '146109', '146235', '146376', '146408']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'vstinner', 'eric.araujo', 'flox', 'meador.inge']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13240'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    Activity

    1. florentx commented on Oct 21, 2011

      florentxmannequin
      MannequinAuthor

      According to bpo-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
    2. added
      performance
      build
      on Oct 21, 2011
    3. pitrou commented on Oct 21, 2011

      @pitrou
      Member

      According to bpo-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?

    4. merwok commented on Oct 21, 2011

      @merwok
      Member

      Just compiled 3.2 on Debian:

      >>> sysconfig.get_config_var('USE_COMPUTED_GOTOS')
      0
    5. pitrou commented on Oct 21, 2011

      @pitrou
      Member

      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.

    6. added
      stdlib
      and removed
      build
      on Oct 21, 2011
    7. changed the title [-]computed gotos not enabled?[/-] [+]sysconfig gives misleading results for USE_COMPUTED_GOTOS[/+] on Oct 21, 2011
    8. added
      type-bug
      and removed
      performance
      on Oct 21, 2011
    9. vstinner commented on Oct 21, 2011

      @vstinner
      Member

      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.

    10. pitrou commented on Oct 21, 2011

      @pitrou
      Member

      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
    11. florentx commented on Oct 21, 2011

      florentxmannequin
      MannequinAuthor

      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
    12. pitrou commented on Oct 21, 2011

      @pitrou
      Member

      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.

    13. 3 remaining items

    14. meadori commented on Oct 26, 2011

      @meadori
      Member

      > 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.

    15. added
      3.8 (EOL)
      3.9 (EOL)
      3.10 (EOL)
      on Nov 16, 2020
    16. transferred this issue fromon Apr 10, 2022
    17. added and removed
      3.10 (EOL)
      3.9 (EOL)
      3.8 (EOL)
      on Apr 29, 2023
    18. arhadthedev commented on Apr 29, 2023

      @arhadthedev
      Member

      Is the issue still reprodusible on OS X?

    19. ronaldoussoren commented on May 2, 2023

      @ronaldoussoren
      Contributor

      Is the issue still reprodusible on OS X?

      % python                                                                                                                                  (master)pyobjc-8
      Python 3.11.3 (v3.11.3:f3909b8bc8, Apr  4 2023, 20:12:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from sysconfig import get_config_var
      >>> get_config_var('HAVE_COMPUTED_GOTOS')
      1
      >>> get_config_var('USE_COMPUTED_GOTOS')
      1
      >>> 

      This is with the 3.11.3 installed from python.org. So no, this doesn't seem to be reproducible on macOS.

    20. ronaldoussoren commented on Jun 24, 2023

      @ronaldoussoren
      Contributor

      Dropping the os-mac label because this isn't a Mac-specific issue.

    21. vasiliyk commented on Oct 22, 2026

      @vasiliyk
      Contributor

      Still reproducible on 3.16.0a1+dev:

      >>> from sysconfig import get_config_var
      >>> get_config_var('HAVE_COMPUTED_GOTOS')
      1
      >>> get_config_var('USE_COMPUTED_GOTOS')
      0

      configure leaves USE_COMPUTED_GOTOS undefined in pyconfig.h.
      sysconfig reads that as 0, but Python/ceval_macros.h treats it as 1, so computed gotos are actually enabled.

      The fix agreed above still applies:
      let configure.ac define USE_COMPUTED_GOTOS to 1 when no option is given and the compiler supports it.

      I will open a PR for this.

    22. vasiliyk commented on Nov 24, 2026

      @vasiliyk
      Contributor

      With PR configure.ac defines USE_COMPUTED_GOTOS to 1 when no option is given and the compiler supports it.

      --with-computed-gotos and --without-computed-gotos still give 1 and 0.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions