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 — Wrong size of c_ulong/c_ulonglong in Linux · Issue #108907 · python/cpython

Wrong size of c_ulong/c_ulonglong in Linux #108907

New issue
Copy link
New issue
Copy link
Closed
Closed
Wrong size of c_ulong/c_ulonglong in Linux#108907
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@dudekw
dudekw
opened on Sep 5, 2023
Issue body actions

Bug report

Bug description:

Attribute _type_ of c_ulong returns L, which is correct following the format characters documentation; however, the documentation says it has 4 bytes size, but sizeof(c_ulong) returns 8 bytes.

>>> sizeof(c_ulong)
8
>>> c_ulong._type_
'L'

Also c_ulonglong is automatically casted to c_ulong:

t5=c_ulonglong(200000000000000000000000000000000000)
>>> type(t5)
<class 'ctypes.c_ulong'>

, thus if c_ulong will have 4 bytes, will be there available a type of 8 bytes size?

CPython versions tested on:

3.8

Operating systems tested on:

Linux

Linked PRs

  • gh-108907: ctypes: Document _type_ codes #145837
  • [3.14] gh-108907: ctypes: Document _type_ codes (GH-145837) #146328

Activity

  1. dudekw
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 5, 2023
  2. serhiy-storchaka commented on Sep 5, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Sep 5, 2023
    Member
    More actions

    The ‘Standard size’ column refers to the size of the packed value in bytes when using standard size; that is, when the format string starts with one of '<', '>', '!' or '='. When using native size, the size of the packed value is platform-dependent.

  3. terryjreedy
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Sep 5, 2023
  4. terryjreedy commented on Sep 5, 2023

    @terryjreedy
    terryjreedy
    on Sep 5, 2023
    Member
    More actions

    _type_ is apparently an attribute of each fundamental data type but unlike value, not of the base class _SimpleCData. Hence it is undocumented in this section. I think it should be, with a mention that the 'types' are 1 char strings from struct Format Characters(I am assuming this) -- with 'native' rather than 'standard' size implied. (I have no idea whether the above has always been true or if type is an addition.)

    _type_ is only mentioned in Arrays and Pointers as "Specifies the type ..." with no indication as to what such specification consists of.

    Reacted by Ronald Oussoren
  5. terryjreedy
    added
    topic-ctypes
    on Sep 5, 2023
  6. ronaldoussoren commented on Sep 6, 2023

    @ronaldoussoren
    ronaldoussoren
    on Sep 6, 2023
    Contributor
    More actions

    IMHO there is no bug here, other than the documentation issue mentioned by @terryjreedy.

    c_ulong and c_ulonglong are documented as being representations of the C types unsigned long and unsigned long long. As such they'll have the size of associated with those types. 64-bit Linux systems generally use a LP64 model where unsigned long and unsigned long long are both 64-bit bit integers, and hence c_ulong and c_ulonglong are the same type. On 32-bit systems unsigned long is generally a 32-bit quantity, and hence c_ulong and c_ulonglong won't. be the same type there.

  7. serhiy-storchaka
    added this to Ctypes issueson Jan 1, 2024
  8. encukou
    added a commit that references this issue on Mar 23, 2026

    gh-108907: ctypes: Document _type_ codes (GH-145837)

    1114d7f
  9. miss-islington
    added a commit that references this issue on Mar 23, 2026

    pythongh-108907: ctypes: Document _type_ codes (pythonGH-145837)

    5cacbb1
  10. encukou
    added a commit that references this issue on Mar 23, 2026

    [3.14] gh-108907: ctypes: Document _type_ codes (GH-145837) (GH-146328)

    f883bbd
  11. encukou commented on Mar 23, 2026

    @encukou
    encukou
    on Mar 23, 2026
    Member
    More actions

    Docs are updated.

    the 'types' are 1 char strings from struct Format Characters(I am assuming this) -- with 'native' rather than 'standard' size implied. (I have no idea whether the above has always been true or if type is an addition.)

    I've kept these -- and array -- separate. There are some differences, but if you're reading about one individual module it's better to get the full table than “X but with Y rather than Z”.

  12. encukou
    closed this as completedon Mar 23, 2026
  13. github-project-automation
    moved this to Done in Ctypes issueson Mar 23, 2026
  14. CuriousLearner
    added a commit that references this issue on Mar 23, 2026

    Merge branch 'main' of github.com:python/cpython into fix-pythongh-13…

    3e05fa3
  15. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-108907: ctypes: Document _type_ codes (pythonGH-145837)

    7383377
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

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-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.