Skip to content

Tkinter doesn't support large integers #61044

Closed

Description

@serhiy-storchaka
BPO 16840
Nosy @loewis, @vstinner, @benjaminp, @serhiy-storchaka
Files
  • tkinter_bignum_4.patch
  • tkinter_hexversion.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-04-22.12:33:08.917>
    created_at = <Date 2013-01-02.15:09:13.577>
    labels = ['type-feature', 'expert-tkinter']
    title = "Tkinter doesn't support large integers"
    updated_at = <Date 2015-04-22.12:33:08.916>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-04-22.12:33:08.916>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-04-22.12:33:08.917>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2013-01-02.15:09:13.577>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['38198', '39158']
    hgrepos = []
    issue_num = 16840
    keywords = ['patch', 'needs review']
    message_count = 21.0
    messages = ['178815', '178988', '179204', '195916', '218743', '235098', '236375', '236381', '236386', '236387', '239928', '239932', '240224', '240228', '240442', '241628', '241630', '241706', '241708', '241729', '241785']
    nosy_count = 6.0
    nosy_names = ['loewis', 'vstinner', 'benjamin.peterson', 'gpolo', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16840'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    Activity

    1. serhiy-storchaka commented on Jan 2, 2013

      @serhiy-storchaka
      MemberAuthor

      A long time Tcl got support first 64-bit integers, and then arbitrary size integers. Python also supports arbitrary size integers. However Tkinter supports only C long integers. For example, on 32-bit platform:

      >>> import tkinter
      >>> t = tkinter.Tk()
      >>> t.tk.call('expr', 2**30)
      1073741824
      >>> t.tk.call('expr', 2**31)
      <wideInt object at 0x9122518>
      >>> t.tk.call('expr', 2**63)
      <bignum object at 0x9126010>

      Those <wideInt object> and <bignum object> are not usable from Python. Potentially this can cause errors in some rare circumstances.

      I'm working on a patch, but was faced with a problem. Tcl provides functions for conversions between Bignum Tcl object and mp_int, but it does not provide all functions for conversions between mp_int and bytes sequence. Which is better, add libtommath library to CPython dependencies, or implement the missing functionality manually? Or may be use haxadecimal representation for conversions?

    2. added
      type-bug
      on Jan 2, 2013
    3. serhiy-storchaka commented on Jan 3, 2013

      @serhiy-storchaka
      MemberAuthor

      Here is a patch which adds support of "wideInt" and "bignum" Tcl types.

    4. serhiy-storchaka commented on Jan 6, 2013

      @serhiy-storchaka
      MemberAuthor

      I reclassify this as enhancement until the real bug is not found.

    5. added
      type-feature
      and removed
      type-bug
      on Jan 6, 2013
    6. serhiy-storchaka commented on Aug 22, 2013

      @serhiy-storchaka
      MemberAuthor

      Patch updated.

    7. serhiy-storchaka commented on May 18, 2014

      @serhiy-storchaka
      MemberAuthor

      Patch synchronized with tip and fixed support of Tcl <8.5.

    8. serhiy-storchaka commented on Jan 31, 2015

      @serhiy-storchaka
      MemberAuthor

      Here is test failure related to this issue:

      http://buildbot.python.org/all/builders/AMD64%20Windows8%202.7/builds/156/steps/test/logs/stdio

      test test_tk failed -- Traceback (most recent call last):
        File "D:\buildarea\2.7.bolen-windows8\build\lib\lib-tk\test\test_tkinter\test_widgets.py", line 91, in test_use
          wid = parent.winfo_id()
        File "D:\buildarea\2.7.bolen-windows8\build\lib\lib-tk\Tkinter.py", line 839, in winfo_id
          self.tk.call('winfo', 'id', self._w))
      TclError: integer value too large to represent
    9. serhiy-storchaka commented on Feb 21, 2015

      @serhiy-storchaka
      MemberAuthor

      Updated patch now supports wideInt if PY_LONG_LONG is not defined or is not equal to Tcl_WideInt. getint() also now supports big integers (currently it returns ambiguous result for values outside the range of C signed int).

      As far as this issue causes random tests failures, may be it makes sense to apply the patch to maintained releases. On other hand, looks as this happens very rarely.

    10. benjaminp commented on Feb 21, 2015

      @benjaminp
      Contributor

      I'm all for fixing random test failures.

    11. 4 remaining items

    12. vstinner commented on Apr 7, 2015

      @vstinner
      Member

      test_expr_bignum() should tolerate the long type:

      http://buildbot.python.org/all/builders/x86%20Tiger%202.7/builds/3007/steps/test/logs/stdio

      ======================================================================
      FAIL: test_expr_bignum (test.test_tcl.TclTest)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/Users/db3l/buildarea/2.7.bolen-tiger/build/Lib/test/test_tcl.py", line 443, in test_expr_bignum
          self.assertIsInstance(result, type(int(result)))
      AssertionError: -2147483648L is not an instance of <type 'int'>

      In fact, I don't understand the test self.assertIsInstance(result, type(int(result))). What do you expect from type(int(x)): int or long depending on the value of x? The problem is that an intermediate result may be a long and so tcl.call('expr', ..) returns a long even if it may fit into a small int.

      I suggest to simply drop the test self.assertIsInstance(result, type(int(result))).

    13. serhiy-storchaka commented on Apr 7, 2015

      @serhiy-storchaka
      MemberAuthor

      It is important that the result is an int at least for small ints. So I prefer to keep limited test.

      •        self.assertIsInstance(result, type(int(result)))
        

      + if abs(result) < 2**31:
      + self.assertIsInstance(result, int)

    14. python-dev commented on Apr 10, 2015

      python-devmannequin
      Mannequin

      New changeset 350c78a92046 by Serhiy Storchaka in branch '2.7':
      Issue bpo-16840: Fixed Tcl test on 2.7 with Tcl 8.4.19.
      https://hg.python.org/cpython/rev/350c78a92046

    15. serhiy-storchaka commented on Apr 20, 2015

      @serhiy-storchaka
      MemberAuthor

      There is at least one buildbot that now fails to build _tkinter.

      http://buildbot.python.org/all/builders/x86%20FreeBSD%206.4%202.7/builds/2457/steps/test/logs/stdio
      building '_tkinter' extension
      gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -g -O0 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/local/include/tcl8.5 -I/usr/local/include/tk8.5 -I/usr/X11R6/include -I. -IInclude -I./Include -I/usr/local/include -I/usr/home/db3l/buildarea/2.7.bolen-freebsd/build/Include -I/usr/home/db3l/buildarea/2.7.bolen-freebsd/build -c /usr/home/db3l/buildarea/2.7.bolen-freebsd/build/Modules/_tkinter.c -o build/temp.freebsd-6.4-RELEASE-i386-2.7-pydebug/usr/home/db3l/buildarea/2.7.bolen-freebsd/build/Modules/_tkinter.o
      /usr/home/db3l/buildarea/2.7.bolen-freebsd/build/Modules/_tkinter.c:101:24: tclTomMath.h: No such file or directory

    16. python-dev commented on Apr 20, 2015

      python-devmannequin
      Mannequin

      New changeset 8ab077c22fbf by Serhiy Storchaka in branch '2.7':
      Issue bpo-16840: Turn on support of bignums only in final release of Tcl 8.5.
      https://hg.python.org/cpython/rev/8ab077c22fbf

      New changeset 7f1622478d17 by Serhiy Storchaka in branch '3.4':
      Issue bpo-16840: Turn on support of bignums only in final release of Tcl 8.5.
      https://hg.python.org/cpython/rev/7f1622478d17

      New changeset 7a7f09528866 by Serhiy Storchaka in branch 'default':
      Issue bpo-16840: Turn on support of bignums only in final release of Tcl 8.5.
      https://hg.python.org/cpython/rev/7a7f09528866

    17. serhiy-storchaka commented on Apr 21, 2015

      @serhiy-storchaka
      MemberAuthor

      This didn't help. Actually we should turn on bignum support only since 8.5.8, because tclTomMath.h was broken before. But this is not related, because tclTomMath.h is not found itself on this buildbot.

    18. serhiy-storchaka commented on Apr 21, 2015

      @serhiy-storchaka
      MemberAuthor

      Ah, we should also test full version of 8.6, because bignums was not supported in earlier alphas and betas (if I remember correctly, this buildbot uses beta version of 8.6).

      TK_VERSION_HEX packs fields in wrong order, not suitable for comparing of non-final releases. It's value for 8.6a3 is larger than 8.6.1.

      Here is a patch that adds TK_HEX_VERSION with correctly packed fields and turn off bignum support in non-final 8.6.

    19. python-dev commented on Apr 21, 2015

      python-devmannequin
      Mannequin

      New changeset 5116916e4f7f by Serhiy Storchaka in branch '2.7':
      Issue bpo-16840. Turn off bignum support in tkinter with with Tcl earlier than 8.5.8
      https://hg.python.org/cpython/rev/5116916e4f7f

    20. python-dev commented on Apr 22, 2015

      python-devmannequin
      Mannequin

      New changeset 4bf210f59ac6 by Serhiy Storchaka in branch '2.7':
      Issue bpo-16840: Skip bignum tests on minor releases where they are not supported.
      https://hg.python.org/cpython/rev/4bf210f59ac6

      New changeset 97519d85b5c8 by Serhiy Storchaka in branch '3.4':
      Issue bpo-16840. Turn off bignum support in tkinter with with Tcl earlier than 8.5.8
      https://hg.python.org/cpython/rev/97519d85b5c8

      New changeset 701b830abbf0 by Serhiy Storchaka in branch 'default':
      Issue bpo-16840. Turn off bignum support in tkinter with with Tcl earlier than 8.5.8
      https://hg.python.org/cpython/rev/701b830abbf0

    21. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    topic-tkintertype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions