[Ironpython-users] Latest status on ctypes?
Doug Blank
doug.blank at gmail.com
Wed Mar 6 16:12:56 CET 2013
On Tue, Mar 5, 2013 at 3:41 PM, Jeff Hardy <jdhardy at gmail.com> wrote:
> On Tue, Mar 5, 2013 at 6:12 AM, Doug Blank <doug.blank at gmail.com> wrote:
>> Looks like there are at least two issues: one where the platform is
>> not known (and doesn't know what low level library to open), but the
>> lower level issue seems to be:
>>
>> $ mono ./ipy64.exe
>> IronPython 2.7.3 (2.7.0.40) on Mono 4.0.30319.1 (64-bit)
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> from ctypes import dlopen
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> File "/home/dblank/Desktop/IronPython-2.7.3/Lib/ctypes/__init__.py",
>> line 441, in <module>
>> File "/home/dblank/Desktop/IronPython-2.7.3/Lib/ctypes/__init__.py",
>> line 353, in __init__
>> OSError: IronPython.Runtime.Exceptions.OSException: cannot load library
>> at IronPython.Modules.CTypes.LoadLibrary (System.String library,
>> Int32 mode) [0x00000] in <filename unknown>:0
>> at IronPython.Modules.CTypes.dlopen (System.String library, Int32
>> mode) [0x00000] in <filename unknown>:0
>> at Microsoft.Scripting.Interpreter.FuncCallInstruction`3[System.String,System.Int32,System.Object].Run
>> (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in
>> <filename unknown>:0
>> at Microsoft.Scripting.Interpreter.Interpreter.Run
>> (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in
>> <filename unknown>:0
>>>>> from _ctypes import dlopen
>>>>> dlopen("/usr/lib/libpython2.7.so")
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> OSError: IronPython.Runtime.Exceptions.OSException: cannot load
>> library /usr/lib/libpython2.7.so
>> at IronPython.Modules.CTypes.LoadLibrary (System.String library,
>> Int32 mode) [0x00000] in <filename unknown>:0
>> at IronPython.Modules.CTypes.dlopen (System.String library, Int32
>> mode) [0x00000] in <filename unknown>:0
>> at Microsoft.Scripting.Interpreter.FuncCallInstruction`3[System.String,System.Int32,System.Object].Run
>> (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in
>> <filename unknown>:0
>> at Microsoft.Scripting.Interpreter.Interpreter.Run
>> (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in
>> <filename unknown>:0
>>
>> libpython2.7.so does exist, but LoadLibrary doesn't appear to be able
>> to deal with it. Am I using this correctly?
>
> 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);
-Doug
> - Jeff
More information about the Ironpython-users
mailing list