Getting the target memory address of a memory range via python / ctypes

I am creating a very simple (coverage) unittest for a (hardware) C interface in python.

The function of this C interface needs memory addresses as it is directly related to memory.

The function prototype is:

void function( ulong startAddress, ulong endAddress, ulong curAddress, nofPaddingElements )

      

The start address, endAddress and curAddress are basically the memory addresses of the array structures.

On the internet (and stackoverflow ;-)) I found links that if I want to do something with ctypes this is what I use.

For startAddress and curAddress, one can follow http://starship.python.net/crew/theller/ctypes/tutorial.html#arrays and http://starship.python.net/crew/theller/ctypes/tutorial.html#pointers . to get a pointer to the address of the first record and a pointer to the address of the current record.

But the endAddress problem is the problem.
This is the real end address of the memory area to be allocated by the function.
Thus, for an array of ints with a length of 10 dollars. This will mean "address i [10]" if you get what I mean (Pratic can of course use i [0] to i [9], but I mean with i [10] address. where the 10th entry ends / the 11th entry will start ==> end address of the array).

Does anyone know how I can get this end address via python / ctypes?

(Refactoring the C code so that it doesn't need the final address is not an option, it has been working correctly for years, it didn't have a unittest)

Oh by the way. the software release I'm currently working with uses python 2.5 (later versions use python 2.7, but it needs to be developed in this release first)

+1


source to share


1 answer


Kudo should go to eryksun (but cannot set the "correct answer" flag for a comment).



0


source







All Articles