[issue19803] memoryview complain ctypes byte array are not native single character

2013-12-02 Thread HCT

HCT added the comment:

I wonder why _pack_ = 1 has significant impact on the behaviour of memoryview 
if memoryview is not a sub class of ctypes structure. unless memoryview was 
specifically coded to understand ctypes structure, I don't see why _pack_ = 1 
should make any difference.

--

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-12-02 Thread Stefan Krah

Stefan Krah added the comment:

Memoryview sends a *request* to ctypes to fill in a Py_buffer struct according
to the buffer *protocol*.  IOW, memoryview knows nothing about ctypes.

For some reason ctypes fills in 'B' as the format if _pack_ is set.  I do not
know if that is intended, it could be a ctypes issue.

--

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-11-29 Thread Stefan Krah

Stefan Krah added the comment:

 class B1(ctypes.Structure):
... _fields_ = [(data, ctypes.c_uint8 * 256), ]
... _pack_ = 1 
... 
 a= B1()
 x = memoryview(a)
 x.format
'B'

In the first case the format is 'B', in the second case the
format is:

 x = memoryview(b)
 x.format
'T{(256)B:data:}'

While the latter is probably a valid PEP 3118 format, it's
not implemented anywhere outside ctypes See #3132.

--
components: +Interpreter Core -Library (Lib), ctypes
resolution:  - duplicate
stage:  - committed/rejected
status: open - closed
superseder:  - implement PEP 3118 struct changes
type:  - behavior

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-11-27 Thread Stefan Krah

Stefan Krah added the comment:

Memoryview currently only knows the types from the struct module.

--
nosy: +skrah

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-11-27 Thread HCT

HCT added the comment:

this seems to disagree with the statement of Memoryview currently only knows 
the types from the struct module.

why is memoryview aware of _pack_, a implementation detail of ctypes 
structures. is memoryview a collection of implementation for different types or 
a unique type on its own?


 import ctypes
 class B1(ctypes.Structure):
... _fields_ = [( data, c_uint8 * 256 ), ]
... _pack_ = 1
...
 class B2(ctypes.Structure):
... _fields_ = [( data, c_uint8 * 256 ), ]
...

 a = B1()
 b = B2()
 memoryview( a ).cast( 'B' )
memory at 0x01FFCDC0
 memoryview( b ).cast( 'B' )
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'


--

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-11-27 Thread HCT

HCT added the comment:

more examples (using 64-bit integer vs 8-bit integer in the above example) to 
show that ctypes aren't being translated for memoryview properly. _pack_ is the 
only way to make memoryview handle ctypes properly


 import ctypes
 class B1(ctypes.Structure):
... _fields_ = [( data, ctypes.c_uint64 * 256 ), ]
... _pack_ = 1
...
 class B2(ctypes.Structure):
... _fields_ = [( data, ctypes.c_uint64 * 256 ), ]
...

 a = B1()
 b = B2()
 memoryview( a ).cast( 'B' )
memory at 0x01FFB030
 memoryview( b ).cast( 'B' )
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'


--

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



[issue19803] memoryview complain ctypes byte array are not native single character

2013-11-26 Thread HCT

New submission from HCT:

I'm trying to create ctypes buffer to be used back and forth with C libraries, 
but I keep getting errors. I need to slice the buffer to cut out different 
pieces to work on, so I try to get a memoryview of the buffer. does the error 
message imply that c_ubyte, c_uint8, c_byte and c_char are not native single 
character types?

 memoryview(c_ubyte()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview((c_ubyte*1024)()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview(c_uint8()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview((c_uint8*1024)()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview((c_byte*1024)()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview((c_char*1024)()).cast('B')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: memoryview: source format must be a native single character format 
prefixed with an optional '@'
 memoryview((c_char*1024)())[0]
Traceback (most recent call last):
  File stdin, line 1, in module
NotImplementedError: memoryview: unsupported format (1024)c
 memoryview((c_byte*1024)())[0]
Traceback (most recent call last):
  File stdin, line 1, in module
NotImplementedError: memoryview: unsupported format (1024)b
 memoryview((c_ubyte*1024)())[0]
Traceback (most recent call last):
  File stdin, line 1, in module
NotImplementedError: memoryview: unsupported format (1024)B
 memoryview((c_uint8*1024)())[0]
Traceback (most recent call last):
  File stdin, line 1, in module
NotImplementedError: memoryview: unsupported format (1024)B


--
components: Library (Lib), ctypes
messages: 204536
nosy: hct
priority: normal
severity: normal
status: open
title: memoryview complain ctypes byte array are not native single character
versions: Python 3.3

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