svn commit: samba r2559 - in branches/SAMBA_4_0/source/scripting/swig: . torture

tpot at samba.org tpot at samba.org
Thu Sep 23 03:26:14 GMT 2004


Author: tpot
Date: 2004-09-23 03:26:14 +0000 (Thu, 23 Sep 2004)
New Revision: 2559

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/scripting/swig&rev=2559&nolog=1

Log:
Python ints can't hold the full range of uint32 values so store them
as Python longs.

Also allow shorter width integer types to be initialised from long values.
Their values are truncated if they are too long.

Modified:
   branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
   branches/SAMBA_4_0/source/scripting/swig/torture/samr.py


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-23 02:37:02 UTC (rev 2558)
+++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-23 03:26:14 UTC (rev 2559)
@@ -58,12 +58,15 @@
 		return 0;
 	}
 
-	if (!PyInt_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
+	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (uint8)PyInt_AsLong(obj);
+	if (PyLong_Check(obj))
+		return (uint8)PyLong_AsLong(obj);
+	else
+		return (uint8)PyInt_AsLong(obj);
 }
 
 PyObject *uint8_to_python(uint8 obj)
@@ -78,12 +81,15 @@
 		return 0;
 	}
 
-	if (!PyInt_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
+	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (uint16)PyInt_AsLong(obj);
+	if (PyLong_Check(obj))
+		return (uint16)PyLong_AsLong(obj);
+	else
+		return (uint16)PyInt_AsLong(obj);
 }
 
 PyObject *uint16_to_python(uint16 obj)
@@ -98,17 +104,20 @@
 		return 0;
 	}
 
-	if (!PyInt_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
+	if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (uint32)PyInt_AsLong(obj);
+	if (PyLong_Check(obj))
+		return (uint32)PyLong_AsLong(obj);
+	else
+		return (uint32)PyInt_AsLong(obj);
 }
 
 PyObject *uint32_to_python(uint32 obj)
 {
-	return PyInt_FromLong(obj);
+	return PyLong_FromLong(obj);
 }
 
 int64 int64_from_python(PyObject *obj, char *name)
@@ -118,12 +127,15 @@
 		return 0;
 	}
 
-	if (!PyLong_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting long value for %s", name);
+	if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (int64)PyLong_AsLongLong(obj);
+	if (PyLong_Check(obj))
+		return (int64)PyLong_AsLongLong(obj);
+	else
+		return (int64)PyInt_AsLong(obj);
 }
 
 PyObject *int64_to_python(int64 obj)
@@ -138,12 +150,15 @@
 		return 0;
 	}
 
-	if (!PyLong_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting long value for %s", name);
+	if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (uint64)PyLong_AsUnsignedLongLong(obj);
+	if (PyLong_Check(obj))
+		return (uint64)PyLong_AsUnsignedLongLong(obj);
+	else
+		return (uint64)PyInt_AsLong(obj);
 }
 
 PyObject *uint64_to_python(uint64 obj)
@@ -158,12 +173,15 @@
 		return 0;
 	}
 
-	if (!PyLong_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting long value for %s", name);
+	if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (NTTIME)PyLong_AsUnsignedLongLong(obj);
+	if (PyLong_Check(obj))
+		return (NTTIME)PyLong_AsUnsignedLongLong(obj);
+	else
+		return (NTTIME)PyInt_AsUnsignedLongMask(obj);
 }
 
 PyObject *NTTIME_to_python(NTTIME obj)
@@ -178,12 +196,15 @@
 		return 0;
 	}
 
-	if (!PyLong_Check(obj)) {
-		PyErr_Format(PyExc_TypeError, "Expecting long value for %s", name);
+	if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
+		PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
 		return 0;
 	}
 
-	return (HYPER_T)PyLong_AsUnsignedLongLong(obj);
+	if (PyLong_Check(obj))
+		return (HYPER_T)PyLong_AsUnsignedLongLong(obj);
+	else
+		return (HYPER_T)PyInt_AsUnsignedLongMask(obj);
 }
 
 PyObject *HYPER_T_to_python(HYPER_T obj)

Modified: branches/SAMBA_4_0/source/scripting/swig/torture/samr.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/torture/samr.py	2004-09-23 02:37:02 UTC (rev 2558)
+++ branches/SAMBA_4_0/source/scripting/swig/torture/samr.py	2004-09-23 03:26:14 UTC (rev 2559)
@@ -872,6 +872,16 @@
     for domain in result['sam']['entries']:
         test_LookupDomain(pipe, handle, domain['name']['name'])
 
+def test_LongInt(pipe):
+
+    # Check that we can use long values for shorter width types
+
+    r = {}
+    r['system_name'] = 0L;
+    r['access_mask'] = 0x02000000L
+
+    result = dcerpc.samr_Connect(pipe, r)
+
 # Parse command line
 
 parser = OptionParser()
@@ -908,6 +918,8 @@
 	dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION,
 	domain, username, password)
 
+test_LongInt(pipe)
+
 handle = test_Connect(pipe)
 
 test_QuerySecurity(pipe, handle)



More information about the samba-cvs mailing list