[IronPython] PyBonjour through Ctypes

Dino Viehland dinov at microsoft.com
Mon Sep 13 14:55:47 PDT 2010


It's not that WINFUNCTYPE is always changing in CPython - it's that each time you run it'll have a different ID.  In IronPython we allocate object IDs sequentially starting at 43.  So if the only thing you call id() on (which printing the repr does implicitly) then the 1st object will always have an id of 43.  If you did "id(100)" first and then looked at ctypes.WINFUNCTYPE then you'd see it'd be 0x2C.

Can you include the line of code where the call is happening and an setup to get into the call?  It does look like there's a 3rd argument that's optional because:

from ctypes import *
WINFUNCTYPE(c_int, c_int, c_int)(100, 'foo', '100')

Starts reporting a different error message on CPython than IronPython.  My guess is we need to implement this but there don't seem to be any tests for it so if we can see at least 1 call site that'd be helpful :)  can you open a bug on CodePlex for this as well?

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Clemens Nylandsted Klokmose
Sent: Sunday, September 12, 2010 7:48 AM
To: users at lists.ironpython.com
Subject: [IronPython] PyBonjour through Ctypes

Hi,
I am experimenting with getting a Python library running in IronPython that relies on PyBonjour (http://code.google.com/p/pybonjour/).
PyBonjour is a pure python library interfacing with the systems bonjour installation. I am completely unexperienced with CTypes, so what I am proposing now might seem naïve.

At the top of the pybonjour.py is code looking like this:
if sys.platform == 'win32':
    # Need to use the stdcall variants
    _libdnssd = ctypes.windll.dnssd
    _CFunc = ctypes.WINFUNCTYPE

IronPython's sys.platform evaluates to 'cli', so I have tried to change the check to if sys.platform == 'win32' or sys.platform == 'cli':
This seems to work, but everytime a C function is called now, Python complains that theres an argument too much.
E.g. TypeError: CFunctionType() takes at most 2 arguments (3 given). My suggestion is that ctypes.WINFUNCTYPE in IronPython might be a wrong value? (In IronPython it seems to always be 0x000000000000002B, whereas in CPython the value varies)

Does anyone have an idea of how to go about this?

It should be noted that I have pybonjour running with the standard CPython on Windows.

Thanks,
Clemens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20100913/8acf474a/attachment.htm>


More information about the Users mailing list