[Zope-CVS] CVS: PythonNet/src/runtime - Converter.cs:1.8 MethodBinder.cs:1.8 Runtime.cs:1.12

Brian Lloyd cvs-admin at zope.org
Mon Oct 27 23:01:16 EST 2003


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

Modified Files:
	Converter.cs MethodBinder.cs Runtime.cs 
Log Message:
Fixups for b1 release


=== PythonNet/src/runtime/Converter.cs 1.7 => 1.8 ===
--- PythonNet/src/runtime/Converter.cs:1.7	Mon Oct 27 21:07:00 2003
+++ PythonNet/src/runtime/Converter.cs	Mon Oct 27 23:00:45 2003
@@ -31,6 +31,7 @@
 	static Type int32Type;
 	static Type int64Type;
 	static Type flagsType;
+	static Type boolType;
 	static Type typeType;
 
 	static Converter () {
@@ -39,6 +40,7 @@
 	    int32Type = typeof(Int32);
 	    int64Type = typeof(Int64);
 	    flagsType = typeof(FlagsAttribute);
+	    boolType = typeof(Boolean);
 	    typeType = typeof(Type);
 	}
 
@@ -82,8 +84,12 @@
 		return Runtime.PyInt_FromInt32((int)value);
 
 	    case TypeCode.Boolean:
-		int i = (bool) value ? 1 : 0;
-		return Runtime.PyInt_FromInt32(i);
+		if ((bool)value) {
+		    Runtime.Incref(Runtime.PyTrue);
+		    return Runtime.PyTrue;
+		}
+		Runtime.Incref(Runtime.PyFalse);
+		return Runtime.PyFalse;
 
 	    case TypeCode.Byte:
 		return Runtime.PyInt_FromInt32((int)((byte)value));
@@ -198,6 +204,10 @@
 		if (Runtime.IsStringType(value)) {
 		    return ToPrimitive(value, stringType, out result, 
 				       setError);
+		}
+
+		else if (Runtime.PyBool_Check(value)) {
+		    return ToPrimitive(value, boolType, out result, setError);
 		}
 
 		else if (Runtime.PyInt_Check(value)) {


=== PythonNet/src/runtime/MethodBinder.cs 1.7 => 1.8 ===
--- PythonNet/src/runtime/MethodBinder.cs:1.7	Mon Oct 27 21:07:00 2003
+++ PythonNet/src/runtime/MethodBinder.cs	Mon Oct 27 23:00:45 2003
@@ -70,8 +70,8 @@
 
 	internal static int GetPrecedence(MethodBase mi) {
 	    ParameterInfo[] pi = mi.GetParameters();
+	    int val = mi.IsStatic ? 3000 : 0;
 	    int num = pi.Length;
-	    int val = 0;
 
 	    for (int i = 0; i < num; i++) {
 		val += ArgPrecedence(pi[i].ParameterType);


=== PythonNet/src/runtime/Runtime.cs 1.11 => 1.12 ===
--- PythonNet/src/runtime/Runtime.cs:1.11	Wed Oct 22 22:53:10 2003
+++ PythonNet/src/runtime/Runtime.cs	Mon Oct 27 23:00:45 2003
@@ -23,7 +23,6 @@
 	/// Encapsulates the low-level Python C API.
 	/// </summary>
 
-	private static IntPtr MainThreadState;
 	internal static bool Is32Bit;
 
 	internal static void Initialize() {
@@ -33,10 +32,6 @@
 	    Runtime.Py_Initialize();
 	    Runtime.PyEval_InitThreads();
 
-	    // Store a reference to the main threadstate.
-	    MainThreadState = PyThreadState_Get();
-
-
 	    IntPtr dict = Runtime.PyImport_GetModuleDict();
 	    IntPtr op = Runtime.PyDict_GetItemString(dict, "__builtin__");
 
@@ -44,6 +39,10 @@
 
 	    PyModuleType = Runtime.PyObject_Type(op); 
 	    PyNone = Runtime.PyObject_GetAttrString(op, "None"); 
+	    PyTrue = Runtime.PyObject_GetAttrString(op, "True"); 
+	    PyFalse = Runtime.PyObject_GetAttrString(op, "False"); 
+
+	    PyBoolType = Runtime.PyObject_Type(PyTrue); 
 	    PyNoneType = Runtime.PyObject_Type(PyNone); 
 	    PyTypeType = Runtime.PyObject_Type(PyNoneType); 
 
@@ -123,9 +122,12 @@
 	internal static IntPtr PyIntType;
 	internal static IntPtr PyLongType;
 	internal static IntPtr PyFloatType;
+	internal static IntPtr PyBoolType;
 	internal static IntPtr PyNoneType;
 	internal static IntPtr PyTypeType;
 
+	internal static IntPtr PyTrue;
+	internal static IntPtr PyFalse;
 	internal static IntPtr PyNone;
 	internal static IntPtr Error;
 
@@ -553,7 +555,11 @@
 
 
 	internal static bool PyInt_Check(IntPtr ob) {
-	    return PyObject_TYPE(ob) == Runtime.PyIntType;
+	    return PyObject_TypeCheck(ob, Runtime.PyIntType);
+	}
+
+	internal static bool PyBool_Check(IntPtr ob) {
+	    return PyObject_TypeCheck(ob, Runtime.PyBoolType);
 	}
 
 




More information about the Zope-CVS mailing list