[Zope-CVS] CVS: PythonNet/src/runtime - ClassObject.cs:1.3 DelegateManager.cs:1.3 ImportHook.cs:1.3 Runtime.cs:1.3

Brian Lloyd brian@zope.com
Fri, 1 Aug 2003 10:30:20 -0400


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

Modified Files:
	ClassObject.cs DelegateManager.cs ImportHook.cs Runtime.cs 
Log Message:
checkpoint refcount fixes

=== PythonNet/src/runtime/ClassObject.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/ClassObject.cs:1.2	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/ClassObject.cs	Fri Aug  1 10:30:13 2003
@@ -119,6 +119,7 @@
 
 	    if (!Runtime.PyTuple_Check(idx)) {
 		args = Runtime.PyTuple_New(1);
+		Runtime.Incref(idx);
 		Runtime.PyTuple_SetItem(args, 0, idx);
 		free = true;
 	    }
@@ -159,6 +160,7 @@
 
 	    if (!Runtime.PyTuple_Check(idx)) {
 		args = Runtime.PyTuple_New(1);
+		Runtime.Incref(idx);
 		Runtime.PyTuple_SetItem(args, 0, idx);
 		free = true;
 	    }
@@ -167,8 +169,10 @@
 	    IntPtr real = Runtime.PyTuple_New(i + 1);
 	    for (int n = 0; n < i; n++) {
 		IntPtr item = Runtime.PyTuple_GetItem(args, n);
+		Runtime.Incref(item);
 		Runtime.PyTuple_SetItem(real, n, item);
 	    }
+	    Runtime.Incref(v);
 	    Runtime.PyTuple_SetItem(real, i, v);
 
 	    IntPtr value = cls.indexer.SetItem(ob, real);


=== PythonNet/src/runtime/DelegateManager.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/DelegateManager.cs:1.2	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/DelegateManager.cs	Fri Aug  1 10:30:13 2003
@@ -226,6 +226,8 @@
 	    Type rtype = method.ReturnType;
 
 	    for (int i = 0; i < pi.Length; i++) {
+		// Here we own the reference to the Python value, and we
+		// give the ownership to the arg tuple.
 		IntPtr arg = Converter.ToPython(args[i], pi[i].ParameterType);
 		int r = Runtime.PyTuple_SetItem(pyargs, i, arg);
 	    }


=== PythonNet/src/runtime/ImportHook.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/ImportHook.cs:1.2	Wed Jul 30 09:55:50 2003
+++ PythonNet/src/runtime/ImportHook.cs	Fri Aug  1 10:30:13 2003
@@ -32,8 +32,8 @@
 
 	    IntPtr dict = Runtime.PyImport_GetModuleDict();
 	    IntPtr mod = Runtime.PyDict_GetItemString(dict, "__builtin__");
-
 	    py_import = Runtime.PyObject_GetAttrString(mod, "__import__");
+	    Runtime.Incref(py_import);
 
 	    // should never die
 	    hook = new StaticMethodWrapper(
@@ -77,6 +77,7 @@
 	    // Could use Python here to avoid a string conversion.
 
 	    string mod_name = Runtime.GetManagedString(py_mod_name);
+	    //Console.WriteLine(mod_name);
 
 	    if (!(mod_name.StartsWith("CLR.") || mod_name == "CLR")) {
 		return Runtime.PyObject_Call(py_import, args, kw);


=== PythonNet/src/runtime/Runtime.cs 1.2 => 1.3 ===
--- PythonNet/src/runtime/Runtime.cs:1.2	Mon Jul 28 22:28:15 2003
+++ PythonNet/src/runtime/Runtime.cs	Fri Aug  1 10:30:13 2003
@@ -120,25 +120,6 @@
 	    (*(int *)op)++;
 	}
 
-	private static void LogDecref(IntPtr op) {
-	    IntPtr tp = Runtime.PyObject_Type(op);
-	    IntPtr fp = Marshal.ReadIntPtr(tp, (6 * IntPtr.Size));
-	    if (fp == IntPtr.Zero) {
-		return;
-	    }
-
-	    IntPtr refs = Marshal.ReadIntPtr(op);
-
-	    IntPtr p1 = Runtime.PyObject_Repr(tp);
-	    string s1 = Runtime.PyString_AsString(p1);
-	    
-	    IntPtr p2 = Runtime.PyObject_Repr(op);
-	    string s2 = Runtime.PyString_AsString(p2);
-
-	    Console.WriteLine("decref: {0} {1} {2} {3} {4}", 
-			      s1, refs, s2, fp, op
-			      );
-	}
 
 	internal unsafe static void Decref(IntPtr op) {
 
@@ -154,10 +135,9 @@
 		if (fp == IntPtr.Zero) {
 		    return;
 		}
-		//LogDecref(op);
+
 		try {
-		    // Fix this - figure out native call / malloc bug.
-		    // NativeCall.Impl.Void_Call_1(fp, op);
+		    NativeCall.Impl.Void_Call_1(fp, op);
 		} catch {
 		    IntPtr ss = Runtime.PyObject_Str(op);
 		    string ds = Runtime.PyString_AsString(ss);