Skip to content

Fix misalignment in fastsearch_memchr_1char #63736

Closed

Description

@andreas-schwab
BPO 19537
Nosy @loewis, @pitrou, @vstinner, @larryhastings, @skrah, @serhiy-storchaka, @andreas-schwab
Files
  • pyasciiobject-align.patch: Add explicit padding to PyASCIIObject
  • 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 = <Date 2014-03-23.21:57:20.154>
    created_at = <Date 2013-11-09.16:32:08.481>
    labels = ['interpreter-core', 'type-bug']
    title = 'Fix misalignment in fastsearch_memchr_1char'
    updated_at = <Date 2014-03-24.22:08:05.478>
    user = 'https://github.com/andreas-schwab'

    bugs.python.org fields:

    activity = <Date 2014-03-24.22:08:05.478>
    actor = 'BreamoreBoy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-03-23.21:57:20.154>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2013-11-09.16:32:08.481>
    creator = 'schwab'
    dependencies = []
    files = ['34589']
    hgrepos = []
    issue_num = 19537
    keywords = ['patch']
    message_count = 28.0
    messages = ['202487', '202537', '202541', '202551', '202554', '202573', '204358', '204367', '204403', '206249', '206250', '206253', '206254', '206285', '206311', '214603', '214634', '214635', '214639', '214640', '214651', '214652', '214673', '214674', '214675', '214728', '214735', '214745']
    nosy_count = 9.0
    nosy_names = ['loewis', 'pitrou', 'vstinner', 'larry', 'skrah', 'BreamoreBoy', 'python-dev', 'serhiy.storchaka', 'schwab']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue19537'
    versions = ['Python 3.3', 'Python 3.4']

    Activity

    1. andreas-schwab commented on Nov 9, 2013

      andreas-schwabmannequin
      MannequinAuthor

      sizeof(foo) is never a good approximation for the alignment of foo

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Nov 9, 2013
    3. serhiy-storchaka commented on Nov 10, 2013

      @serhiy-storchaka
      Member

      Current code assumes that PyUnicode_DATA() is aligned to PyUnicode_KIND() bytes. If this is not true on some platform it will be easer to add a padding than rewrite a code. A lot of code depends on this assumption. See also bpo-14422.

      I afraid that proposed patch may slow down a search.

    4. pitrou commented on Nov 10, 2013

      @pitrou
      Member

      I don't understand in which concrete situation the current code could be wrong. The start of the unicode string should always be aligned, due to how unicode objects are allocated.

    5. andreas-schwab commented on Nov 10, 2013

      andreas-schwabmannequin
      MannequinAuthor

      (gdb) p sizeof(PyASCIIObject)
      $1 = 22

    6. skrah commented on Nov 10, 2013

      skrahmannequin
      Mannequin

      Andreas Schwab <report@bugs.python.org> wrote:

      (gdb) p sizeof(PyASCIIObject)
      $1 = 22

      m68k again? ;)

    7. andreas-schwab commented on Nov 10, 2013

      andreas-schwabmannequin
      MannequinAuthor

      There is nothing wrong with that.

    8. skrah commented on Nov 25, 2013

      skrahmannequin
      Mannequin

      (gdb) p sizeof(PyASCIIObject)
      $1 = 22

      If the only issue is that the size should be 24 instead of 22,
      could we perhaps add an unused uint16_t to the struct just
      for this architecture?

    9. serhiy-storchaka commented on Nov 25, 2013

      @serhiy-storchaka
      Member

      What is sizeof(PyUnicodeObject)?

    10. andreas-schwab commented on Nov 25, 2013

      andreas-schwabmannequin
      MannequinAuthor

      (gdb) p sizeof(PyUnicodeObject)
      $1 = 38

    11. serhiy-storchaka commented on Dec 15, 2013

      @serhiy-storchaka
      Member

      Antoine, if sizeof(PyUnicodeObject) is 38, the start of UCS4 unicode string is not aligned. This should be fixed.

    12. pitrou commented on Dec 15, 2013

      @pitrou
      Member

      Antoine, if sizeof(PyUnicodeObject) is 38, the start of UCS4 unicode
      string is not aligned. This should be fixed.

      Probably. Does anyone want to propose a patch?

    13. andreas-schwab commented on Dec 15, 2013

      andreas-schwabmannequin
      MannequinAuthor

      How about adding explicit padding to the bitfield in PyASCIIObject?

    14. pitrou commented on Dec 15, 2013

      @pitrou
      Member

      How about adding explicit padding to the bitfield in PyASCIIObject?

      That sounds ok to me, but it must be explicitly for 68k (or use a
      sufficiently smart scheme not to affect already aligned architectures).

    15. 2 remaining items

    16. andreas-schwab commented on Mar 23, 2014

      andreas-schwabmannequin
      MannequinAuthor

      The attached patch has been tested on {i586,x86_64,ppc,ppc64,ppc64le,armv6hl,armv7hl,aarch64,m68k}-suse-linux.

    17. pitrou commented on Mar 23, 2014

      @pitrou
      Member

      Are unnamed struct fields actually valid C?

    18. skrah commented on Mar 23, 2014

      skrahmannequin
      Mannequin

      Yes, §6.7.2.1:

      A bit-field declaration with no declarator, but only a colon and a width, indicates an unnamed bit-field.

      With a footnote:

      1. An unnamed bit-field structure member is useful for padding to conform to externally imposed layouts.

      Unnamed struct members are valid, too:

      There may be unnamed padding at the end of a structure or union.

    19. python-dev commented on Mar 23, 2014

      python-devmannequin
      Mannequin

      New changeset 004ae1472a43 by Antoine Pitrou in branch '3.4':
      Issue bpo-19537: Fix PyUnicode_DATA() alignment under m68k. Patch by Andreas Schwab.
      http://hg.python.org/cpython/rev/004ae1472a43

      New changeset 0128b25068de by Antoine Pitrou in branch 'default':
      Issue bpo-19537: Fix PyUnicode_DATA() alignment under m68k. Patch by Andreas Schwab.
      http://hg.python.org/cpython/rev/0128b25068de

    20. pitrou commented on Mar 23, 2014

      @pitrou
      Member

      Ok, I've committed the patch, then. Thank you, Andreas.

    21. vstinner commented on Mar 23, 2014

      @vstinner
      Member

      What is the size of the PyASCIIObject on x86/x64 with and without the
      patch? GCC and Visual Studio provide attributes to align structures.

    22. pitrou commented on Mar 23, 2014

      @pitrou
      Member

      What is the size of the PyASCIIObject on x86/x64 with and without the
      patch?

      Haven't tried on x86, but on x86-64 it's the same. If it changes it will
      probably get detected by the sys.getsizeof() tests.

    23. vstinner commented on Mar 24, 2014

      @vstinner
      Member

      2014-03-24 0:30 GMT+01:00 Antoine Pitrou <report@bugs.python.org>:

      > What is the size of the PyASCIIObject on x86/x64 with and without the
      > patch?

      Haven't tried on x86, but on x86-64 it's the same. If it changes it will
      probably get detected by the sys.getsizeof() tests.

      test_sys has been modified:

      •    asciifields = "nnbP"
        

      + asciifields = "nn4bP"

      It would like to know if objects are bigger with the change or not.

    24. pitrou commented on Mar 24, 2014

      @pitrou
      Member

      Look at the commits, not the patch.

    25. vstinner commented on Mar 24, 2014

      @vstinner
      Member

      Look at the commits, not the patch.

      Ah! You wrote "Ok, I've committed the patch". Ok, your commit is fine. I would prefered a named field (called "padding"), but it's fine ;-)

    26. BreamoreBoy commented on Mar 24, 2014

      BreamoreBoymannequin
      Mannequin

      Martin, Larry msg214639 states "Fix PyUnicode_DATA() alignment under m68k.", your comments please.

    27. skrah commented on Mar 24, 2014

      skrahmannequin
      Mannequin

      Mark Lawrence, stop playing off committers against each other. This is
      outright trolling.

    28. BreamoreBoy commented on Mar 24, 2014

      BreamoreBoymannequin
      Mannequin

      Please do not threaten me, I've been told that I'm to be ignored, and I now observe that committers seem to be sneaking patches into the source control system when the platform is unsupported. I'll stop placing comments on appropriate issues if and only if I get satisfactory answers to my questions, which so far are conspicuous by their absence.

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

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions