[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2012-07-18 Thread Meador Inge

Meador Inge mead...@gmail.com added the comment:

I am closing this issue in favor of issue6493.  This patch attached to this 
issue is incorrect.  The proposed definition of BIT_MASK allows for undefined 
behavior when the number of bits shifted is 64 for a uint64.  The patch in 
issue6493 handles this case correctly.

--
nosy: +meador.inge
resolution:  - duplicate
stage: patch review - committed/rejected
status: open - closed
superseder:  - Can not set value for structure members larger than 32 bits

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-07-21 Thread Vlad Riscutia

Vlad Riscutia riscutiav...@gmail.com added the comment:

Ping? This also fixes 6493 (I believe in a cleaner way)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Vlad Riscutia

Vlad Riscutia riscutiav...@gmail.com added the comment:

Changing title and type to better reflect issue.

On Windows MSVC build, ctypes is not correctly setting bitfields backed by 64 
bit integers if specifying custom width. Simple repro:

from ctypes import *

class X(Structure):
_fields_ = [(a, c_ulonglong, 16),
(b, c_ulonglong, 32),
(c, c_ulonglong, 16)]
s = X()
s.b = 1

print(s.b) # this prints 0

Whenever field width goes over 32 bits, setting or getting value of the field 
in cfield.c will only look at last (actual size - 32) bits of the field. So 
if we have a field of 34 bits, only least significant 2 bits will be operated 
on. The above repro results in an (actual size - 32) = 0 bits so nothing is 
getting set with the assignement.

This is not caught in unit test package because we have only this in 
test_bitfields.py:

def test_ulonglong(self):
class X(Structure):
_fields_ = [(a, c_ulonglong, 1),
(b, c_ulonglong, 62),
(c, c_ulonglong, 1)]

self.assertEqual(sizeof(X), sizeof(c_longlong))
x = X()
self.assertEqual((x.a, x.b, x.c), (0, 0, 0))
x.a, x.b, x.c = 7, 7, 7
self.assertEqual((x.a, x.b, x.c), (1, 7, 1))

For 62 bit width, we will actually operate on last 30 bits but this test passes 
as 7 fits in those bits. If we would actually try to set it to 
0x3FFF, result will be different than expected (0x3FFF).

I will look into extending UT package with some tests that set full range of 
bits and check if they are actually being set correctly.

This issue reproes with latest bits but only on Windows. Root cause seems to be 
BIT_MASK macro in cfield.c which is ifdef-ed to something different on Windows. 
I patched on my machine by removing the special treatment:

@@ -429,12 +429,7 @@
 #define LOW_BIT(x)  ((x)  0x)
 #define NUM_BITS(x) ((x)  16)
 
-/* This seems nore a compiler issue than a Windows/non-Windows one */
-#ifdef MS_WIN32
-#  define BIT_MASK(size) ((1  NUM_BITS(size))-1)
-#else
-#  define BIT_MASK(size) ((1LL  NUM_BITS(size))-1)
-#endif
+#define BIT_MASK(size) ((1LL  NUM_BITS(size))-1)
 
 /* This macro CHANGES the first parameter IN PLACE. For proper sign handling,
we must first shift left, then right.



Unittests still pass with this in place and now fields are handled correctly 
though I don't know why this was put in in the first place. Looking at file 
history it seems it was there from the start (from 2006). Could it be that it 
was addressing some MSVC bug which got fixed in the meantime? Things seem to be 
building and working fine now when using 1LL for shift.

Also related to this I have doubts about the SWAP_8 macro which is similarly 
changed for MSVC, also in cfield.c.

I am only able to build 32 bit version so I can't say whether this was put in 
place due to some x64 issue, maybe someone can check behavior on x64 build. If 
that's the case, maybe #ifdef should take that into account.

--
nosy: +vladris
title: support read/write c_ulonglong type bitfield structures - ctypes is not 
correctly handling bitfields backed by 64 bit integers on Windows
type: feature request - behavior
versions: +Python 3.3 -Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

Vlad, thanks for delving into this. Your two header changes are contradictory. 
If this is a feature request, then it is 3.3 only. If this is a behavior (bug) 
issue, then 3.2 should be included ;-). 'higstar's second comment indicates 
'feature', but I am not sure what 'integer field means in this context'. I am 
guessing that UT = 'unittest'

Higstar, I see buried in your 3rd message the reference to Windows and 2.6. 
Please specify OS and version in initial messages.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Vlad Riscutia

Vlad Riscutia riscutiav...@gmail.com added the comment:

Terry, I am kind of new to this so I might not have marked header correctly. 
Please feel free to fix it.

This is 100% bug not feature request. Initial message was confusing because 
highstar thought Python has such bitfields as readonly and was asking for a 
feature to make them read-write. That is not the case, behavior is caused by a 
bug. By UT I mean unittest.

I reproed this on 64bit Windows 7 on latest sources with x32 build (as I said, 
I don't have x64 build).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
versions: +Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Vlad Riscutia

Vlad Riscutia riscutiav...@gmail.com added the comment:

Attached is addition to unittests which repro the issue. They will currently 
pass on Linux but fail on Windows.

--
keywords: +patch
Added file: http://bugs.python.org/file22447/issue6068_unittest.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread higstar

higstar adr...@higstar.com added the comment:

Issue was originally found on do sp2 on Python 2.6.
Thanks Vlad, this rendered ctypes useless for my purposes, had to mask and
shift myself.
On Jun 25, 2011 8:32 AM, Vlad Riscutia rep...@bugs.python.org wrote:

 Vlad Riscutia riscutiav...@gmail.com added the comment:

 Attached is addition to unittests which repro the issue. They will
currently pass on Linux but fail on Windows.

 --
 keywords: +patch
 Added file: http://bugs.python.org/file22447/issue6068_unittest.diff

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue6068
 ___

--
Added file: http://bugs.python.org/file22448/unnamed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___pIssue was originally found on do sp2 on Python 2.6.br
Thanks Vlad, this rendered ctypes useless for my purposes, had to mask and 
shift myself./p
div class=gmail_quoteOn Jun 25, 2011 8:32 AM, quot;Vlad Riscutiaquot; 
lt;a href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt; 
wrote:br type=attributiongt; brgt; Vlad Riscutia lt;a 
href=mailto:riscutiav...@gmail.com;riscutiav...@gmail.com/agt; added the 
comment:br
gt; brgt; Attached is addition to unittests which repro the issue. They 
will currently pass on Linux but fail on Windows.brgt; brgt; 
--brgt; keywords: +patchbrgt; Added file: a 
href=http://bugs.python.org/file22447/issue6068_unittest.diff;http://bugs.python.org/file22447/issue6068_unittest.diff/abr
gt; brgt; ___brgt; Python tracker 
lt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;brgt; 
lt;a 
href=http://bugs.python.org/issue6068;http://bugs.python.org/issue6068/agt;br
gt; ___br/div
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Santoso Wijaya

Changes by Santoso Wijaya santoso.wij...@gmail.com:


--
nosy: +santa4nt

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Santoso Wijaya

Santoso Wijaya santoso.wij...@gmail.com added the comment:

FWIW, I tested the patch on a 64-bit Python build and test_ctypes passes with 
the new unittest added.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Adding our windows committers to nosy to see if this can be committed.

--
nosy: +brian.curtin, r.david.murray, tim.golden
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6068] ctypes is not correctly handling bitfields backed by 64 bit integers on Windows

2011-06-24 Thread Vlad Riscutia

Vlad Riscutia riscutiav...@gmail.com added the comment:

Attaching patch as previous attachment is only unittest. I included change to 
SWAP_8 macro also as it looks like same issue and it will probably popup later.

--
Added file: http://bugs.python.org/file22451/issue6068_patch.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6068
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com