Re: ctypes question

2010-12-14 Thread News Wombat
On Dec 11, 12:59 pm, MrJean1 mrje...@gmail.com wrote:

 In general, for shared libraries, you need to define those first as
 prototype using ctypes.CFUNCTYPE() and then instantiate each prototype
 once supplying the necessary parameter flags using
 prototype(func_spec, tuple_of_param_flags).  See sections 15.16.2.3
 and 4 of the ctypes docs*.

I tried the cfuntype and proto steps, and it's not crashing now
(that's good), but now i'm just left with null pointers as a return
object.  I'm still working through all of the examples you sent.  They
were extremely helpful.  Here's where I'm at now...

What is strange is I can actually get smiGetNode to work if I don't
cfunctype/proto it.  If i do, nada.  however, the smiGetNextNode fails
no matter what, usually with a segfault, but depending on how i
construct it, sometimes a null pointer.

constants.py: http://pastebin.com/f3b4Wbf0
libsmi.py: http://pastebin.com/XgtpG6gr
smi.c (the actual function): http://pastebin.com/Pu2vabWM
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes question

2010-12-10 Thread News Wombat
Hi everyone,

I've been experimenting with the ctypes module and think it's great.
I'm hitting a few snags though with seg faults.  I attached two links
that holds the code.  The line i'm having problems with is this,

sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY)

It will work one time, and if I call it again with the result of the
previous, even though the result (a c struct) looks ok, it will
segfault.  I think it's a problem with pointers or maybe the function
in the c library trying to change a string that python won't let it
change.  I'm stuck, any tips would be appreciated.  Thanks, and Merry
Christmas!

constants.py: http://pastebin.com/HvngjzZN
libsmi.py: http://pastebin.com/19C9kYEa
-- 
http://mail.python.org/mailman/listinfo/python-list