Getting the end-memory address of a memory-range via python / ctypes

醉酒当歌 提交于 2019-12-13 01:28:48

问题


I'm creating a very basic (coverage) unittest for a (hardware) C-interface in python.

A function of that C-interface needs memory-addresses since it talks directly to memory.

The prototype of the function is:

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

The startAddress, endAddress and curAddress are basically memory-addresses of an array-of-structs.

On the web (and stackoverflow ;-) ) I found references that if I want to do something with ctypes, so that is what I use.

For the 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 obtain a pointer to the address of the first entry and a pointer to the address of the current entry.

But the endAddress is the problem.
It is the real end address of the memory area which needs to be allocated by the function.
So for an array of ints of 10 long it would mean the 'address of i[10]' if you get what I mean (Pratically one can of course only use i[0] till i[9], but I mean with i[10] the address where the 10th entry ends / the 11th entry would start ==> the end-address of the array).

Does anybody know how I can obtain this end-address via python / ctypes?

(Refactoring the C-code so it does not need the end-address, is not an option, it is already working correctly for years, it only did not have an unittest)

Oh btw. the software-release I'm currently working with is using python 2.5 (later releases use python 2.7, but it first needs to be developed on this release)

来源:https://stackoverflow.com/questions/29495767/getting-the-end-memory-address-of-a-memory-range-via-python-ctypes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!