[Zope-CVS] CVS: PythonNet/src/runtime - DebugHelper.cs:1.3 Exceptions.cs:1.3 ImportHook.cs:1.2 ModuleObject.cs:1.2 TypeManager.cs:1.4

Brian Lloyd brian@zope.com
Wed, 30 Jul 2003 09:56:03 -0400


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

Modified Files:
	DebugHelper.cs Exceptions.cs ImportHook.cs ModuleObject.cs 
	TypeManager.cs 
Log Message:
capture updates

=== PythonNet/src/runtime/DebugHelper.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/DebugHelper.cs:1.2	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/DebugHelper.cs	Wed Jul 30 09:55:50 2003
@@ -27,7 +27,7 @@
 
 	    for (int i = 0; i < args.Length; i++) {
 		IntPtr ob = Runtime.PyObject_Repr(args[i]);
-		result += Runtime.PyString_AsString(ob);
+		result += Runtime.GetManagedString(ob);
 		Runtime.Decref(ob);
 		result += " ";
 	    }


=== PythonNet/src/runtime/Exceptions.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/Exceptions.cs:1.2	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/Exceptions.cs	Wed Jul 30 09:55:50 2003
@@ -34,6 +34,7 @@
 						    BindingFlags.Static)) {
 		IntPtr op = Runtime.PyObject_GetAttrString(module, fi.Name);
 		if (op != IntPtr.Zero) {
+		    Runtime.Incref(op);
 		    fi.SetValue(type, op);
 		}
 	    }


=== PythonNet/src/runtime/ImportHook.cs 1.1 => 1.2 ===
--- PythonNet/src/runtime/ImportHook.cs:1.1	Mon Jul 14 15:59:51 2003
+++ PythonNet/src/runtime/ImportHook.cs	Wed Jul 30 09:55:50 2003
@@ -68,7 +68,7 @@
 	    // borrowed reference
 	    IntPtr py_mod_name = Runtime.PyTuple_GetItem(args, 0);
 
-	    if (!Runtime.PyString_Check(py_mod_name)) {
+	    if (!Runtime.IsStringType(py_mod_name)) {
 		Exceptions.SetError(Exceptions.TypeError, "string expected");
 		return IntPtr.Zero;
 	    }
@@ -76,7 +76,7 @@
 	    // If not a CLR module, defer to the standard Python import.
 	    // Could use Python here to avoid a string conversion.
 
-	    string mod_name = Runtime.PyString_AsString(py_mod_name);
+	    string mod_name = Runtime.GetManagedString(py_mod_name);
 
 	    if (!(mod_name.StartsWith("CLR.") || mod_name == "CLR")) {
 		return Runtime.PyObject_Call(py_import, args, kw);


=== PythonNet/src/runtime/ModuleObject.cs 1.1 => 1.2 ===
--- PythonNet/src/runtime/ModuleObject.cs:1.1	Mon Jul 14 15:59:51 2003
+++ PythonNet/src/runtime/ModuleObject.cs	Wed Jul 30 09:55:50 2003
@@ -185,7 +185,7 @@
 		return op;
 	    }
  
-	    string name = Runtime.PyString_AsString(key);
+	    string name = Runtime.GetManagedString(key);
 	    if (name == "__dict__") {
 		return Runtime.PyDictProxy_New(self.dict);
 	    }


=== PythonNet/src/runtime/TypeManager.cs 1.3 => 1.4 ===
--- PythonNet/src/runtime/TypeManager.cs:1.3	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/TypeManager.cs	Wed Jul 30 09:55:50 2003
@@ -39,7 +39,6 @@
 	    p_thunk = Marshal.AllocHGlobal(IntPtr.Size);
 	    cache = new Hashtable();
 	    dList = new ArrayList();
-	    a = new ArrayList();
 	}
 
 	//====================================================================
@@ -68,8 +67,6 @@
 	}
 
 
-	static ArrayList a;
-
 
 
 	// Given a PyTypeObject instance, fill the slot pointer members of
@@ -187,9 +184,33 @@
 
 	    IntPtr o = FinishType(pyTypeObj);
 	    InitMethods(o, obType);
+
+	    unscrew(o);
+
 	    return o;
 	}
 
+	internal static void unscrew(IntPtr op) {
+	    IntPtr pname = Marshal.ReadIntPtr(op, (3 * IntPtr.Size));
+	    string name = Marshal.PtrToStringAnsi(pname);
+
+	    int flags = (int)Marshal.ReadIntPtr(op, (21 * IntPtr.Size));
+	    if ((flags & (1 << 14)) != 0) {
+		Console.WriteLine("type {0} is GC!", name);
+	    }
+
+	    IntPtr mro = Marshal.ReadIntPtr(op, (43 * IntPtr.Size));
+	    if (mro == IntPtr.Zero) {
+		Console.WriteLine("type {0} has null mro", name);
+	    }
+	    else {
+		if (Runtime.PyObject_Type(mro) != Runtime.PyTupleType) {
+		Console.WriteLine("type {0} non-tuple mro", name);
+		}
+	    }
+
+ 
+	}
 
 	// Initialize a new binary-compatible PyTypeObject for a Python
 	// type that reflects a managed type.
@@ -203,7 +224,6 @@
 	    }
 
 
-	    // todo - can blit this after first time!
 	    PyTypeObject pyTypeObj = new PyTypeObject();
 	    pyTypeObj.tp_name = Marshal.StringToHGlobalAnsi(name);
 
@@ -229,6 +249,9 @@
 
 	    IntPtr op = FinishType(pyTypeObj);
 	    obj.pyHandle = op;
+
+	    unscrew(op);
+
 	    return op;
 	}