Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use inline function in Cython [closed]

I am new in Cython and I have a problem compiling an inline function. The simplified code is:

cdef inline REG8(ulong addr):
   (<volatile_uchar_ptr *>(addr))[0]

I am trying to use the inline function inside a Python method:

def test(self):
    REG8(addr) = 0x08                         # ==> Error: "Cannot assign or delete this".
    (<volatile_uchar_ptr *>(addr))[0] = 0x08  # ==> OK. 

When I use the inline function REG8(), I get the compiler error: Cannot assign or delete this. However, the inserted code will work. I have no clue what is wrong here and will appreciate any help.

like image 365
Reza Abtin Avatar asked Jan 02 '26 00:01

Reza Abtin


1 Answers

You missed a [0]:

REG8(addr)[0] = 0x08

You were assigning to a function call, not the value it points to.

like image 138
Veedrac Avatar answered Jan 03 '26 14:01

Veedrac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!