[Ironpython-users] Latest status on ctypes?

Jeff Hardy jdhardy at gmail.com
Wed Mar 6 17:04:53 CET 2013


On Wed, Mar 6, 2013 at 7:12 AM, Doug Blank <doug.blank at gmail.com> wrote:
>> It shouldn't even be trying to load libpython, since IronPython won't
>> be able to do anything sensible with it. That said, it should still
>> load, but I have no idea why it's not. Which OS are you using? And
>> which version of Mono?
>
> I'm using Mono 2.10.8.1 on Ubuntu.
>
> With your hints above, I'm guessing that there is an error in
> ctypes/__init__.py line 352:
>
> -       if handle is None:
> +       if handle is None and self._name:
>           self._handle = _dlopen(self._name, mode)
>         else:
>             self._handle = handle
>
> because handle and self.name are both None. That gives:
>
>>>> import ctypes
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "/home/dblank/Calico/trunk/bin/Lib/ctypes/__init__.py", line
> 478, in <module>
> SystemError: LocalAlloc
>
> The first offending line is:
>
> memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)
>
> Those values are:
>
>>>> print(CFUNCTYPE, c_void_p, c_void_p, c_void_p, c_size_t, _memmove_addr)
> <function CFUNCTYPE at 0x0000000000000042> <class '<module>.c_void_p'>
> <class '<module>.c_void_p'> <class '<module>.c_void_p'> <class
> '<module>.c_ulonglong'> 1100039664
>
> I have a libdl.so (even copied it next to exe). Perhaps there is
> something wrong with LocalAlloc, or contract:
>
> [DllImport("kernel32.dll"),
> ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
> private static extern IntPtr LocalAlloc(uint flags, IntPtr size);
>

The first major issue is that LocalAlloc is a Windows function, so
unless Mono provides a shim (which I doubt), there's no way it can be
loaded. I don't have the code handy to check *why* it's trying to use
LocalAlloc, but I have a feeling there's an assumption that
"IronPython == Windows" somewhere. Where does _memmove_addr come from?

I'm afraid you're breaking trail, Doug. When Dino wrote ctypes I doubt
he tested it on Linux, and I don't think anyone else has tried in the
meantime.

- Jeff


More information about the Ironpython-users mailing list