467,145 Members | 1,026 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

Re: ctypes - swig - pointer

On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <ge*******@gmail.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(value_type)
same as *value_type; - mydll.foo2(*value_type)
same as **value_type; - mydll.foo3(**value_type)

How can pass it in python. If i do that:
rules=POINTER(value_type)
opr=rsl.StrengthOfRules(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
Jun 30 '08 #1
  • viewed: 14220
Share:
2 Replies
On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod.comwrote:
On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmail.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(value_type)
same as *value_type; - mydll.foo2(*value_type)
same as **value_type; - mydll.foo3(**value_type)
How can pass it in python. If i do that:
rules=POINTER(value_type)
opr=rsl.StrengthOfRules(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
Jun 30 '08 #2

"gianluca" <ge*******@gmail.comwrote in message
news:58**********************************@z72g2000 hsb.googlegroups.com...
On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod.comwrote:
>On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmail.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(value_type)
same as *value_type; - mydll.foo2(*value_type)
same as **value_type; - mydll.foo3(**value_type)
>How can pass it in python. If i do that:
rules=POINTER(value_type)
opr=rsl.StrengthOfRules(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
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 "<interactive input>", line 1, in <module>
File "C:\dev\python\lib\ctypes\__init__.py", line 282, in pointer
return POINTER(type(inst))(inst)
File "C:\dev\python\lib\ctypes\__init__.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(px) # int** ppx = &px;
x
c_long(5)
>>px
<ctypes.LP_c_long object at 0x00E87350>
>>ppx
<ctypes.LP_LP_c_long object at 0x00E873A0>

--Mark

Jul 1 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Thomas Heller | last post: by
2 posts views Thread by ajikoe@gmail.com | last post: by
1 post views Thread by marc.wyburn@googlemail.com | last post: by
6 posts views Thread by Jack | last post: by
8 posts views Thread by gianluca | last post: by
reply views Thread by gianluca | last post: by
2 posts views Thread by Sells, Fred | last post: by
reply views Thread by Terry Reedy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.