[Python.NET] PythonNet for Mono, mostly done but need some help

Christian Heimes lists at cheimes.de
Tue Jul 17 15:15:28 CEST 2007


I've good news for Linux, BSD and Mac users. With some outstanding help
from the mono mailing list I was able to get PythonNet running on my
Ubuntu box.

I had a hard time implementing support for UCS-4 unicode representation
until Jonathan Pryor and Jonathan Chambers gave me some information and
sample code for a custom marshaler. UCS-4 uses up to four bytes to store
unicode while Windows is using a wchar (?) or UCS-2 to store unicode.
The CLR supports just CharSet.Unicode which is Microsoft's name for
UCS-2. Most Linux distributions like Debian/Ubuntu are using a UCS-4
build of Python.

After the UCS-4 vs. UCS-2 problem was fixed I was confronted with same
nasty seg faults. Brian gave me the tip to search for code that tries to
Decref NULL (IntPtr.Zero) and I found three places. One is my fault, one
Brian's and the third is equally shared between us since I didn't fix a
problem the right way in the first place. Mono seems to be more
sensitive to ref counter problems than .NET on Windows.

The results are very promising but Mono's generic and overloading
support seems to have some flaws. Two unit tests are failing that are
working under Windows and a third test is failing early. I'd appreciate
any insight knowledge to fix the outstanding tests.

======================================================================
ERROR: testGenericMethodOverloadSelection (test_generic.GenericTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/heimes/dev/python/pythonnet25/src/tests/test_generic.py",
line 353, in testGenericMethodOverloadSelection
    value = type.Overloaded[str]("test")
TypeError: No match found for given type params

======================================================================
ERROR: testGenericMethodTypeHandling (test_generic.GenericTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/heimes/dev/python/pythonnet25/src/tests/test_generic.py",
line 303, in testGenericMethodTypeHandling
    self._testGenericMethodByType(System.Boolean, True)
  File "/home/heimes/dev/python/pythonnet25/src/tests/test_generic.py",
line 202, in _testGenericMethodByType
    result = stype.Overloaded[ptype](value)
TypeError: No match found for given type params

======================================================================
FAIL: Test usage of generic value type definitions.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/heimes/dev/python/pythonnet25/src/tests/test_generic.py",
line 81, in testGenericValueType
    self.failUnless(inst.HasValue)
AssertionError


I'm also having trouble to create a facade clr module for Mono. The
clr.pyd doesn't work under Mono since Unix builds of Python can't load a
Windows PE executable. You can find my first and naive approach at
http://pythonnet.svn.sourceforge.net/viewvc/pythonnet/branches/clr-2.0-python-2.5-branch/src/monoclr/
You can compile it with python setup.py or simple do "$ make -f
makefile.mono clr.so".

Christian



More information about the PythonDotNet mailing list