GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bitfield layout wrong in ctypes · Issue #84039 · python/cpython

bitfield layout wrong in ctypes #84039

New issue
Copy link
New issue
Copy link
Closed
Closed
bitfield layout wrong in ctypes#84039
Copy link
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

thesamprice
mannequin
opened on Mar 5, 2020
Issue body actions
BPO 39858
Nosy @thesamprice
Files
  • ctypeSizeTest.py: Example test code
  • 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 2020-03-05.05:22:35.966>
    labels = ['3.8', 'ctypes', 'type-bug', '3.7', '3.9']
    title = 'bitfield layout wrong in ctypes'
    updated_at = <Date 2020-03-05.15:57:41.683>
    user = 'https://github.com/thesamprice'

    bugs.python.org fields:

    activity = <Date 2020-03-05.15:57:41.683>
    actor = 'thesamprice'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['ctypes']
    creation = <Date 2020-03-05.05:22:35.966>
    creator = 'thesamprice'
    dependencies = []
    files = ['48954']
    hgrepos = []
    issue_num = 39858
    keywords = []
    message_count = 2.0
    messages = ['363417', '363438']
    nosy_count = 1.0
    nosy_names = ['thesamprice']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39858'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. thesamprice commented on Mar 5, 2020

      @thesamprice
      thesampricemannequin
      on Mar 5, 2020
      MannequinAuthor
      More actions

      if 8 1 byte fields are included in a ctype field, it allows an extra byte to be included in the packing when there is no room left for the next field.

      If I put the bitfields in a child structure then I get expected results.

      In [35]: run ctypeSizeTest.py
      Size is 4 Expected 3
      0 0x10000 a0
      0 0x10001 a1
      0 0x10002 a2
      0 0x10003 a3
      0 0x10004 a4
      0 0x10005 a5
      0 0x10006 a6
      0 0x10007 a7
      0 0x40008 b0 <- Expected to be at offset 1, not 0.
      2 0xc0000 b1 <- Expected to be at offset 1, not 2
      Size is 3 Expected 3
      0 0x1 a
      1 0x40000 b0
      1 0xc0004 b1

    2. thesamprice
      added
      topic-ctypes
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Mar 5, 2020
    3. thesamprice commented on Mar 5, 2020

      @thesamprice
      thesampricemannequin
      on Mar 5, 2020
      MannequinAuthor
      More actions

      Does not happen on windows.

      Error is in cfield.c

      #ifndef MS_WIN32
          } else if (bitsize /* this is a bitfield request */
              && *pfield_size /* we have a bitfield open */
              && dict->size * 8 >= *pfield_size
              && (*pbitofs + bitsize) <= dict->size * 8) {
              /* expand bit field */
              fieldtype = EXPAND_BITFIELD;
      #endif
      

      Specifically dict->size * 8 >= *pfield_size
      if *bitofs == *pfield_size then the current field is filled, and expanding the bitfield should not be done.

      Consider adding this *pfield_size != *bitofs
      #ifndef MS_WIN32
          } else if (bitsize /* this is a bitfield request */
              && *pfield_size /* we have a bitfield open */
              && *pfield_size != *pbitofs /* Current field has been filled, start new one */
              && dict->size * 8 >= *pfield_size
              && (*pbitofs + bitsize) <= dict->size * 8) {
              /* expand bit field */
              fieldtype = EXPAND_BITFIELD;
      #endif
    4. thesamprice
      added
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      on Mar 5, 2020
    5. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    6. serhiy-storchaka
      added this to Ctypes issueson Jan 1, 2024
    7. encukou commented on Sep 10, 2024

      @encukou
      encukou
      on Sep 10, 2024
      Member
      More actions

      Fixed in #97702, the reproducer is now part of tests (as the Example_gh_84039* classes)

    8. encukou
      closed this as completedon Sep 10, 2024
    9. github-project-automation
      moved this to Done in Ctypes issueson Sep 10, 2024
    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

      3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      • Ctypes issues
        Status
        Done
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.