[Zope-CVS] CVS: PythonNet/src/runtime - CLRModule.il:1.1 ClassBase.cs:1.8 ClassManager.cs:1.7 ClassObject.cs:1.8 Converter.cs:1.6 DebugHelper.cs:1.5 DelegateManager.cs:1.5 DelegateObject.cs:1.5 EventBinding.cs:1.4 EventObject.cs:1.5 Exceptions.cs:1.6 ExtensionType.cs:1.3 ImportHook.cs:1.6 InterfaceObject.cs:1.3 Interop.cs:1.4 ManagedType.cs:1.4 MetaType.cs:1.7 MethodBinder.cs:1.6 MethodObject.cs:1.3 MethodWrapper.cs:1.5 ModuleObject.cs:1.4 PyObject.cs:1.3 Python.cs:1.3 Runtime.cs:1.11 TypeManager.cs:1.9

Brian Lloyd cvs-admin at zope.org
Wed Oct 22 22:53:41 EDT 2003


Update of /cvs-repository/PythonNet/src/runtime
In directory cvs.zope.org:/tmp/cvs-serv22945/src/runtime

Modified Files:
	ClassBase.cs ClassManager.cs ClassObject.cs Converter.cs 
	DebugHelper.cs DelegateManager.cs DelegateObject.cs 
	EventBinding.cs EventObject.cs Exceptions.cs ExtensionType.cs 
	ImportHook.cs InterfaceObject.cs Interop.cs ManagedType.cs 
	MetaType.cs MethodBinder.cs MethodObject.cs MethodWrapper.cs 
	ModuleObject.cs PyObject.cs Python.cs Runtime.cs 
	TypeManager.cs 
Added Files:
	CLRModule.il 
Log Message:
Lots of fixes to support Python 2.3.2, new sneaky CLR.dll stub to support 
loading the managed runtime into a plain CPython process, prep for b1.


=== Added File PythonNet/src/runtime/CLRModule.il ===
// Copyright (c) 2003 Zope Corporation and Contributors.
//
// All Rights Reserved.
//
// This software is subject to the provisions of the Zope Public License,
// Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// FOR A PARTICULAR PURPOSE.

//============================================================================
// This file is a hand-maintained stub - it implements CLR.dll, which can be
// loaded by a standard CPython interpreter as an extension module. When it 
// is loaded, it bootstraps the managed runtime integration layer and defers
// to it do initialization and put the CLR module into sys.modules, etc.
//============================================================================

.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
  .ver 1:0:5000:0
}
.assembly extern Python.Runtime
{
  .publickeytoken = (B2 C3 0B 6E FB AF 71 E5 )
  .ver 1:0:0:0
}
.assembly CLR
{
  // --- The following custom attribute is added automatically, do not uncomment -------
  //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool,
  //                                                                                bool) = ( 01 00 00 01 00 00 ) 
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}

.module CLR.dll
// MVID: {01BEB897-1638-4D9D-B01C-3638714A76B4}
.imagebase 0x00400000
.subsystem 0x00000003
.file alignment 512
.corflags 0x00000002

.vtfixup [1] int32 fromunmanaged at VT_01
.data VT_01 = int32(0)


.class public auto ansi beforefieldinit CLRModule
       extends [mscorlib]System.Object
{
} // end of class CLRModule



.class public auto ansi beforefieldinit CLRModule
       extends [mscorlib]System.Object
{
  .method public hidebysig static void 
   modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) 
   initCLR() cil managed
  {
    .vtentry 1:1
    .export [1] as initCLR

    // Code size       8 (0x8)
    .maxstack  0
    IL_0000:  call void [Python.Runtime]Python.Runtime.PythonEngine::InitExt()
    IL_0005:  br.s       IL_0007

    IL_0007:  ret
  } // end of method CLRModule::initCLR

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // Code size       7 (0x7)
    .maxstack  1
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method CLRModule::.ctor

} // end of class CLRModule




=== PythonNet/src/runtime/ClassBase.cs 1.7 => 1.8 ===
--- PythonNet/src/runtime/ClassBase.cs:1.7	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ClassBase.cs	Wed Oct 22 22:53:10 2003
@@ -95,7 +95,7 @@
 	    }
 
 	    Iterator iter = new Iterator(e.GetEnumerator());
-	    return iter.Handle;
+	    return iter.pyHandle;
 	}
 
 
@@ -144,8 +144,8 @@
 	    ManagedType self = GetManagedObject(ob);
 	    IntPtr dict = Marshal.ReadIntPtr(ob, ObjectOffset.ob_dict);
 	    Runtime.Decref(dict);
-	    Runtime._PyObject_GC_UnTrack(self.pyHandle);
-	    Runtime._PyObject_GC_Del(self.pyHandle);
+	    Runtime.PyObject_GC_UnTrack(self.pyHandle);
+	    Runtime.PyObject_GC_Del(self.pyHandle);
 	    Runtime.Decref(self.tpHandle);
 	    self.gcHandle.Free();
 	}


=== PythonNet/src/runtime/ClassManager.cs 1.6 => 1.7 ===
--- PythonNet/src/runtime/ClassManager.cs:1.6	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ClassManager.cs	Wed Oct 22 22:53:10 2003
@@ -113,7 +113,7 @@
 	    while(iter.MoveNext()) {
 		item = (ManagedType)iter.Value;
 		name = (string)iter.Key;
-		Runtime.PyDict_SetItemString(dict, name, item.Handle);
+		Runtime.PyDict_SetItemString(dict, name, item.pyHandle);
 	    }
 
 	    return impl;


=== PythonNet/src/runtime/ClassObject.cs 1.7 => 1.8 ===
--- PythonNet/src/runtime/ClassObject.cs:1.7	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ClassObject.cs	Wed Oct 22 22:53:10 2003
@@ -114,9 +114,7 @@
 		    return IntPtr.Zero;
 		}
 
-		op = CLRObject.GetInstHandle(result, tp);
-		Runtime.Incref(op);
-		return op;
+		return CLRObject.GetInstHandle(result, tp);
 	    }
 
 	    if (type.IsAbstract) {


=== PythonNet/src/runtime/Converter.cs 1.5 => 1.6 ===
--- PythonNet/src/runtime/Converter.cs:1.5	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/Converter.cs	Wed Oct 22 22:53:10 2003
@@ -73,7 +73,6 @@
 
 	    case TypeCode.Object:
 		result = CLRObject.GetInstHandle(value, type);
-		Runtime.Incref(result);
 		return result;
 
 	    case TypeCode.String:
@@ -122,7 +121,6 @@
 
 	    default:
 		result = CLRObject.GetInstHandle(value, type);
-		Runtime.Incref(result);
 		return result;
 	    }
 
@@ -243,10 +241,17 @@
 		// Trickery to support 64-bit platforms.
 	        if (IntPtr.Size == 4) {
 		    op = Runtime.PyNumber_Int(value);
+
+		    // As of Python 2.3, large ints magically convert :(
+		    if (Runtime.PyLong_Check(op) ) {
+			Runtime.Decref(op);
+			goto overflow;
+		    }
+
 		    if (op == IntPtr.Zero) {
 		        if (Exceptions.ExceptionMatches(overflow)) {
 			    goto overflow;
-		      }
+			}
 		      goto type_error;
 		    }
 		    ival = (int)Runtime.PyInt_AsLong(op);


=== PythonNet/src/runtime/DebugHelper.cs 1.4 => 1.5 ===
--- PythonNet/src/runtime/DebugHelper.cs:1.4	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/DebugHelper.cs	Wed Oct 22 22:53:10 2003
@@ -55,8 +55,8 @@
 	    op = Marshal.ReadIntPtr(type, TypeOffset.tp_bases);
 	    DebugUtil.Print("  bases: ", op);
 
-	    op = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
-	    DebugUtil.Print("  mro: ", op);
+	    //op = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
+	    //DebugUtil.Print("  mro: ", op);
 
 	    op = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
 	    if (op == IntPtr.Zero) {


=== PythonNet/src/runtime/DelegateManager.cs 1.4 => 1.5 ===
--- PythonNet/src/runtime/DelegateManager.cs:1.4	Tue Oct  7 22:29:17 2003
+++ PythonNet/src/runtime/DelegateManager.cs	Wed Oct 22 22:53:10 2003
@@ -207,8 +207,13 @@
 	    this.dtype = dtype;
 	}
 
-	public void Finalize() {
+        ~Dispatcher() {
+	    // TODO: The new PyGILState_* APIs do not appear to work in the
+	    // managed runtime (at least on the gc thread) - think harder.
+	    IntPtr ts = PythonEngine.EnsureThread();
+	    IntPtr cs = Runtime.PyThreadState_Swap(ts);
 	    Runtime.Decref(target);
+	    Runtime.PyThreadState_Swap(cs);
 	}
 
 	public object Dispatch(ArrayList args) {
@@ -232,8 +237,8 @@
 	    }
 
 	    IntPtr op = Runtime.PyObject_Call(target, pyargs, IntPtr.Zero);
-
 	    Runtime.Decref(pyargs);
+
 	    if (op == IntPtr.Zero) {
 		PythonException e = new PythonException();
 		throw e;


=== PythonNet/src/runtime/DelegateObject.cs 1.4 => 1.5 ===
--- PythonNet/src/runtime/DelegateObject.cs:1.4	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/DelegateObject.cs	Wed Oct 22 22:53:10 2003
@@ -27,9 +27,9 @@
 
 	internal DelegateObject(Type tp) : base(tp) {
 	    binder = new MethodBinder(tp.GetMethod("Invoke"));
-	    binder.FreeThreaded = false;
 	}
 
+
 	//====================================================================
 	// Given a PyObject pointer to an instance of a delegate type, return
 	// the true managed delegate the Python object represents (or null).
@@ -44,10 +44,12 @@
 	    return null;
 	}
 
+
 	internal override bool CanSubclass() {
 	    return false;
 	}
 
+
 	//====================================================================
 	// DelegateObject __new__ implementation. The result of this is a new
 	// PyObject whose type is DelegateObject and whose ob_data is a handle
@@ -77,12 +79,11 @@
 	    }
 
 	    Delegate d = DelegateManager.GetDelegate(self.type, method);
-	    IntPtr op = CLRObject.GetInstHandle(d, self.Handle);
-	    Runtime.Incref(op);
-	    return op;
+	    return CLRObject.GetInstHandle(d, self.pyHandle);
 	}
 
 
+
 	//====================================================================
 	// Implements __call__ for reflected delegate types.
 	//====================================================================
@@ -109,6 +110,7 @@
 	    return self.binder.Invoke(ob, args, kw);
 	}
 
+
 	//====================================================================
 	// Implements __cmp__ for reflected delegate types.
 	//====================================================================
@@ -124,13 +126,7 @@
 	}
 
 
-	/*
-	public override IntPtr ClassRepr() {
-	    string s = String.Format("<delegate '{0}'>", this.type.FullName);
-	    return Runtime.PyString_FromStringAndSize(s, s.Length);
-	}
-	*/
-
     }	
+
 
 }


=== PythonNet/src/runtime/EventBinding.cs 1.3 => 1.4 ===
--- PythonNet/src/runtime/EventBinding.cs:1.3	Tue Oct  7 22:29:17 2003
+++ PythonNet/src/runtime/EventBinding.cs	Wed Oct 22 22:53:10 2003
@@ -48,8 +48,8 @@
 		return IntPtr.Zero;
 	    }
 
-	    Runtime.Incref(self.Handle);
-	    return self.Handle;
+	    Runtime.Incref(self.pyHandle);
+	    return self.pyHandle;
 	}
 
 
@@ -72,8 +72,8 @@
 		return IntPtr.Zero;
 	    }
 
-	    Runtime.Incref(self.Handle);
-	    return self.Handle;
+	    Runtime.Incref(self.pyHandle);
+	    return self.pyHandle;
 	}
 
 


=== PythonNet/src/runtime/EventObject.cs 1.4 => 1.5 ===
--- PythonNet/src/runtime/EventObject.cs:1.4	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/EventObject.cs	Wed Oct 22 22:53:10 2003
@@ -116,6 +116,7 @@
 
 	    // RemoveEventHandler doesn't work for non-public events.
 
+
 	    object[] args = { found };
 	    MethodInfo mi = this.info.GetRemoveMethod(true);
 	    mi.Invoke(obj, BindingFlags.Default, null, args, null);
@@ -138,7 +139,7 @@
 
 	    MethodInfo method = d.GetType().GetMethod("Invoke", flags);
 	    IntPtr wrapped = CLRObject.GetInstHandle(d);
-	    Runtime.Incref(wrapped);
+
   	    MethodBinder binder = new MethodBinder(method);
  	    IntPtr op = binder.Invoke(wrapped, args, kw);
 	    Runtime.Decref(wrapped);
@@ -191,8 +192,8 @@
 		    self.unbound = new EventBinding(self, IntPtr.Zero);
 		}
 		binding = self.unbound;
-		Runtime.Incref(binding.Handle);
-		return binding.Handle;
+		Runtime.Incref(binding.pyHandle);
+		return binding.pyHandle;
 	    }
 
 	    if (Runtime.PyObject_IsInstance(ob, tp) < 1) {
@@ -201,7 +202,7 @@
 	    }
 
 	    binding = new EventBinding(self, ob);
-	    return binding.Handle;
+	    return binding.pyHandle;
 	}
 
 
@@ -247,7 +248,7 @@
 	public static new void tp_dealloc(IntPtr ob) {
 	    EventObject self = (EventObject)GetManagedObject(ob);
 	    if (self.unbound != null) {
-		Runtime.Decref(self.unbound.Handle);
+		Runtime.Decref(self.unbound.pyHandle);
 	    }
 	    ExtensionType.FinalizeObject(self);
 	}


=== PythonNet/src/runtime/Exceptions.cs 1.5 => 1.6 ===
--- PythonNet/src/runtime/Exceptions.cs:1.5	Fri Aug  8 15:49:21 2003
+++ PythonNet/src/runtime/Exceptions.cs	Wed Oct 22 22:53:10 2003
@@ -136,7 +136,6 @@
 
 	    Runtime.PyErr_Clear();
 	    IntPtr op = CLRObject.GetInstHandle(e);
-	    Runtime.Incref(op);
 	    Runtime.PyErr_SetString(op, e.Message);
 	}
 


=== PythonNet/src/runtime/ExtensionType.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/ExtensionType.cs:1.2	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ExtensionType.cs	Wed Oct 22 22:53:10 2003
@@ -42,7 +42,7 @@
 	    // concrete extension types, so untrack the object to save calls
 	    // from Python into the managed runtime that are pure overhead.
 
-	    Runtime._PyObject_GC_UnTrack(py);
+	    Runtime.PyObject_GC_UnTrack(py);
 
 	    this.tpHandle = tp;
 	    this.pyHandle = py;
@@ -55,7 +55,7 @@
 	//====================================================================
 
 	public static void FinalizeObject(ManagedType self) {
-	    Runtime._PyObject_GC_Del(self.pyHandle);
+	    Runtime.PyObject_GC_Del(self.pyHandle);
 	    Runtime.Decref(self.tpHandle);
 	    self.gcHandle.Free();
 	}
@@ -119,7 +119,6 @@
 	public static void tp_dealloc(IntPtr ob) {
 	    // Clean up a Python instance of this extension type. This 
 	    // frees the allocated Python object and decrefs the type.
-	    //Console.WriteLine("dealloc");
 	    ManagedType self = GetManagedObject(ob);
 	    FinalizeObject(self);
 	}


=== PythonNet/src/runtime/ImportHook.cs 1.5 => 1.6 ===
--- PythonNet/src/runtime/ImportHook.cs:1.5	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ImportHook.cs	Wed Oct 22 22:53:10 2003
@@ -23,6 +23,7 @@
 	static IntPtr py_import;
 	static ModuleObject root;
 	static StaticMethodWrapper hook;
+
 	public static void Initialize() {
 
 	    // Initialize the Python <--> CLR module hook. We replace the
@@ -34,6 +35,7 @@
 	    IntPtr mod = Runtime.PyDict_GetItemString(dict, "__builtin__");
 	    py_import = Runtime.PyObject_GetAttrString(mod, "__import__");
 
+
   	    hook = new StaticMethodWrapper(typeof(ImportHook),"__import__");
 
   	    Runtime.PyObject_SetAttrString(mod, "__import__", hook.pyHandle);
@@ -41,6 +43,8 @@
 	    Runtime.Decref(hook.pyHandle);
 
 	    root = new ModuleObject("");
+
+	    Runtime.PyDict_SetItemString(dict, "CLR", root.pyHandle);
 	}
 
 


=== PythonNet/src/runtime/InterfaceObject.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/InterfaceObject.cs:1.2	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/InterfaceObject.cs	Wed Oct 22 22:53:10 2003
@@ -57,9 +57,7 @@
 		//obj = CastHelper.CastObject(obj, type);
 	    }
 
-	    IntPtr op = CLRObject.GetInstHandle(obj, self.pyHandle);
-	    Runtime.Incref(op);
-	    return op;
+	    return CLRObject.GetInstHandle(obj, self.pyHandle);
 	}
 
 


=== PythonNet/src/runtime/Interop.cs 1.3 => 1.4 ===
--- PythonNet/src/runtime/Interop.cs:1.3	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/Interop.cs	Wed Oct 22 22:53:10 2003
@@ -44,8 +44,8 @@
 	    int size = IntPtr.Size;
 	    ob_refcnt = 0;
 	    ob_type = 1 * size;
-	    ob_data = 2 * size;
-	    ob_dict = 3 * size;
+	    ob_dict = 2 * size;
+	    ob_data = 3 * size;
 	}
 
 	public static int magic() {
@@ -58,8 +58,8 @@
 
 	public static int ob_refcnt;
 	public static int ob_type;
-	public static int ob_data;
 	public static int ob_dict;
+	public static int ob_data;
     }
 
 
@@ -76,7 +76,7 @@
 	}
 
 	public static int magic() {
-	    return ob_size; // * IntPtr.Size;
+	    return ob_size;
 	}
 
 	public static int ob_refcnt = 0;
@@ -126,6 +126,7 @@
 	public static int tp_cache = 0;
 	public static int tp_subclasses = 0;
 	public static int tp_weaklist = 0;
+	public static int tp_del = 0;
 
 	public static int nb_add = 0;
 	public static int nb_subtract = 0;
@@ -166,6 +167,10 @@
 	public static int nb_inplace_floor_divide = 0;
 	public static int nb_inplace_true_divide = 0;
 
+	public static int mp_length = 0;
+	public static int mp_subscript = 0;
+	public static int mp_ass_subscript = 0;
+
 	public static int sq_length = 0;
 	public static int sq_concat = 0;
 	public static int sq_repeat = 0;
@@ -177,10 +182,6 @@
 	public static int sq_inplace_concat = 0;
 	public static int sq_inplace_repeat = 0;
 
-	public static int mp_length = 0;
-	public static int mp_subscript = 0;
-	public static int mp_ass_subscript = 0;
-
 	public static int bf_getreadbuffer = 0;
 	public static int bf_getwritebuffer = 0;
 	public static int bf_getsegcount = 0;
@@ -189,8 +190,6 @@
 	public static int name = 0;
 	public static int slots = 0;
 	public static int members = 0;
-
-
 
     }
 


=== PythonNet/src/runtime/ManagedType.cs 1.3 => 1.4 ===
--- PythonNet/src/runtime/ManagedType.cs:1.3	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ManagedType.cs	Wed Oct 22 22:53:10 2003
@@ -28,14 +28,6 @@
 	internal IntPtr pyHandle;   // PyObject *
 	internal IntPtr tpHandle;   // PyType *
 
-	public IntPtr Handle {
-	    get { return pyHandle; }
-	}
-
-	public IntPtr TypeHandle {
-	    get { return tpHandle; }
-	}
-
 
 	//====================================================================
 	// Given a Python object, return the associated managed object or null.


=== PythonNet/src/runtime/MetaType.cs 1.6 => 1.7 ===
--- PythonNet/src/runtime/MetaType.cs:1.6	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/MetaType.cs	Wed Oct 22 22:53:10 2003
@@ -44,7 +44,6 @@
 
 	[CallConvCdecl()]
 	public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) {
-
 	    int len = Runtime.PyTuple_Size(args);
 	    if (len < 3) {
 		Exceptions.SetError(Exceptions.TypeError, 
@@ -191,14 +190,6 @@
 	public static void tp_dealloc(IntPtr tp) {
 	    DebugUtil.Print("mt tp_dealloc: ", tp);
 
-	    // Free the allocated name of the generated type object.
-
-	    IntPtr op = Marshal.ReadIntPtr(tp, TypeOffset.tp_name);
-	    Marshal.FreeHGlobal(op);
-
-	    //op = Marshal.ReadIntPtr(tp, TypeOffset.ob_type);
-	    Runtime.Decref(op); // is this right?
-
 	    // Fix this when we dont cheat on the handle for subclasses!
 
 	    int flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags);
@@ -208,38 +199,18 @@
 	    }
 
 	    // Delegate the rest of finalization the Python metatype.
-
-	    op = Marshal.ReadIntPtr(Runtime.PyTypeType, TypeOffset.tp_dealloc);
+	    IntPtr py_type = Runtime.PyTypeType;
+	    IntPtr op = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dealloc);
 	    NativeCall.Void_Call_1(op, tp);
-
 	}
 
 
 	[CallConvCdecl()]
 	public static void tp_free(IntPtr tp) {
-	    Console.WriteLine("mt tp_free - fix!");
-	}
-
-
-
-	[CallConvCdecl()]
-	public static int tp_traverse(IntPtr ob, IntPtr func, IntPtr args) {
-	    //DebugUtil.Print("mt traverse: ", ob);
-	    return 0;
-	}
-
-
-	[CallConvCdecl()]
-	public static int tp_clear(IntPtr ob) {
-	    //Console.WriteLine("mtt clear");
-	    return 0;
+	    Console.WriteLine("mt tp_free");
+	    return;
 	}
 
-
-	[CallConvCdecl()]
-	public static int tp_is_gc(IntPtr type) {
-	    return 1;
-	}
 
     }
 


=== PythonNet/src/runtime/MethodBinder.cs 1.5 => 1.6 ===
--- PythonNet/src/runtime/MethodBinder.cs:1.5	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/MethodBinder.cs	Wed Oct 22 22:53:10 2003
@@ -26,7 +26,6 @@
 
 	// MethodInfo info;
 	public ArrayList list;
-	public bool FreeThreaded = true;
 	public MethodBase[] methods;
 	public bool init = false;
 


=== PythonNet/src/runtime/MethodObject.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/MethodObject.cs:1.2	Tue Oct  7 22:29:17 2003
+++ PythonNet/src/runtime/MethodObject.cs	Wed Oct 22 22:53:10 2003
@@ -36,7 +36,6 @@
 	}
 
 	public virtual IntPtr Invoke(IntPtr target, IntPtr args, IntPtr kw) {
-	    // TODO: should probably release GIL around the method call
 	    return binder.Invoke(target, args, kw);
 	}
 
@@ -59,8 +58,8 @@
 		    self.unbound = new MethodBinding(self, IntPtr.Zero);
 		}
 		binding = self.unbound;
-		Runtime.Incref(binding.Handle);;
-		return binding.Handle;
+		Runtime.Incref(binding.pyHandle);;
+		return binding.pyHandle;
 	    }
 
 	    if (Runtime.PyObject_IsInstance(ob, tp) < 1) {
@@ -69,7 +68,7 @@
 	    }
 
 	    binding = new MethodBinding(self, ob);
-	    return binding.Handle;
+	    return binding.pyHandle;
 	}
 
 	//====================================================================
@@ -91,7 +90,7 @@
 	public static new void tp_dealloc(IntPtr ob) {
 	    MethodObject self = (MethodObject)GetManagedObject(ob);
 	    if (self.unbound != null) {
-		Runtime.Decref(self.unbound.Handle);
+		Runtime.Decref(self.unbound.pyHandle);
 	    }
 	    ExtensionType.FinalizeObject(self);
 	}


=== PythonNet/src/runtime/MethodWrapper.cs 1.4 => 1.5 ===
--- PythonNet/src/runtime/MethodWrapper.cs:1.4	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/MethodWrapper.cs	Wed Oct 22 22:53:10 2003
@@ -62,10 +62,6 @@
 	}
 
 
-	public IntPtr Handle {
-	    get { return pyHandle; }
-	}
-
 	public IntPtr Call(IntPtr args, IntPtr kw) {
 	    return Runtime.PyCFunction_Call(pyHandle, args, kw);
 	}


=== PythonNet/src/runtime/ModuleObject.cs 1.3 => 1.4 ===
--- PythonNet/src/runtime/ModuleObject.cs:1.3	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/ModuleObject.cs	Wed Oct 22 22:53:10 2003
@@ -10,6 +10,7 @@
 // FOR A PARTICULAR PURPOSE.
 
 using System;
+using System.Runtime.InteropServices;
 using System.Collections.Specialized;
 using System.Collections;
 using System.Reflection;
@@ -29,6 +30,7 @@
 	string moduleName;
 	string _namespace;
 	Hashtable cache;
+	bool hacked;
 	IntPtr dict;
 
 	public ModuleObject(string name) : base() {
@@ -41,6 +43,23 @@
 	    Runtime.PyDict_SetItemString(dict, "__name__", pyname);
 	    Runtime.PyDict_SetItemString(dict, "__doc__", Runtime.PyNone);
 	    Runtime.Decref(pyname);
+
+	    Marshal.WriteIntPtr(this.pyHandle, ObjectOffset.ob_dict, dict);
+
+	    // This hackery is required in order to allow a plain Python to
+	    // import the managed runtime via the CLR bootstrapper module. 
+	    // The standard Python machinery in control at the time of the
+	    // import requires the module to pass PyModule_Check. :(
+
+	    if (!hacked) {
+		IntPtr type = this.tpHandle;
+		IntPtr mro = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
+		IntPtr ext = Runtime.ExtendTuple(mro, Runtime.PyModuleType);
+		Marshal.WriteIntPtr(type, TypeOffset.tp_mro, ext);
+		Runtime.Decref(mro);
+		hacked = true;
+	    }
+
 	}
 
 	public string ModuleName {
@@ -125,7 +144,7 @@
  	//===================================================================
 
 	private void StoreAttribute(string name, ManagedType ob) {
-	    Runtime.PyDict_SetItemString(dict, name, ob.Handle);
+	    Runtime.PyDict_SetItemString(dict, name, ob.pyHandle);
 	    cache[name] = ob;
 	}
 
@@ -181,14 +200,15 @@
  
 	    string name = Runtime.GetManagedString(key);
 	    if (name == "__dict__") {
-		return Runtime.PyDictProxy_New(self.dict);
+		Runtime.Incref(self.dict);
+		return self.dict;
 	    }
 
 	    ManagedType attr = self.GetAttribute(name);
 
 	    if (attr != null) {
-		Runtime.Incref(attr.Handle);
-		return attr.Handle;
+		Runtime.Incref(attr.pyHandle);
+		return attr.pyHandle;
 	    }
 
 	    Exceptions.SetError(Exceptions.AttributeError, name);


=== PythonNet/src/runtime/PyObject.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/PyObject.cs:1.2	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/PyObject.cs	Wed Oct 22 22:53:10 2003
@@ -88,7 +88,6 @@
 	/// </remarks>
 
 	public void Dispose() {
-	    //Console.WriteLine("dispose called: {0}", this.ToString());
 	    GC.SuppressFinalize(this);
 	    Runtime.Decref(obj);
 	    obj = IntPtr.Zero;	


=== PythonNet/src/runtime/Python.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/Python.cs:1.2	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/Python.cs	Wed Oct 22 22:53:10 2003
@@ -48,11 +48,23 @@
 		istate = Marshal.ReadIntPtr(ts, 1 * IntPtr.Size);
 
 		initialized = true;
+		Exceptions.Clear();
 	    }
 	}
 
 
 	//====================================================================
+	// A helper to perform initialization from the context of an active
+	// CPython interpreter process - this bootstraps the managed runtime
+	// when it is imported by the CLR extension module.
+	//====================================================================
+
+	public static void InitExt() {
+	    Initialize();
+	}
+
+
+	//====================================================================
 	// Shutdown and clean up the Python runtime. After calling this method,
 	// the Python runtime can no longer be used in the current process.
 	//====================================================================
@@ -121,9 +133,6 @@
 		ts = Runtime.PyEval_SaveThread();
 	    }
 	}
-
-
-
 
 
 	//====================================================================


=== PythonNet/src/runtime/Runtime.cs 1.10 => 1.11 ===
--- PythonNet/src/runtime/Runtime.cs:1.10	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/Runtime.cs	Wed Oct 22 22:53:10 2003
@@ -151,6 +151,29 @@
 	}
 
 
+	internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) {
+	    int size = Runtime.PyTuple_Size(t);
+	    int add = args.Length;
+	    int total = size + add;
+	    IntPtr item;
+
+	    IntPtr items = Runtime.PyTuple_New(size + add);
+	    for (int i = 0; i < size; i++) {
+		item = Runtime.PyTuple_GetItem(t, i);
+		Runtime.Incref(item);
+		Runtime.PyTuple_SetItem(items, i, item);   
+	    }
+
+	    for (int n = 0; n < add; n++) {
+		item = args[n];
+		Runtime.Incref(item);
+		Runtime.PyTuple_SetItem(items, size + n, item);   
+	    }
+
+	    return items;
+	}
+
+
 	//===================================================================
 	// Managed exports of the Python C API. Where appropriate, we do 
 	// some optimization to avoid managed <--> unmanaged transitions
@@ -185,152 +208,168 @@
 	}
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	Py_Initialize();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	Py_Finalize();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	Py_NewInterpreter();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	Py_EndInterpreter(IntPtr threadState);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyThreadState_New(IntPtr istate);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyThreadState_Get();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyThreadState_Swap(IntPtr tstate);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
+		    ExactSpelling=true, CharSet=CharSet.Ansi)]
+	internal unsafe static extern IntPtr
+	PyGILState_Ensure();
+
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
+		    ExactSpelling=true, CharSet=CharSet.Ansi)]
+	internal unsafe static extern void
+	PyGILState_Release(IntPtr gs);
+
+
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
+		    ExactSpelling=true, CharSet=CharSet.Ansi)]
+	internal unsafe static extern IntPtr
+	PyGILState_GetThisThreadState();
+
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	public unsafe static extern int
 	Py_Main(int argc, string[] argv);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_InitThreads();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_AcquireLock();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_ReleaseLock();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_AcquireThread(IntPtr tstate);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_ReleaseThread(IntPtr tstate);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyEval_SaveThread();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyEval_RestoreThread(IntPtr tstate);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetProgramName();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
         Py_SetProgramName(string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetPythonHome();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
         Py_SetPythonHome(string home);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetVersion();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetPlatform();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetCopyright();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetCompiler();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern string
         Py_GetBuildInfo();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyRun_SimpleString(string code);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyCFunction_New(IntPtr ml, IntPtr self);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyClass_New(IntPtr bases, IntPtr dict, IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyMethod_New(IntPtr func, IntPtr self, IntPtr cls);
@@ -375,113 +414,113 @@
 	    return Marshal.PtrToStringAnsi(ppName);
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_HasAttrString(IntPtr pointer, string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
         PyObject_GetAttrString(IntPtr pointer, string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_HasAttr(IntPtr pointer, IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
         PyObject_GetAttr(IntPtr pointer, IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
         PyObject_GetItem(IntPtr pointer, IntPtr key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern int
         PyObject_DelItem(IntPtr pointer, IntPtr key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
         PyObject_GetIter(IntPtr op);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
         PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_CallObject(IntPtr pointer, IntPtr args);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_Compare(IntPtr value1, IntPtr value2);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_IsInstance(IntPtr ob, IntPtr type);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_IsSubclass(IntPtr ob, IntPtr type);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyCallable_Check(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_IsTrue(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_Size(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_Hash(IntPtr op);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_Repr(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_Str(IntPtr pointer);
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_Dir(IntPtr pointer);
@@ -491,23 +530,23 @@
 	// Python number API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyNumber_Int(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyNumber_Long(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyNumber_Float(IntPtr ob);
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern bool
 	PyNumber_Check(IntPtr ob);
@@ -519,7 +558,7 @@
 
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	private unsafe static extern IntPtr
 	PyInt_FromLong(IntPtr value);
@@ -535,17 +574,17 @@
 	}
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyInt_AsLong(IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyInt_FromString(string value, IntPtr end, int radix);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyInt_GetMax();
@@ -555,52 +594,52 @@
 	    return PyObject_TYPE(ob) == Runtime.PyLongType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromLong(long value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromUnsignedLong(uint value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromDouble(double value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromLongLong(long value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromUnsignedLongLong(ulong value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyLong_FromString(string value, IntPtr end, int radix);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyLong_AsLong(IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern uint
 	PyLong_AsUnsignedLong(IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern long
 	PyLong_AsLongLong(IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern ulong
 	PyLong_AsUnsignedLongLong(IntPtr value);
@@ -610,17 +649,17 @@
 	    return PyObject_TYPE(ob) == Runtime.PyFloatType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyFloat_FromDouble(double value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyFloat_FromString(IntPtr value, IntPtr junk);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern double
 	PyFloat_AsDouble(IntPtr ob);
@@ -630,77 +669,77 @@
 	// Python sequence API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern bool
 	PySequence_Check(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_GetItem(IntPtr pointer, int index);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_SetItem(IntPtr pointer, int index, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_DelItem(IntPtr pointer, int index);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_GetSlice(IntPtr pointer, int i1, int i2);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_DelSlice(IntPtr pointer, int i1, int i2);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_Size(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_Contains(IntPtr pointer, IntPtr item);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_Concat(IntPtr pointer, IntPtr other);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_Repeat(IntPtr pointer, int count);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_Index(IntPtr pointer, IntPtr item);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySequence_Count(IntPtr pointer, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_Tuple(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySequence_List(IntPtr pointer);
@@ -723,23 +762,23 @@
 	    return PyString_FromStringAndSize(value, value.Length);
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyString_FromStringAndSize(string value, int size);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern string
 	PyString_AsString(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyString_AsString",
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr 
 	PyString_AS_STRING(IntPtr op);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyString_Size(IntPtr pointer);
@@ -749,19 +788,19 @@
 	    return PyObject_TYPE(ob) == Runtime.PyUnicodeType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_FromObject",
 		    ExactSpelling=true, CharSet=CharSet.Unicode)]
 	internal unsafe static extern IntPtr
 	PyUnicode_FromObject(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_FromEncodedObject",
 		    ExactSpelling=true, CharSet=CharSet.Unicode)]
 	internal unsafe static extern IntPtr
 	PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_FromUnicode",
 		   ExactSpelling=true, CharSet=CharSet.Unicode)]
 	internal unsafe static extern IntPtr
@@ -771,25 +810,26 @@
 	    return PyUnicode_FromUnicode(s, (s.Length));
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_GetSize",
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyUnicode_GetSize(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_AsUnicode",
 		   ExactSpelling=true)]
 	internal unsafe static extern char *
 	PyUnicode_AsUnicode(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   EntryPoint="PyUnicodeUCS2_AsUnicode",
 		   ExactSpelling=true, CharSet=CharSet.Unicode)]
 	internal unsafe static extern IntPtr
 	PyUnicode_AS_UNICODE(IntPtr op);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
+		   EntryPoint="PyUnicodeUCS2_FromOrdinal",
 		   ExactSpelling=true, CharSet=CharSet.Unicode)]
 	internal unsafe static extern IntPtr 
 	PyUnicode_FromOrdinal(int c);
@@ -816,77 +856,77 @@
 	    return PyObject_TYPE(ob) == Runtime.PyDictType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_New();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDictProxy_New(IntPtr dict);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_GetItem(IntPtr pointer, IntPtr key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_GetItemString(IntPtr pointer, string key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyDict_SetItemString(IntPtr pointer, string key, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyDict_DelItem(IntPtr pointer, IntPtr key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyMapping_HasKey(IntPtr pointer, IntPtr key);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_Keys(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_Values(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_Items(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyDict_Copy(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyDict_Update(IntPtr pointer, IntPtr other);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyDict_Clear(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyDict_Size(IntPtr pointer);
@@ -900,57 +940,57 @@
 	    return PyObject_TYPE(ob) == Runtime.PyListType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyList_New(int size);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyList_AsTuple(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyList_GetItem(IntPtr pointer, int index);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_SetItem(IntPtr pointer, int index, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_Insert(IntPtr pointer, int index, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_Append(IntPtr pointer, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_Reverse(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_Sort(IntPtr pointer);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyList_GetSlice(IntPtr pointer, int start, int end);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyList_Size(IntPtr pointer);
@@ -964,27 +1004,27 @@
 	    return PyObject_TYPE(ob) == Runtime.PyTupleType;
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyTuple_New(int size);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyTuple_GetItem(IntPtr pointer, int index);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyTuple_SetItem(IntPtr pointer, int index, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyTuple_GetSlice(IntPtr pointer, int start, int end);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyTuple_Size(IntPtr pointer);
@@ -994,58 +1034,58 @@
 	// Python module API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern string
 	PyModule_GetName(IntPtr module);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyModule_GetDict(IntPtr module);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern string
 	PyModule_GetFilename(IntPtr module);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyImport_Import(IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyImport_ImportModule(string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyImport_ReloadModule(IntPtr module);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyImport_AddModule(string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyImport_GetModuleDict();
 
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PySys_SetArgv(int argc, IntPtr argv);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PySys_GetObject(string name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PySys_SetObject(string name, IntPtr ob);
@@ -1055,7 +1095,7 @@
 	// Python type object API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern bool 
 	PyType_IsSubtype(IntPtr t1, IntPtr t2);
@@ -1065,77 +1105,77 @@
 	  return (t == tp) || PyType_IsSubtype(t, tp);
 	}
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		   ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyType_GenericAlloc(IntPtr type, int n);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyType_Ready(IntPtr type);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	_PyType_Lookup(IntPtr type, IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyObject_GenericGetAttr(IntPtr obj, IntPtr name);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	_PyObject_GetDictPtr(IntPtr obj);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
-	_PyObject_GC_New(IntPtr tp);
+	PyObject_GC_New(IntPtr tp);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void 
-	_PyObject_GC_Del(IntPtr tp);
+	PyObject_GC_Del(IntPtr tp);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void 
-	_PyObject_GC_Track(IntPtr tp);
+	PyObject_GC_Track(IntPtr tp);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void 
-	_PyObject_GC_UnTrack(IntPtr tp);
+	PyObject_GC_UnTrack(IntPtr tp);
 
 
 	//====================================================================
 	// Python memory API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyMem_Malloc(int size);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyMem_Realloc(IntPtr ptr, int size);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyMem_Free(IntPtr ptr);
@@ -1145,62 +1185,62 @@
 	// Python exception API
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyErr_SetString(IntPtr ob, string message);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyErr_SetObject(IntPtr ob, IntPtr message);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern IntPtr
 	PyErr_SetFromErrno(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern void
 	PyErr_SetNone(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyErr_ExceptionMatches(IntPtr exception);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
 	internal unsafe static extern int
 	PyErr_Occurred();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	PyErr_Clear();
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern void
 	PyErr_Print();
@@ -1210,12 +1250,12 @@
 	// Miscellaneous
 	//====================================================================
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
 	PyMethod_Self(IntPtr ob);
 
-	[DllImport("python22", CallingConvention=CallingConvention.Cdecl,
+	[DllImport("python23", CallingConvention=CallingConvention.Cdecl,
 		    ExactSpelling=true, CharSet=CharSet.Ansi)]
         internal unsafe static extern IntPtr
 	PyMethod_Function(IntPtr ob);


=== PythonNet/src/runtime/TypeManager.cs 1.8 => 1.9 ===
--- PythonNet/src/runtime/TypeManager.cs:1.8	Mon Oct 20 23:05:14 2003
+++ PythonNet/src/runtime/TypeManager.cs	Wed Oct 22 22:53:10 2003
@@ -95,10 +95,6 @@
 	    IntPtr offset = (IntPtr)ObjectOffset.ob_dict;
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_dictoffset, offset);
 
-	    //CopySlot(py_type, type, TypeOffset.tp_hash);
-	    //CopySlot(py_type, type, TypeOffset.tp_weaklistoffset);
-	    //CopySlot(py_type, type, TypeOffset.tp_is_gc);
-
 	    InitializeSlots(type, impl);
 
 	    int flags = TypeFlags.Default;
@@ -109,9 +105,11 @@
 
 	    Runtime.PyType_Ready(type);
 
-	    InitMethods(type, impl);
+	    IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
+	    IntPtr mod = Runtime.PyString_FromString("(clr)");
+	    Runtime.PyDict_SetItemString(dict, "__module__", mod);
 
-	    //DebugUtil.DumpType(type);
+	    InitMethods(type, impl);
 
 	    return type;
 	}
@@ -124,6 +122,10 @@
 	    if (i > -1) {
 		name = name.Substring(i + 1);
 	    }
+	    i = name.LastIndexOf('.');
+	    if (i > -1) {
+		name = name.Substring(i + 1);
+	    }
 
 	    IntPtr base_ = IntPtr.Zero;
 	    if (clrType.BaseType != null) {
@@ -162,6 +164,10 @@
 
 	    Runtime.PyType_Ready(type);
 
+	    IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
+	    string mn = "CLR." + clrType.Namespace;
+	    IntPtr mod = Runtime.PyString_FromString(mn);
+	    Runtime.PyDict_SetItemString(dict, "__module__", mod);
 
 	    // Hide the gchandle of the implementation in a magic type slot.
 	    GCHandle gc = GCHandle.Alloc(impl);
@@ -172,8 +178,6 @@
 	    impl.gcHandle = gc;
 	    impl.pyHandle = type;
 
-	    //DebugUtil.DumpType(type);
-
 	    return type;
 	}
 
@@ -200,8 +204,8 @@
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_);
 	    Runtime.Incref(base_);
 
-	    Marshal.WriteIntPtr(type, TypeOffset.tp_bases, bases);
-	    Runtime.Incref(bases);
+	    //Marshal.WriteIntPtr(type, TypeOffset.tp_bases, bases);
+	    //Runtime.Incref(bases);
 
 	    dict = Runtime.PyDict_Copy(dict);
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_dict, dict);
@@ -218,9 +222,11 @@
 	    CopySlot(base_, type, TypeOffset.tp_clear);
 	    CopySlot(base_, type, TypeOffset.tp_is_gc);
 
-
 	    Runtime.PyType_Ready(type);
 
+	    dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
+	    IntPtr mod = Runtime.PyString_FromString("<clr>");
+	    Runtime.PyDict_SetItemString(dict, "__module__", mod);
 
 	    // for now, move up hidden handle...
 	    IntPtr gc = Marshal.ReadIntPtr(base_, TypeOffset.magic());
@@ -247,60 +253,14 @@
 	    // Copy gc and other type slots from the base Python metatype.
 
 	    CopySlot(py_type, type, TypeOffset.tp_basicsize);
-	    //Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, (IntPtr)0);
-
-	    //CopySlot(py_type, type, TypeOffset.tp_itemsize);
-	    //CopySlot(py_type, type, TypeOffset.tp_compare);
-	    //CopySlot(py_type, type, TypeOffset.tp_hash);
-	    CopySlot(py_type, type, TypeOffset.tp_dictoffset);
-	    CopySlot(py_type, type, TypeOffset.tp_weaklistoffset);
-	    //CopySlot(py_type, type, TypeOffset.tp_traverse);
-	    //CopySlot(py_type, type, TypeOffset.tp_clear);
-	    //CopySlot(py_type, type, TypeOffset.tp_is_gc);
-	    //CopySlot(py_type, type, TypeOffset.tp_repr);
-
-	    //CopySlot(py_type, type, TypeOffset.tp_free);
-
-	    // Override type slots with those of the managed implementation.
-
-	    InitializeSlots(type, impl);
-
-	    int flags = TypeFlags.Default;
-	    flags |= TypeFlags.Managed;
-	    flags |= TypeFlags.HeapType;
-	    flags |= TypeFlags.HaveGC;
-	    Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags);
-
-	    Runtime.PyType_Ready(type);
-
-	    return type;
-	}
-
-
-
-	internal static IntPtr CreateMetaTypeOld(Type impl) {
-
-	    // The managed metatype is functionally little different than the
-	    // standard Python metatype (PyType_Type). It overrides certain of
-	    // the standard type slots, and has to subclass PyType_Type for 
-	    // certain functions in the C runtime to work correctly with it.
-
-	    IntPtr type = AllocateTypeObject("CLR Metatype");
-	    IntPtr py_type = Runtime.PyTypeType;
-
-	    // Copy gc and other type slots from the base Python metatype.
-
-	    CopySlot(py_type, type, TypeOffset.tp_basicsize);
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, (IntPtr)0);
 
-	    CopySlot(py_type, type, TypeOffset.tp_itemsize);
-	    CopySlot(py_type, type, TypeOffset.tp_compare);
-	    CopySlot(py_type, type, TypeOffset.tp_hash);
 	    CopySlot(py_type, type, TypeOffset.tp_dictoffset);
 	    CopySlot(py_type, type, TypeOffset.tp_weaklistoffset);
-	    //CopySlot(py_type, type, TypeOffset.tp_traverse);
-	    //CopySlot(py_type, type, TypeOffset.tp_clear);
-	    //CopySlot(py_type, type, TypeOffset.tp_is_gc);
+
+	    CopySlot(py_type, type, TypeOffset.tp_traverse);
+	    CopySlot(py_type, type, TypeOffset.tp_clear);
+	    CopySlot(py_type, type, TypeOffset.tp_is_gc);
 	    //CopySlot(py_type, type, TypeOffset.tp_repr);
 
 	    //CopySlot(py_type, type, TypeOffset.tp_free);
@@ -313,55 +273,14 @@
 	    flags |= TypeFlags.Managed;
 	    flags |= TypeFlags.HeapType;
 	    flags |= TypeFlags.HaveGC;
-	    flags |= TypeFlags.Ready;
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags);
 
-	    //IntPtr op = Runtime.PyDict_New();
-	    //Marshal.WriteIntPtr(type, TypeOffset.tp_dict, op);
-
 	    Runtime.PyType_Ready(type);
 
-	    InitializeSlots(type, impl);
-
-	    // Set the tp_base, tp_bases and tp_mro work around issues with
-	    // metaclasses. This is needed because Python will not initialize 
-	    // reflected types correctly unless their type is a subtype of 
-	    // the standard metatype. However, erratic things will happen in
-	    // PyType_Ready if you try to subtype PyType_Type :(
-	    // 
-	    // As a workaround, it turns out that PyType_Check determines
-	    // sub-type-ness by looking at the mro, so as long as we add 
-	    // PyType_Type to the end of our mro, we can fool the runtime.
-
-	    IntPtr basetype = Runtime.PyBaseObjectType;
-
-	    Marshal.WriteIntPtr(type, TypeOffset.tp_base, basetype);
-
-	    //temp = Marshal.ReadIntPtr(type, TypeOffset.tp_bases);
-	    //Runtime.PyTuple_SetItem(temp, 0, basetype);
-	    //Runtime.Incref(basetype);
-
-	    IntPtr temp = Runtime.PyTuple_New(1);
-	    Runtime.PyTuple_SetItem(temp, 0, basetype);
-	    Runtime.Incref(basetype);
-
-
-	    temp = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
-	    Runtime.Decref(temp);
-
-	    temp = Runtime.PyTuple_New(3);
-	    Runtime.PyTuple_SetItem(temp, 0, type);
-	    Runtime.PyTuple_SetItem(temp, 1, basetype);
-	    Runtime.PyTuple_SetItem(temp, 2, py_type);
-	    Runtime.Incref(type);
-	    Runtime.Incref(basetype);
-	    Runtime.Incref(py_type);
-
-	    Marshal.WriteIntPtr(type, TypeOffset.tp_mro, temp);
+	    IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
+	    IntPtr mod = Runtime.PyString_FromString("CLR");
+	    Runtime.PyDict_SetItemString(dict, "__module__", mod);
 
-
-	    //DebugUtil.DumpType(Runtime.PyTypeType);
-	    //DebugUtil.DumpType(Runtime.PyBaseObjectType);
 	    //DebugUtil.DumpType(type);
 
 	    return type;
@@ -375,9 +294,15 @@
 	internal static IntPtr AllocateTypeObject(string name) {
 	    IntPtr type = Runtime.PyType_GenericAlloc(Runtime.PyTypeType, 0);
 
-	    // TODO: this will leak for our metatype...
-	    IntPtr temp = Marshal.StringToHGlobalAnsi(name);
+	    // Cheat a little: we'll set tp_name to the internal char * of
+	    // the Python version of the type name - otherwise we'd have to
+	    // allocate the tp_name and would have no way to free it.
+
+	    IntPtr temp = Runtime.PyString_FromString(name);
+	    IntPtr raw = Runtime.PyString_AS_STRING(temp);
+
 	    Marshal.WriteIntPtr(type, TypeOffset.tp_name, temp);
+	    Marshal.WriteIntPtr(type, TypeOffset.name, raw);
 
 	    temp = Runtime.PyString_FromString(name);
 	    Marshal.WriteIntPtr(type, TypeOffset.name, temp);
@@ -450,14 +375,7 @@
 	//====================================================================
 
 	private static void InitMethods(IntPtr pytype, Type type) {
-	    //IntPtr ppdict = Runtime._PyObject_GetDictPtr(pytype);
-	    //IntPtr dict = Marshal.ReadIntPtr(ppdict, 0);
 	    IntPtr dict = Marshal.ReadIntPtr(pytype, TypeOffset.tp_dict);
-
-	    if (dict == IntPtr.Zero) {
-		DebugUtil.Print("null dict for: ", pytype);
-	    }
-
 	    Type marker = typeof(PythonMethodAttribute);
 
 	    BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
@@ -473,7 +391,7 @@
 			mi[0] = method;
 			MethodObject m = new TypeMethod(method_name, mi);
 			Runtime.PyDict_SetItemString(dict, method_name,
-						     m.Handle);
+						     m.pyHandle);
 		    }
 		}
 		type = type.BaseType;
@@ -489,28 +407,6 @@
 	    IntPtr fp = Marshal.ReadIntPtr(from, offset);
 	    Marshal.WriteIntPtr(to, offset, fp);
 	}
-
-
-
-
-//  	internal static void AddDict(IntPtr type) {
-//  	    IntPtr op = Runtime.PyDict_New();
-//  	    Marshal.WriteIntPtr(type, TypeOffset.tp_dict, op);
-//  	}
-
-
-
-//  	internal static void MyReady(IntPtr type) {
-//  	    int flags = (int)Marshal.ReadIntPtr(type, TypeOffset.tp_flags);
-//  	    flags |= TypeFlags.Ready;
-//  	    Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags);
-
-//  	    IntPtr op = Runtime.PyDict_New();
-//  	    Marshal.WriteIntPtr(type, TypeOffset.tp_dict, op);
-
-
-//  	}
-
 
 
     }




More information about the Zope-CVS mailing list