[pypy-issue] [issue1356] Casting a str into a ctype pointer fails

Vincent Pelletier tracker at bugs.pypy.org
Mon Dec 31 23:16:21 CET 2012

New submission from Vincent Pelletier <plr.vincent at gmail.com>:

import ctypes
ctypes.cast('\x01\x02\x03\x04', ctypes.POINTER(ctypes.c_char))

The actual use-case for this is a (dirty) attempt at reversing byte order 2-by-2 in a stream when 
on a little endian host:
ctypes.cast('\x01\x02\x03\x04', ctypes.POINTER(ctypes.c_ushort))
The idea is to be faster than repeatedly calling struct.unpack('>H', read(2)).

messages: 5116
nosy: pypy-issue, vpelletier
priority: bug
release: 2.0
status: unread
title: Casting a str into a ctype pointer fails

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list