homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: c_uint32 bitfields break structures
Type: behavior Stage:
Components: ctypes Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Rony Batista, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2015年05月26日 19:02 by Rony Batista, last changed 2022年04月11日 14:58 by admin.

Files
File name Uploaded Description Edit
ctypesBug.py Rony Batista, 2015年05月26日 19:06
Messages (5)
msg244125 - (view) Author: Rony Batista (Rony Batista) Date: 2015年05月26日 19:02
ctypes Structures with c_uint32 bitfields have strange behaviour on OS X.
In the attached code when the field "number" is set, it changes the whole 32 bits, even thou its meant to be 23 bits.
The behavior is unexpected in:
OS X: Python 2.7.9
The behavior is as expected in the following environments:
Windows: python 2.7.9
Ubuntu: python 2.7.6
msg244126 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2015年05月26日 19:04
You forgot to actually attach the code.
msg244127 - (view) Author: Rony Batista (Rony Batista) Date: 2015年05月26日 19:06
Silly me, Heres the code.
msg244132 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015年05月26日 20:22
Without diving into the details of your test program, I get the same results on a 64-bit Debian Python 2.7.9 as with a 64-bit OS X 2.7.10:
c_uint32 TESTS:
Class Name		exponent 	number 	Sign 	float 				binary repr
IEEE754Float_u ('-0x7b', '0xbeb2aL', 0L, 69.95930480957031, ['0x42', '0x8b', '0xeb', '0x2a'])
IEEE754Float_u ('-0x7b', '0xbeb2aL', 0L, 69.95930480957031, ['0x42', '0x8b', '0xeb', '0x2a'])
AN575Float_uint ('0x0', '0xbeb2a', 0L, 1.094551427887186e-39, ['0x0', '0xb', '0xeb', '0x2a'])
AN575Float_uint ('0x0', '0xbeb2a', 0L, 1.094551427887186e-39, ['0x0', '0xb', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 0L, 1.094551427887186e-39, ['0x85', '0xb', '0xeb', '0x2a'])
IEEE754Float_u ('-0x7b', '0xbeb2aL', 1L, -69.95930480957031, ['0xc2', '0x8b', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 1L, 1.094551427887186e-39, ['0x85', '0x8b', '0xeb', '0x2a'])
But using the same OS X 2.7.10 in 32-bit mode, I get:
c_uint32 TESTS:
Class Name		exponent 	number 	Sign 	float 				binary repr
IEEE754Float_u ('-0x7b', '0xbeb2aL', 0L, 69.95930480957031, ['0x42', '0x8b', '0xeb', '0x2a'])
IEEE754Float_u ('-0x7b', '0xbeb2aL', 0L, 69.95930480957031, ['0x42', '0x8b', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 0L, 69.95930480957031, ['0x85', '0xb', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 0L, 69.95930480957031, ['0x85', '0xb', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 0L, 69.95930480957031, ['0x85', '0xb', '0xeb', '0x2a'])
IEEE754Float_u ('-0x7b', '0xbeb2aL', 1L, -69.95930480957031, ['0xc2', '0x8b', '0xeb', '0x2a'])
AN575Float_uint ('-0x7b', '0xbeb2a', 1L, -69.95930480957031, ['0x85', '0x8b', '0xeb', '0x2a'])
msg244223 - (view) Author: Rony Batista (Rony Batista) Date: 2015年05月27日 22:57
Well, looks like the issue is with 64 bit mode then.
For the first 5 cases the right answer is 69.95930480957031, and for the last 2 its -69.95930480957031. The results for the 32 bit mode are all correct.
History
Date User Action Args
2022年04月11日 14:58:17adminsetgithub: 68478
2015年05月27日 22:57:25Rony Batistasetmessages: + msg244223
2015年05月26日 20:22:05ned.deilysetnosy: + ned.deily
messages: + msg244132
2015年05月26日 19:06:18Rony Batistasetfiles: + ctypesBug.py

messages: + msg244127
2015年05月26日 19:04:35ronaldoussorensetnosy: + ronaldoussoren
messages: + msg244126
2015年05月26日 19:02:48Rony Batistacreate

AltStyle によって変換されたページ (->オリジナル) /