A Question about ctypes and a function f(void **)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sapsi

    A Question about ctypes and a function f(void **)

    Hello,
    I have a C function f(void**,int *), in which it writes some
    information (it is a RGB32 image).

    Here is what i do
    rowlength=c_int ()
    data=c_void_p()
    d=pointer(data)
    f(d,byref(rowle ngth)
    The call works (no segmentation fault), now how do i access the data
    in d? Because i need to pass it to a another function QImage that
    takes void* as its first parameter.

    If i do d.contents i get c_void_p(306747 8024L)

    All suggestions welcome.
    Regards
    Saptarshi
  • Nick Craig-Wood

    #2
    Re: A Question about ctypes and a function f(void **)

    sapsi <saptarshi.guha @gmail.comwrote :
    I have a C function f(void**,int *), in which it writes some
    information (it is a RGB32 image).
    >
    Here is what i do
    rowlength=c_int ()
    data=c_void_p()
    d=pointer(data)
    f(d,byref(rowle ngth)
    The call works (no segmentation fault), now how do i access the data
    in d? Because i need to pass it to a another function QImage that
    takes void* as its first parameter.
    >
    If i do d.contents i get c_void_p(306747 8024L)
    You almost answered your own question!

    d.contents is a c_void_p ie a (void *) so you can pass d.contents to
    QImage directly I would have thought.

    If you want to actually read the data from python then you'll need to
    cast it to some other pointer type than c_void_p first, eg
    >>d
    c_void_p(136692 916)
    >>s = c_char_p(d.valu e)
    >>s
    c_char_p(136692 916)
    >>s.value
    'hello'
    >>>
    or use ctypes.memmove to copy the data out to somewhere else.

    --
    Nick Craig-Wood <nick@craig-wood.com-- http://www.craig-wood.com/nick

    Comment

    Working...