Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-126937: ctypes: fix TypeError when a field's size is >65535 bytes#126938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
19625671900cf52bd972bd2954cd0d21229d8a6f0816bfb447402a8f8994ad0db171e07bc0cebcd8c011a3bd1715e8aec07d3bb10946f26119c1b3bdcf97f203bc32bf61faa6File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix :exc:`TypeError` when a :class:`ctypes.Structure` has a field size | ||
| that doesn't fit into an unsigned 16-bit integer. | ||
| Instead, the maximum number of *bits* is :data:`sys.maxsize`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -292,7 +292,7 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct | ||
| if (!tmp){ | ||
| goto error; | ||
| } | ||
| Py_ssize_t total_align = PyLong_AsInt(tmp); | ||
| Py_ssize_t total_align = PyLong_AsSsize_t(tmp); | ||
| Py_DECREF(tmp); | ||
| if (total_align < 0){ | ||
| if (!PyErr_Occurred()){ | ||
| @@ -306,7 +306,7 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct | ||
| if (!tmp){ | ||
| goto error; | ||
| } | ||
| Py_ssize_t total_size = PyLong_AsInt(tmp); | ||
| Py_ssize_t total_size = PyLong_AsSsize_t(tmp); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was a reason for using Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was an accident -- my mistake. | ||
| Py_DECREF(tmp); | ||
| if (total_size < 0){ | ||
| if (!PyErr_Occurred()){ | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be guaranteed? What if
bit_size_objis not None and is not an int?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can.
The implementation is split between internal Python code in
ctypes._layout, and C code here. They are currently tightly coupled. The assert also verifies the Python part.