logo       

Re: cast function, other ideas: msg#00012

python.ctypes

Subject: Re: cast function, other ideas

Thomas Heller wrote:
cast(ptr, c_char_p) returns a c_char_p instance, pointing to the same
address as the ptr instance (an instance of POINTER(c_ubyte)).
c_char_p has a .value attribute, which allows to access the nul
terminated string pointed to. IMO, the cast() function is a better way
to access the string at that address, instead of implementing .value
attributes for all the POINTER(byte) types.

Further, I think a get_string() function, which also takes a POINTER
instance (or even an integer address) as parameter would be useful in
ctypes, to make it easier to get these strings. With help of cast, it
can be implemented in this way, although I would prefer to implement it
in C to make it more efficient:

def get_string(ptr):
return cast(ptr, c_char_p).value

+1 (I recently needed something like cast() for this exact same scenario).

Thanks for ctypes!
-Dave


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise