[Zope-CVS] CVS: PythonNet/src - AssemblyManager.cs:1.2 CallbackThunks.cs:1.2 ClassBase.cs:1.2 CodeGenerator.cs:1.2 Converter.cs:1.2 Exceptions.cs:1.2 InterfaceObject.cs:1.2 ManagedType.cs:1.2 MetaType.cs:1.2 MethodBinder.cs:1.2 MethodObject.cs:1.2 MethodWrapper.cs:1.2 PythonException.cs:1.2 PythonInterpreter.cs:1.2 Runtime.cs:1.2 TypeGenerator.cs:1.2 TypeManager.cs:1.2 TypeMethod.cs:1.2 CastHelper.cs:NONE PyDict.cs:NONE PyFloat.cs:NONE PyInteger.cs:NONE PyList.cs:NONE PyLong.cs:NONE PyModule.cs:NONE PyNumber.cs:NONE PyObject.cs:NONE PySequence.cs:NONE PyString.cs:NONE PyTuple.cs:NONE

Brian Lloyd brian@zope.com
Mon, 14 Jul 2003 14:34:58 -0400


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

Modified Files:
	AssemblyManager.cs CallbackThunks.cs ClassBase.cs 
	CodeGenerator.cs Converter.cs Exceptions.cs InterfaceObject.cs 
	ManagedType.cs MetaType.cs MethodBinder.cs MethodObject.cs 
	MethodWrapper.cs PythonException.cs PythonInterpreter.cs 
	Runtime.cs TypeGenerator.cs TypeManager.cs TypeMethod.cs 
Removed Files:
	CastHelper.cs PyDict.cs PyFloat.cs PyInteger.cs PyList.cs 
	PyLong.cs PyModule.cs PyNumber.cs PyObject.cs PySequence.cs 
	PyString.cs PyTuple.cs 
Log Message:
checkin decoy removal from last week

=== PythonNet/src/AssemblyManager.cs 1.1 => 1.2 ===
--- PythonNet/src/AssemblyManager.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/AssemblyManager.cs	Mon Jul 14 14:34:09 2003
@@ -16,8 +16,9 @@
 namespace Python.Runtime {
 
     /// <summary>
-    /// Manages the tracking of assemblies and namespaces and provides a
-    /// simplified internal interface for finding and obtaining Types.
+    /// The AssemblyManager maintains information about the assemblies and 
+    /// namespaces that have been loaded, and provides a simplified internal 
+    /// interface for finding and obtaining Type objects by qualified names.
     /// </summary>
 
     internal class AssemblyManager {
@@ -47,8 +48,11 @@
 	}
 
 	//===================================================================
-	// Event handler for assembly load events. This ensures that we
-	// can track all assemblies loaded into the running app domain.
+	// Event handler for assembly load events. At the time the Python 
+	// runtime loads, we scan the app domain to map the assemblies that
+	// are loaded at the time. We also have to register this event handler
+	// so that we can know about assemblies that get loaded after the 
+	// Python runtime is initialized.
 	//===================================================================
 
 	static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args){


=== PythonNet/src/CallbackThunks.cs 1.1 => 1.2 ===
--- PythonNet/src/CallbackThunks.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/CallbackThunks.cs	Mon Jul 14 14:34:09 2003
@@ -12,6 +12,7 @@
 using System;
 using System.Collections;
 using System.Runtime.InteropServices;
+using System.Reflection;
 
 namespace Python.Runtime {
 
@@ -38,7 +39,7 @@
 	public IntPtr ob_refcnt;
 	public IntPtr ob_type;
 	public IntPtr ob_data;
-	public IntPtr ob_dict;
+	// public IntPtr ob_dict;
     }
 
 
@@ -196,13 +197,18 @@
 
 
 
+    // Get thunk should be here, not in type gen / manager!
+
     // This class defines the function prototypes (delegates) used for low
     // level integration with the CPython runtime. It also provides name 
     // based lookup of the correct prototype for a particular slot name.
 
     internal class Prototypes {
 
+
+	static ArrayList keepAlive;
 	static Hashtable pmap;
+ 	static IntPtr temp;
 
 	static Prototypes() {
 
@@ -217,6 +223,8 @@
 		p[item.Name] = item;
 	    }
 
+	    keepAlive = new ArrayList();
+	    temp = Marshal.AllocHGlobal(IntPtr.Size);
 	    pmap = new Hashtable();
 
 	    pmap["tp_dealloc"] = p["DestructorFunc"];
@@ -307,6 +315,22 @@
 	    return pmap[name] as Type;
 	}
 
+
+	internal static IntPtr GetThunk(MethodInfo method) {
+	    // WARNING: this probably needs a thread lock!
+	    //Type dt = typeof(CallbackThunks).GetNestedType(method.Name);
+	    Type dt = Prototypes.GetPrototype(method.Name);
+	    if (dt != null) {
+		Delegate d = Delegate.CreateDelegate(dt, method);
+		CallbackThunk cb = new CallbackThunk(d);
+		Marshal.StructureToPtr(cb, temp, false);
+		IntPtr fp = Marshal.ReadIntPtr(temp);
+		keepAlive.Add(d);
+		return fp;
+	    }
+	    return IntPtr.Zero;
+	}
+
 	[CallConvCdecl()]
 	public delegate IntPtr UnaryFunc(IntPtr ob);
 
@@ -467,94 +491,6 @@
 	    fn = d;
 	}
     }
-
-
-    // Bleah. We can't call function pointers directly from the CLR.
-    // This lets us call certain type slots by wrapping the slot in
-    // a PyCFunction and invoking it through the Python runtime.
-
-    internal class SlotMethod {
-
-	public static IntPtr mdef;
-
-	static SlotMethod() {
-	    mdef = Marshal.AllocHGlobal(4 * IntPtr.Size);
-	}
-
-	public static IntPtr Call(IntPtr fn, IntPtr self, IntPtr args) { 
-	    Marshal.WriteIntPtr(mdef, (1 * IntPtr.Size), fn);
-	    Marshal.WriteIntPtr(mdef, (2 * IntPtr.Size), (IntPtr)0x0001);
-	    IntPtr func = Runtime.PyCFunction_New(mdef, self);
-	    IntPtr result = Runtime.PyObject_Call(func, args, IntPtr.Zero);
-	    Runtime.Decref(func);
-	    return result;
-	}
-
-	public static IntPtr Call(IntPtr fn, IntPtr self, IntPtr args, 
-				  IntPtr kw) { 
-	    Marshal.WriteIntPtr(mdef, (1 * IntPtr.Size), fn);
-	    Marshal.WriteIntPtr(mdef, (2 * IntPtr.Size), (IntPtr)0x0002);
-	    IntPtr func = Runtime.PyCFunction_New(mdef, self);
-	    IntPtr result = Runtime.PyObject_Call(func, args, kw);
-	    Runtime.Decref(func);
-	    return result;
-	}
-
-	public static IntPtr Call(IntPtr fn, IntPtr self) { 
-	    Marshal.WriteIntPtr(mdef, (1 * IntPtr.Size), fn);
-	    Marshal.WriteIntPtr(mdef, (2 * IntPtr.Size), (IntPtr)0x0004);
-	    IntPtr args = Runtime.PyTuple_New(0);
-	    IntPtr func = Runtime.PyCFunction_New(mdef, self);
-	    IntPtr result = Runtime.PyObject_Call(func, args, IntPtr.Zero);
-	    Runtime.Decref(func);
-	    Runtime.Decref(args);
-	    return result;
-	}
-
-    }
-
-
-    // A NativeMethod object wraps a (static) managed method, making it
-    // look like a PyCFunction object. This is used mainly to implement
-    // the CLR import hook.
-
-    internal class NativeMethod {
-
-	public Delegate mDelegate;
-	public IntPtr methodDef;
-	public IntPtr pyHandle;
-
-	public NativeMethod(Type obType, string name) {
-
-	    // Allocate and initialize a PyMethodDef structure to represent 
-	    // the managed method, then create a PyCFunction. The PyMethodDef 
-	    // will be cleaned up when the NativeMethod is garbage-collected.
-
-	    mDelegate = Delegate.CreateDelegate(typeof(CallbackThunks.generic),
-						obType.GetMethod(name)
-						);
-	    CallbackThunk cb = new CallbackThunk(mDelegate);
-	    IntPtr pThunk = Marshal.AllocHGlobal(IntPtr.Size);
-	    Marshal.StructureToPtr(cb, pThunk, false);
-	    IntPtr fp = Marshal.ReadIntPtr(pThunk);
-	    Marshal.FreeHGlobal(pThunk);
-
-	    methodDef = Runtime.PyMem_Malloc(4 * IntPtr.Size);
-	    Marshal.WriteIntPtr(methodDef, Marshal.StringToHGlobalAnsi(name));
-	    Marshal.WriteIntPtr(methodDef, (1 * IntPtr.Size), fp);
-	    Marshal.WriteIntPtr(methodDef, (2 * IntPtr.Size), (IntPtr)0x0002);
-	    Marshal.WriteIntPtr(methodDef, (3 * IntPtr.Size), IntPtr.Zero);
-	    pyHandle = Runtime.PyCFunction_New(methodDef, IntPtr.Zero);
-
-	}
-
-	public IntPtr Call(IntPtr args, IntPtr kw) {
-	    return Runtime.PyCFunction_Call(pyHandle, args, kw);
-	}
-
-    }
-
-
 
 
 


=== PythonNet/src/ClassBase.cs 1.1 => 1.2 ===
--- PythonNet/src/ClassBase.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/ClassBase.cs	Mon Jul 14 14:34:09 2003
@@ -50,11 +50,9 @@
 	    Hashtable methods = new Hashtable();
 	    IntPtr pp = Runtime._PyObject_GetDictPtr(this.tpHandle);
 	    IntPtr op = Marshal.ReadIntPtr(pp);
+	    IntPtr dict = op;
 
-
-	    PyDict dict = new PyDict(op);
 	    Type type = this.type;
-
 	    ArrayList list;
 	    MethodInfo mInfo;
 	    String name;
@@ -116,7 +114,8 @@
 		    if (!(mm.IsPublic || mm.IsFamily || mm.IsFamilyOrAssembly))
 			continue;
 		    mt = new PropertyObject((PropertyInfo) mi);
-		    dict[mi.Name] = (PyObject) mt;
+
+		    Runtime.PyDict_SetItemString(dict, mi.Name, mt.Handle);
 		    continue;
 
 	        case MemberTypes.Field:
@@ -124,12 +123,12 @@
 		    if (!(fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly))
 			continue;
 		    mt = new FieldObject((FieldInfo) mi);
-		    dict[mi.Name] = (PyObject) mt;
+		    Runtime.PyDict_SetItemString(dict, mi.Name, mt.Handle);
 		    continue;
 
 	        case MemberTypes.Event:
 		    mt = new EventObject((EventInfo) mi);
-		    dict[mi.Name] = (PyObject) mt;
+		    Runtime.PyDict_SetItemString(dict, mi.Name, mt.Handle);
 		    continue;
 
 	        case MemberTypes.NestedType:
@@ -138,7 +137,7 @@
 			  tp.IsNestedFamORAssem))
 			continue;
 		    mt = ClassManager.GetClass(tp);
-		    dict[mi.Name] = (PyObject) mt;
+		    Runtime.PyDict_SetItemString(dict, mi.Name, mt.Handle);
 		    continue;
 
 	        case MemberTypes.TypeInfo:
@@ -161,7 +160,7 @@
 		MethodInfo[] mlist = (MethodInfo[])list.ToArray(typeof(MethodInfo));
 
 		mt = new MethodObject(name, mlist);
-		dict[name] = (PyObject) mt;
+		Runtime.PyDict_SetItemString(dict, name, mt.Handle);
 
 	    }
 	}
@@ -180,6 +179,7 @@
 	    CLRObject co2 = GetManagedObject(other) as CLRObject;
 	    Object o1 = co1.inst;
 	    Object o2 = co2.inst;
+	    // Console.WriteLine("cmp: {0} {1}", o1, o2);
 	    if (Object.Equals(o1, o2)) {
 		return 0;
 	    }


=== PythonNet/src/CodeGenerator.cs 1.1 => 1.2 ===
--- PythonNet/src/CodeGenerator.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/CodeGenerator.cs	Mon Jul 14 14:34:09 2003
@@ -42,7 +42,7 @@
 	}
 
 	//====================================================================
-	/// DefineType is a shortcut utility to get a new TypeBuilder.
+	// DefineType is a shortcut utility to get a new TypeBuilder.
 	//====================================================================
 
 	internal static TypeBuilder DefineType(string name) {
@@ -51,7 +51,7 @@
 	}
 
 	//====================================================================
-	/// DefineType is a shortcut utility to get a new TypeBuilder.
+	// DefineType is a shortcut utility to get a new TypeBuilder.
 	//====================================================================
 
 	internal static TypeBuilder DefineType(string name, Type basetype) {


=== PythonNet/src/Converter.cs 1.1 => 1.2 ===
--- PythonNet/src/Converter.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/Converter.cs	Mon Jul 14 14:34:09 2003
@@ -35,16 +35,6 @@
 	}
 
 
-//  	internal static IntPtr ToPython(Object value) {
-//  	    if (value == null) {
-//  		IntPtr result = Runtime.PyNone;
-//  		Runtime.Incref(result);
-//  		return result;
-//  	    }
-//  	    return ToPython(value, value.GetType());
-//  	}
-
-
 	//====================================================================
 	// Return a Python object for the given native object, converting
 	// basic types (string, int, etc.) into equivalent Python objects.
@@ -55,6 +45,8 @@
 	internal static IntPtr ToPython(Object value, Type type) {
 	    IntPtr result = IntPtr.Zero;
 
+	    // Null always converts to None in Python.
+
 	    if (value == null) {
 		result = Runtime.PyNone;
 		Runtime.Incref(result);
@@ -176,7 +168,7 @@
 	static bool ToPrimitive(IntPtr value, Type obType, out Object result, 
 				bool setError) {
 
-	    PyObject overflow = Exceptions.OverflowError;
+	    IntPtr overflow = Exceptions.OverflowError;
 	    TypeCode tc = Type.GetTypeCode(obType);
 	    result = null;
 	    IntPtr op;


=== PythonNet/src/Exceptions.cs 1.1 => 1.2 ===
--- PythonNet/src/Exceptions.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/Exceptions.cs	Mon Jul 14 14:34:09 2003
@@ -22,22 +22,19 @@
 
 	private Exceptions() {}
 
-	internal static void Initialize() {
-	    // TODO: fix this to use PyObject wrappers correctly (refs!).
+	// This is called when the Python runtime is intitialized. It 
+	// uses reflection to populate static fields that expose handles
+	// to the standard Python exception types.
 
-	    // This is called when the Python runtime is intitialized. It 
-	    // uses reflection to generate PyObject instances to wrap the
-	    // standard Python exception types.
+	internal static void Initialize() {
 	    IntPtr module = Runtime.PyImport_ImportModule("exceptions");
+	    Type type = typeof(Exceptions);
 
-	    Type tp = typeof(Exceptions);
-	    foreach (FieldInfo fi in tp.GetFields(BindingFlags.Public | 
-						  BindingFlags.Static)) {
+	    foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | 
+						    BindingFlags.Static)) {
 		IntPtr op = Runtime.PyObject_GetAttrString(module, fi.Name);
 		if (op != IntPtr.Zero) {
-		    // owned reference
-		    PyObject ob = new PyObject(op);
-		    fi.SetValue(tp, ob);
+		    fi.SetValue(type, op);
 		}
 	    }
 	    Runtime.Decref(module);
@@ -68,8 +65,8 @@
 	/// Python object. This is a wrapper for PyErr_ExceptionMatches.
 	/// </remarks>
 
-	public static bool ExceptionMatches(PyObject ob) {
-	    return Runtime.PyErr_ExceptionMatches(ob.Handle) != 0;
+	public static bool ExceptionMatches(IntPtr ob) {
+	    return Runtime.PyErr_ExceptionMatches(ob) != 0;
 	}
 
 	/// <summary>
@@ -81,8 +78,8 @@
 	/// Python object. This is a wrapper for PyErr_GivenExceptionMatches.
 	/// </remarks>
 
-	public static bool ExceptionMatches(PyObject exc, PyObject ob) {
-	    int i = Runtime.PyErr_GivenExceptionMatches(exc.Handle, ob.Handle);
+	public static bool ExceptionMatches(IntPtr exc, IntPtr ob) {
+	    int i = Runtime.PyErr_GivenExceptionMatches(exc, ob);
 	    return (i != 0);
 	}
 
@@ -95,8 +92,8 @@
 	/// This is a wrapper for the Python PyErr_SetString call.
 	/// </remarks>
 
-	public static void SetError(PyObject ob, string value) {
-	    Runtime.PyErr_SetString(ob.Handle, value);
+	public static void SetError(IntPtr ob, string value) {
+	    Runtime.PyErr_SetString(ob, value);
 	}
 
 	/// <summary>
@@ -108,8 +105,8 @@
 	/// This is a wrapper for the Python PyErr_SetObject call.
 	/// </remarks>
 
-	public static void SetError(PyObject ob, PyObject value) {
-	    Runtime.PyErr_SetObject(ob.Handle, value.Handle);
+	public static void SetError(IntPtr ob, IntPtr value) {
+	    Runtime.PyErr_SetObject(ob, value);
 	}
 
 	/// <summary>
@@ -123,10 +120,9 @@
 	/// </remarks>
 
 	public static void SetError(Exception e) {
-	  Runtime.PyErr_Clear();
+	    Runtime.PyErr_Clear();
 	    IntPtr op = CLRObject.GetInstHandle(e);
 	    Runtime.Incref(op);
-	    Runtime.Incref(op);
 	    Runtime.PyErr_SetString(op, e.Message);
 	}
 
@@ -139,9 +135,9 @@
 	/// This is a wrapper for the Python PyErr_SetFromErrno call.
 	/// </remarks>
 
-	public static void SetFromErrno(PyObject ob) {
-	    Runtime.PyErr_SetFromErrno(ob.Handle);
-	}
+	//public static void SetFromErrno(PyObject ob) {
+	//    Runtime.PyErr_SetFromErrno(ob.Handle);
+	//}
 
 	/// <summary>
 	/// ErrorOccurred Method
@@ -177,50 +173,50 @@
 	/// This is a wrapper for the Python PyErr_Restore call.
 	/// </remarks>
 
-	public static void Restore(PyObject type, PyObject val, PyObject tb) {
-	    Runtime.PyErr_Restore(type.Handle, val.Handle, tb.Handle);
-	}
-
-
-	public static PyObject ArithmeticError;
-	public static PyObject AssertionError;
-	public static PyObject AttributeError;
-	public static PyObject DeprecationWarning;
-	public static PyObject EOFError;
-	public static PyObject EnvironmentError;
-	public static PyObject Exception;
-	public static PyObject FloatingPointError;
-	public static PyObject IOError;
-	public static PyObject ImportError;
-	public static PyObject IndentationError;
-	public static PyObject IndexError;
-	public static PyObject KeyError;
-	public static PyObject KeyboardInterrupt;
-	public static PyObject LookupError;
-	public static PyObject MemoryError;
-	public static PyObject NameError;
-	public static PyObject NotImplementedError;
-	public static PyObject OSError;
-	public static PyObject OverflowError;
-	public static PyObject OverflowWarning;
-	public static PyObject ReferenceError;
-	public static PyObject RuntimeError;
-	public static PyObject RuntimeWarning;
-	public static PyObject StandardError;
-	public static PyObject StopIteration;
-	public static PyObject SyntaxError;
-	public static PyObject SyntaxWarning;
-	public static PyObject SystemError;
-	public static PyObject SystemExit;
-	public static PyObject TabError;
-	public static PyObject TypeError;
-	public static PyObject UnboundLocalError;
-	public static PyObject UnicodeError;
-	public static PyObject UserWarning;
-	public static PyObject ValueError;
-	public static PyObject Warning;
-	public static PyObject WindowsError;
-	public static PyObject ZeroDivisionError;
+	//public static void Restore(PyObject type, PyObject val, PyObject tb) {
+	//Runtime.PyErr_Restore(type.Handle, val.Handle, tb.Handle);
+	//}
+
+
+	public static IntPtr ArithmeticError;
+	public static IntPtr AssertionError;
+	public static IntPtr AttributeError;
+	public static IntPtr DeprecationWarning;
+	public static IntPtr EOFError;
+	public static IntPtr EnvironmentError;
+	public static IntPtr Exception;
+	public static IntPtr FloatingPointError;
+	public static IntPtr IOError;
+	public static IntPtr ImportError;
+	public static IntPtr IndentationError;
+	public static IntPtr IndexError;
+	public static IntPtr KeyError;
+	public static IntPtr KeyboardInterrupt;
+	public static IntPtr LookupError;
+	public static IntPtr MemoryError;
+	public static IntPtr NameError;
+	public static IntPtr NotImplementedError;
+	public static IntPtr OSError;
+	public static IntPtr OverflowError;
+	public static IntPtr OverflowWarning;
+	public static IntPtr ReferenceError;
+	public static IntPtr RuntimeError;
+	public static IntPtr RuntimeWarning;
+	public static IntPtr StandardError;
+	public static IntPtr StopIteration;
+	public static IntPtr SyntaxError;
+	public static IntPtr SyntaxWarning;
+	public static IntPtr SystemError;
+	public static IntPtr SystemExit;
+	public static IntPtr TabError;
+	public static IntPtr TypeError;
+	public static IntPtr UnboundLocalError;
+	public static IntPtr UnicodeError;
+	public static IntPtr UserWarning;
+	public static IntPtr ValueError;
+	public static IntPtr Warning;
+	public static IntPtr WindowsError;
+	public static IntPtr ZeroDivisionError;
 
     }
 


=== PythonNet/src/InterfaceObject.cs 1.1 => 1.2 ===
--- PythonNet/src/InterfaceObject.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/InterfaceObject.cs	Mon Jul 14 14:34:09 2003
@@ -54,7 +54,7 @@
 
 	    if (obj.GetType() != type) {
 		// this probably isn't needed anymore...
-		obj = CastHelper.CastObject(obj, type);
+		//obj = CastHelper.CastObject(obj, type);
 	    }
 
 	    IntPtr op = CLRObject.GetInstHandle(obj, self.pyHandle);


=== PythonNet/src/ManagedType.cs 1.1 => 1.2 ===
--- PythonNet/src/ManagedType.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/ManagedType.cs	Mon Jul 14 14:34:09 2003
@@ -99,13 +99,6 @@
 	    return (result != null);
 	}
 
-
-
-
-	public static explicit operator PyObject (ManagedType ob) {
-	    return new PyObject(ob.pyHandle);
-	}
-
     }
 
 }


=== PythonNet/src/MetaType.cs 1.1 => 1.2 ===
--- PythonNet/src/MetaType.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/MetaType.cs	Mon Jul 14 14:34:09 2003
@@ -24,7 +24,7 @@
     
     internal class MetaType : ManagedType {
 
-	static Type delegateType;
+	// static Type delegateType;
 	static IntPtr PyCLRMetaType;
 	static IntPtr stdflags;
 	static ArrayList dList;


=== PythonNet/src/MethodBinder.cs 1.1 => 1.2 ===
--- PythonNet/src/MethodBinder.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/MethodBinder.cs	Mon Jul 14 14:34:09 2003
@@ -24,16 +24,16 @@
 
     internal class MethodBinder {
 
-	MethodInfo info;
+	// MethodInfo info;
 	ArrayList list;
 
 	internal MethodBinder () {
-	    this.info = null;
+	    // this.info = null;
 	    this.list = new ArrayList();
 	}
 	
 	internal MethodBinder(MethodInfo mi) : base () {
-	    this.info = null;
+	    // this.info = null;
 	    this.list = new ArrayList();
 	    this.list.Add(mi);
 	}


=== PythonNet/src/MethodObject.cs 1.1 => 1.2 ===
--- PythonNet/src/MethodObject.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/MethodObject.cs	Mon Jul 14 14:34:09 2003
@@ -18,7 +18,6 @@
     //========================================================================
     // Implements a Python type that provides access to CLR object methods.
     //========================================================================
-    // todo: decref unbound on dealloc
 
     internal class MethodObject : ExtensionType {
 


=== PythonNet/src/MethodWrapper.cs 1.1 => 1.2 ===
--- PythonNet/src/MethodWrapper.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/MethodWrapper.cs	Mon Jul 14 14:34:09 2003
@@ -41,9 +41,11 @@
 
 	    // Currently, these are never released. need to think harder.
 
-	    mDelegate = Delegate.CreateDelegate(typeof(CallbackThunks.generic),
-						obType.GetMethod(name)
-						);
+	    mDelegate = Delegate.CreateDelegate(
+				 typeof(Prototypes.TernaryFunc), 
+				 //CallbackThunks.generic),
+				 obType.GetMethod(name)
+				 );
 	    CallbackThunk cb = new CallbackThunk(mDelegate);
 	    IntPtr pThunk = Marshal.AllocHGlobal(IntPtr.Size);
 	    Marshal.StructureToPtr(cb, pThunk, false);


=== PythonNet/src/PythonException.cs 1.1 => 1.2 ===
--- PythonNet/src/PythonException.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/PythonException.cs	Mon Jul 14 14:34:09 2003
@@ -62,9 +62,9 @@
 	/// Returns the exception type as a Python object.
 	/// </remarks>
 
-	public PyObject Type {
+	public IntPtr Type {
 	    get {
-		return null;
+		return IntPtr.Zero;
 	    }
 	}
 
@@ -76,9 +76,9 @@
 	/// Returns the exception value as a Python object.
 	/// </remarks>
 
-	public PyObject Value {
+	public IntPtr Value {
 	    get {
-		return null;
+		return IntPtr.Zero;
 	    }
 	}
 
@@ -90,9 +90,9 @@
 	/// Returns the exception traceback as a Python object.
 	/// </remarks>
 
-	public PyObject Traceback {
+	public IntPtr Traceback {
 	    get {
-		return null;
+		return IntPtr.Zero;
 	    }
 	}
 
@@ -135,8 +135,8 @@
 	/// PythonException instance matches the given exception type.
 	/// </remarks>
 
-	public static bool Matches(PyObject ob) {
-	    return Runtime.PyErr_ExceptionMatches(ob.Handle) != 0;
+	public static bool Matches(IntPtr ob) {
+	    return Runtime.PyErr_ExceptionMatches(ob) != 0;
 	}
 
     } 


=== PythonNet/src/PythonInterpreter.cs 1.1 => 1.2 ===
--- PythonNet/src/PythonInterpreter.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/PythonInterpreter.cs	Mon Jul 14 14:34:09 2003
@@ -10,6 +10,7 @@
 // FOR A PARTICULAR PURPOSE.
 
 using System;
+using System.Threading;
 using System.Collections;
 
 namespace Python.Runtime {
@@ -17,56 +18,83 @@
 
     public class PythonInterpreter {
 
+	private static Hashtable threads;
 	public static bool initialized;
 
-	//private static IntPtr mainThread;
-	//private static Hashtable threads;
-
 	public static void Initialize() {
 	    if (!initialized) {
 		Runtime.Initialize();
+
+		threads = new Hashtable();
+		IntPtr ts = Runtime.PyThreadState_Get();
+		threads[Thread.CurrentThread] = ts;
+
 		initialized = true;
 	    }
 	}
 
+	public static void Finalize() {
+	    if (initialized) {
+		Runtime.Py_Finalize();
+		initialized = false;
+	    }
+	}
 
-	public static void TestInit() {
-	    /*
-
-	      First time decref on a gc-aware object:
-	        PyObject_GC_UnTrack(ob)
-
-
-	     */
-	    Runtime.Py_Initialize();
-	    initialized = true;
-
-	    // always causes segfault
-	    IntPtr d = Runtime.PyDict_New();
-	    Runtime.Decref(d);
-
-	    IntPtr t = Runtime.PyTuple_New(0);
-	    Runtime.Decref(t);
 
-	    // this always works (non-gc aware)
-	    IntPtr i = Runtime.PyInt_FromLong(550);
-	    Runtime.Decref(i);
+	// NOTE: all of the thread state stuff is just notes to myself
+	// at the moment... Implementing async delegates will help to 
+	// sort it out.
+
+	//====================================================================
+	// Register the calling thread with the interpreter.
+	//====================================================================
+
+	public static void RegisterThread() {
+	    IntPtr ts = Runtime.PyThreadState_Get();
+	    Thread t = Thread.CurrentThread;
+	    threads[t] = ts;
+	}
 
-	    IntPtr l = Runtime.PyLong_FromLong(550);
-	    Runtime.Decref(l);
+	
+	//====================================================================
+	// Finalize a thread finished with the interpreter.
+	//====================================================================
 
-    }
+	public static void FinalizeThread() {
+	    /*
+	    IntPtr threadState = (IntPtr)threads[Thread.CurrentThread];
+	    if (threadState == null) {
+		// ???
+	    }
+	    Runtime.PyEval_AcquireLock();
+	    Runtime.PyThreadState_Swap(IntPtr.Zero);
+	    Runtime.PyThreadState_Clear(threadState);
+	    Runtime.PyThreadState_Delete(threadState);
+	    // remove it!
+	    Runtime.PyEval_ReleaseLock();
+	    */
+	}
 
 
+	//====================================================================
+	// Acquire the Python global interpreter lock.
+	//====================================================================
 
-	public static void Finalize() {
-	    if (initialized) {
-		Runtime.Py_Finalize();
-		initialized = false;
+	public static void AcquireLock() {
+	    Object o = threads[Thread.CurrentThread];
+	    if (o != null) {
+		return;
 	    }
+	    Runtime.PyEval_AcquireLock();
+	    
 	}
 
 
+
+	//====================================================================
+	// Interpreter properties
+	//====================================================================
+
 	public static bool IsInitialized {
 	    get {
 		return initialized;
@@ -105,84 +133,51 @@
 	    }
 	}
 
-	public static string Platform {
-	    get { 
-		return Runtime.Py_GetPlatform(); 
-	    }
-	}
-
-	public static string Copyright {
+	public static string BuildInfo {
 	    get { 
-		return Runtime.Py_GetCopyright(); 
+		return Runtime.Py_GetBuildInfo(); 
 	    }
 	}
 
-	public static string Compiler {
+	public static string Platform {
 	    get { 
-		return Runtime.Py_GetCompiler(); 
+		return Runtime.Py_GetPlatform(); 
 	    }
 	}
 
-	public static string BuildInfo {
+	public static string Copyright {
 	    get { 
-		return Runtime.Py_GetBuildInfo(); 
+		return Runtime.Py_GetCopyright(); 
 	    }
 	}
 
 
-	// TODO: support InitThreads, etc.
-
-	/*
-	  public void InitThreads() {}
-
-	  public static void RegisterThread() {
-	  IntPtr threadState = threads.Get(Thread.CurrentThread);
-	  if (threadState != null) {
-	  return;
-	  }
-	  Runtime.PyEval_AcquireLock();
-	
-	  }
-
-	  public static void FinalizeThread() {
-	  IntPtr threadState = threads.Get(Thread.CurrentThread);
-	  if (threadState == null) {
-	  throw
-	  }
-	  Runtime.PyEval_AcquireLock();
-	  Runtime.PyThreadState_Swap(IntPtr.Zero);
-	  Runtime.PyThreadState_Clear(threadState);
-	  Runtime.PyThreadState_Delete(threadState);
-	  // remove it!
-	  Runtime.PyEval_ReleaseLock();
-	  }
 
-	*/
 
 
 	public static int RunSimpleString(string code) {
 	    return Runtime.PyRun_SimpleString(code);
 	}
 
-	public static PyModule ImportModule(string name) {
-	    PyString moduleName = new PyString(name);
-	    IntPtr pointer = Runtime.PyImport_Import(moduleName.Handle);
-	    return new PyModule(pointer);
-	}
-
-	public static PyModule ReloadModule(PyModule module) {
-	    IntPtr pointer = Runtime.PyImport_ReloadModule(module.Handle);
-	    return new PyModule(pointer);
-	}
-
-	public static PyModule AddModule(string name) {
-	    IntPtr result = Runtime.PyImport_AddModule(name);
-	    if (result == IntPtr.Zero) {
-		throw new PythonException();
-	    }
-	    Runtime.Incref(result);
-	    return new PyModule(result);
-	}
+//  	public static PyModule ImportModule(string name) {
+//  	    PyString moduleName = new PyString(name);
+//  	    IntPtr pointer = Runtime.PyImport_Import(moduleName.Handle);
+//  	    return new PyModule(pointer);
+//  	}
+
+//  	public static PyModule ReloadModule(PyModule module) {
+//  	    IntPtr pointer = Runtime.PyImport_ReloadModule(module.Handle);
+//  	    return new PyModule(pointer);
+//  	}
+
+//  	public static PyModule AddModule(string name) {
+//  	    IntPtr result = Runtime.PyImport_AddModule(name);
+//  	    if (result == IntPtr.Zero) {
+//  		throw new PythonException();
+//  	    }
+//  	    Runtime.Incref(result);
+//  	    return new PyModule(result);
+//  	}
 
     }
 


=== PythonNet/src/Runtime.cs 1.1 => 1.2 ===
--- PythonNet/src/Runtime.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/Runtime.cs	Mon Jul 14 14:34:09 2003
@@ -180,6 +180,10 @@
 	    return Marshal.PtrToStringAnsi(ppName);
 	}
 
+
+
+
+
 	internal static IntPtr PyModuleType;
 	internal static IntPtr PyClassType;
 	internal static IntPtr PyInstanceType;


=== PythonNet/src/TypeGenerator.cs 1.1 => 1.2 ===
--- PythonNet/src/TypeGenerator.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/TypeGenerator.cs	Mon Jul 14 14:34:09 2003
@@ -56,19 +56,19 @@
 	    return IntPtr.Zero;
 	}
 
-	private static IntPtr GetThunk(MethodInfo method) {
-	    //Type dt = typeof(CallbackThunks).GetNestedType(method.Name);
-	    Type dt = Prototypes.GetPrototype(method.Name);
-	    if (dt != null) {
-		Delegate d = Delegate.CreateDelegate(dt, method);
-		CallbackThunk cb = new CallbackThunk(d);
-		Marshal.StructureToPtr(cb, p_thunk, false);
-		IntPtr fp = Marshal.ReadIntPtr(p_thunk);
-		alive.Add(d);
-		return fp;
-	    }
-	    return IntPtr.Zero;
-	}
+//  	private static IntPtr GetThunk(MethodInfo method) {
+//  	    //Type dt = typeof(CallbackThunks).GetNestedType(method.Name);
+//  	    Type dt = Prototypes.GetPrototype(method.Name);
+//  	    if (dt != null) {
+//  		Delegate d = Delegate.CreateDelegate(dt, method);
+//  		CallbackThunk cb = new CallbackThunk(d);
+//  		Marshal.StructureToPtr(cb, p_thunk, false);
+//  		IntPtr fp = Marshal.ReadIntPtr(p_thunk);
+//  		alive.Add(d);
+//  		return fp;
+//  	    }
+//  	    return IntPtr.Zero;
+//  	}
 
 
 	// Given a PyTypeObject instance, fill the slot pointer members of
@@ -92,7 +92,7 @@
 		    FieldInfo fi = typedesc.GetField(name);
 		    IntPtr value = (IntPtr) fi.GetValue(typeObj);
 		    if ((fi != null) && (value == IntPtr.Zero)) {
-			fi.SetValue(typeObj, GetThunk(method));
+			fi.SetValue(typeObj, Prototypes.GetThunk(method));
 		    }
 		}
 		type = type.BaseType;


=== PythonNet/src/TypeManager.cs 1.1 => 1.2 ===
--- PythonNet/src/TypeManager.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/TypeManager.cs	Mon Jul 14 14:34:09 2003
@@ -22,7 +22,7 @@
 
     //=======================================================================
     // The TypeManager class is responsible for building binary-compatible
-    // Python type objects that are connected to a managed implementation.
+    // Python type objects that reflect a managed type.
     //=======================================================================
 
     internal class TypeManager {
@@ -42,6 +42,10 @@
 	    a = new ArrayList();
 	}
 
+	//====================================================================
+	// Internal use: given a managed Type object, return the *handle* of 
+	// a Python type object that reflects the managed type. The handle is
+	// a PyObject *, 
 
 	internal static IntPtr GetTypeHandle(Type obType) {
 	    Object ob = cache[obType];
@@ -64,71 +68,8 @@
 	}
 
 
-	static AssemblyBuilder ab;
-	static ModuleBuilder mb;
 	static ArrayList a;
 
-	internal static IntPtr GetThunk2(MethodInfo method) {
-	    // this doesn't work because SigHelper expects to work with
-	    // a generated module. If we could find a way to get a sig
-	    // and length from a methodinfo, we could really make this
-	    // simple...
-	    if (mb == null) {
-		AssemblyName aname = new AssemblyName();
-		aname.Name = "__";
-		AssemblyBuilderAccess aa = AssemblyBuilderAccess.Run;
-		
-		ab = Thread.GetDomain().DefineDynamicAssembly(aname, aa);
-		mb = ab.DefineDynamicModule("__");
-	    }
-
-	    SignatureHelper s = SignatureHelper.GetMethodSigHelper(
-								   //mb, //
-								   method.DeclaringType.Module,
-				  CallingConvention.Cdecl,
-				  method.ReturnType
-				  );
-
-	    ParameterInfo[] pi = method.GetParameters();
-	    for (int n = 0; n < pi.Length; n++) {
-		s.AddArgument(pi[n].ParameterType);
-	    }
-	    byte[] bsig = s.GetSignature();
-	    int csig = bsig.Length;
-	    
-	    IntPtr psig = Marshal.AllocHGlobal(bsig.Length);
-	    Marshal.Copy(bsig, 0, psig, csig);
-
-	    IntPtr fp = Marshal.GetUnmanagedThunkForManagedMethodPtr(
-				method.MethodHandle.GetFunctionPointer(), 
-				psig, 
-				csig
-				);
-	    //Marshal.FreeHGlobal(psig);
-
-	    a.Add(fp);
-	    a.Add(s);
-	    return fp;
-
-	}
-
-
-
-
-
-	private static IntPtr GetThunk(MethodInfo method) {
-	    Type dt = typeof(CallbackThunks).GetNestedType(method.Name);
-	    //Type dt = Prototypes.GetPrototype(method.Name);
-	    if (dt != null) {
-		Delegate d = Delegate.CreateDelegate(dt, method);
-		CallbackThunk cb = new CallbackThunk(d);
-		Marshal.StructureToPtr(cb, p_thunk, false);
-		IntPtr fp = Marshal.ReadIntPtr(p_thunk);
-		dList.Add(d);
-		return fp;
-	    }
-	    return IntPtr.Zero;
-	}
 
 
 	// Given a PyTypeObject instance, fill the slot pointer members of
@@ -156,7 +97,7 @@
 		    FieldInfo fi = typedesc.GetField(name);
 		    IntPtr value = (IntPtr) fi.GetValue(typeObj);
 		    if ((fi != null) && (value == IntPtr.Zero)) {
-			fi.SetValue(typeObj, GetThunk(method));
+			fi.SetValue(typeObj, Prototypes.GetThunk(method));
 		    }
 		}
 		type = type.BaseType;


=== PythonNet/src/TypeMethod.cs 1.1 => 1.2 ===
--- PythonNet/src/TypeMethod.cs:1.1	Mon Feb 17 22:44:36 2003
+++ PythonNet/src/TypeMethod.cs	Mon Jul 14 14:34:09 2003
@@ -30,7 +30,6 @@
 	    arglist[0] = ob;
 	    arglist[1] = args;
 	    arglist[2] = kw;
-	    Object result;
 
 	    try {	
 		Object inst = null;

=== Removed File PythonNet/src/CastHelper.cs ===

=== Removed File PythonNet/src/PyDict.cs ===

=== Removed File PythonNet/src/PyFloat.cs ===

=== Removed File PythonNet/src/PyInteger.cs ===

=== Removed File PythonNet/src/PyList.cs ===

=== Removed File PythonNet/src/PyLong.cs ===

=== Removed File PythonNet/src/PyModule.cs ===

=== Removed File PythonNet/src/PyNumber.cs ===

=== Removed File PythonNet/src/PyObject.cs ===

=== Removed File PythonNet/src/PySequence.cs ===

=== Removed File PythonNet/src/PyString.cs ===

=== Removed File PythonNet/src/PyTuple.cs ===