My question is similar to this one on
StackExchange but in the pure Python mode. First, a couple disclaimers, this is my first time using Cython, and I'm working off of others' work (PyAV). which constrains me to use the pure Python mode.
My understanding is in Cython, I can do something like
cdef char[::1] view = <char[:size]>incoming_p_void
to convert a void C pointer, which points to an array of a known size, to a memoryview of the designated data type (char in this case).
How do you do the same in the pure Python mode?
Here is my (failing) code in progress (the src_view line is the contentious line):
@cython.cclass
class Packet(Buffer):
@cython.cfunc
@cython.locals(size=cython.size_t, pal=cython.p_void, dst_view = cython.char[::1])
@cython.returns(cython.char[:])
def _get_palette(self):
pal = lib.av_packet_get_side_data(self.ptr, lib.AV_PKT_DATA_PALETTE, cython.address(size))
if pal:
result = np.empty(size, dtype=np.uint8)
dst_view = result
src_view = cython.declare(cython.char[:size], cython.cast(cython.p_char,pal))
dst_view[:] = src_view
return result
else:
return np.empty(0, dtype=np.uint8)
When compiled, I get the error that I pasted down below. If anybody here could help me sort this out, I'd be greatly appreciated.
Thanks,
Kesh
[1/1] Cythonizing av/packet.py
Error compiling Cython file:
------------------------------------------------------------
...
pal = lib.av_packet_get_side_data(self.ptr, lib.AV_PKT_DATA_PALETTE, cython.address(size))
if pal:
result = np.empty(size, dtype=np.uint8)
dst_view = result
src_view = cython.declare(cython.char[:size], cython.cast(cython.p_char,pal))
^
------------------------------------------------------------
av/packet.py:252:49: Unknown type
Error compiling Cython file:
------------------------------------------------------------
...
pal = lib.av_packet_get_side_data(self.ptr, lib.AV_PKT_DATA_PALETTE, cython.address(size))
if pal:
result = np.empty(size, dtype=np.uint8)
dst_view = result
src_view = cython.declare(cython.char[:size], cython.cast(cython.p_char,pal))
^
------------------------------------------------------------
av/packet.py:252:29: 'declare' not a valid cython language construct
Error compiling Cython file:
------------------------------------------------------------
...
pal = lib.av_packet_get_side_data(self.ptr, lib.AV_PKT_DATA_PALETTE, cython.address(size))
if pal:
result = np.empty(size, dtype=np.uint8)
dst_view = result
src_view = cython.declare(cython.char[:size], cython.cast(cython.p_char,pal))
^
------------------------------------------------------------
av/packet.py:252:29: 'declare' not a valid cython attribute or is being used incorrectly
Error compiling Cython file:
------------------------------------------------------------
...
pal = lib.av_packet_get_side_data(self.ptr, lib.AV_PKT_DATA_PALETTE, cython.address(size))
if pal:
result = np.empty(size, dtype=np.uint8)
dst_view = result
src_view = cython.declare(cython.char[:size], cython.cast(cython.p_char,pal))
^
------------------------------------------------------------
av/packet.py:252:37: Compiler crash in AnalyseExpressionsTransform