Re: ctypes - swig - pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: ctypes - swig - pointer

    On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonomica@gmai l.comwrote:
    >I've a problem with dll function colled with python/ctypes. My
    >functions (C) requred a typedef int "value_type " in tree different
    >way:
    >same as value_type; - mydll.foo1(valu e_type)
    >same as *value_type; - mydll.foo2(*val ue_type)
    >same as **value_type; - mydll.foo3(**va lue_type)
    >
    >How can pass it in python. If i do that:
    >rules=POINTER( value_type)
    >opr=rsl.Streng thOfRules(rules ,10)
    >R=POINTER(rule s)
    POINTER takes a class and returns a new class which represents a pointer
    to input class.

    pointer takes an instance and returns a new object which represents a
    pointer to that instance.

    Jean-Paul
  • gianluca

    #2
    Re: ctypes - swig - pointer

    On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod .comwrote:
    On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmai l.comwrote:
    I've a problem with dll function colled with python/ctypes. My
    functions (C) requred a typedef int "value_type " in tree different
    way:
    same as value_type; - mydll.foo1(valu e_type)
    same as *value_type; - mydll.foo2(*val ue_type)
    same as **value_type; - mydll.foo3(**va lue_type)
    >
    How can pass it in python. If i do that:
    rules=POINTER(v alue_type)
    opr=rsl.Strengt hOfRules(rules, 10)
    R=POINTER(rules )
    >
    POINTER takes a class and returns a new class which represents a pointer
    to input class.
    >
    pointer takes an instance and returns a new object which represents a
    pointer to that instance.
    >
    Jean-Paul
    so,
    if I write this:
    p=pointer(value _type)
    mydll.foo1(p)
    could be correct but python say me:
    TypeError: _type_ must have storage info
    what does mean?

    thank you

    gima

    Comment

    • Mark Tolonen

      #3
      Re: ctypes - swig - pointer


      "gianluca" <geonomica@gmai l.comwrote in message
      news:58461c91-ed11-4153-8d74-429353e4fdd1@z7 2g2000hsb.googl egroups.com...
      On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod .comwrote:
      >On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmai l.com>
      >wrote:
      >I've a problem with dll function colled with python/ctypes. My
      >functions (C) requred a typedef int "value_type " in tree different
      >way:
      >same as value_type; - mydll.foo1(valu e_type)
      >same as *value_type; - mydll.foo2(*val ue_type)
      >same as **value_type; - mydll.foo3(**va lue_type)
      >>
      >How can pass it in python. If i do that:
      >rules=POINTER( value_type)
      >opr=rsl.Streng thOfRules(rules ,10)
      >R=POINTER(rule s)
      >>
      >POINTER takes a class and returns a new class which represents a pointer
      >to input class.
      >>
      >pointer takes an instance and returns a new object which represents a
      >pointer to that instance.
      >>
      >Jean-Paul
      >
      so,
      if I write this:
      p=pointer(value _type)
      mydll.foo1(p)
      could be correct but python say me:
      TypeError: _type_ must have storage info
      what does mean?
      >
      thank you
      >
      gima
      It means you cannot create a pointer to a type, you need to provide an
      instance of a type:
      >>from ctypes import *
      >>px=pointer(c_ int)
      Traceback (most recent call last):
      File "<interacti ve input>", line 1, in <module>
      File "C:\dev\python\ lib\ctypes\__in it__.py", line 282, in pointer
      return POINTER(type(in st))(inst)
      File "C:\dev\python\ lib\ctypes\__in it__.py", line 226, in POINTER
      {'_type_': cls})
      TypeError: _type_ must have storage info
      >>x=c_int(5) # make an instance (C equiv. is "int x=5;")
      >>px=pointer( x) # int* px = &x;
      >>ppx=pointer(p x) # int** ppx = &px;
      >>x
      c_long(5)
      >>px
      <ctypes.LP_c_lo ng object at 0x00E87350>
      >>ppx
      <ctypes.LP_LP_c _long object at 0x00E873A0>

      --Mark

      Comment

      Working...