1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

r2559: 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.
(This used to be commit e9eb231d64)
This commit is contained in:
Tim Potter 2004-09-23 03:26:14 +00:00 committed by Gerald (Jerry) Carter
parent 54d33d5674
commit 46cbe76a2c
2 changed files with 55 additions and 22 deletions

View File

@ -58,12 +58,15 @@ uint8 uint8_from_python(PyObject *obj, char *name)
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 @@ uint16 uint16_from_python(PyObject *obj, char *name)
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 @@ uint32 uint32_from_python(PyObject *obj, char *name)
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 @@ int64 int64_from_python(PyObject *obj, char *name)
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 @@ uint64 uint64_from_python(PyObject *obj, char *name)
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 @@ NTTIME NTTIME_from_python(PyObject *obj, char *name)
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 @@ HYPER_T HYPER_T_from_python(PyObject *obj, char *name)
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)

View File

@ -872,6 +872,16 @@ def test_EnumDomains(pipe, connect_handle):
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 @@ pipe = dcerpc.pipe_connect(binding,
dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION,
domain, username, password)
test_LongInt(pipe)
handle = test_Connect(pipe)
test_QuerySecurity(pipe, handle)