[SCM] Samba Shared Repository - branch master updated
Stefan Metzmacher
metze at samba.org
Tue Sep 1 15:01:03 UTC 2015
The branch, master has been updated
via 5aefea8 python/tests: Add more assertions that we get back the value we expect
via 1f50e19 python/tests: Add tests for 64 bit signed integers
via e6fbeb8 pidl/python: also add a ndr_PyLong_FromLongLong() for symnetric reasons
via d1416d6 pidl/python: Provide static inline helper function ndr_PyLong_FromUnsignedLongLong
via c2f4e32 pidl/python: Calculate maximum integer values using a lookup table
from 88b27eb spoolss: handle SetPrinter for info level 4
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 5aefea842528d053b86b50ff2ed9047db1ca4594
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Sep 1 15:00:30 2015 +1200
python/tests: Add more assertions that we get back the value we expect
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
Autobuild-Date(master): Tue Sep 1 17:00:53 CEST 2015 on sn-devel-104
commit 1f50e194517b84ccc8d0208d563e83dabfb2327a
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Sep 1 14:58:20 2015 +1200
python/tests: Add tests for 64 bit signed integers
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit e6fbeb860638ad1113914b9460a618025d950d08
Author: Stefan Metzmacher <metze at samba.org>
Date: Tue Sep 1 10:30:49 2015 +0200
pidl/python: also add a ndr_PyLong_FromLongLong() for symnetric reasons
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit d1416d65a3cc61e4e56d1a43bb634d12f418ba0e
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Sep 1 14:33:35 2015 +1200
pidl/python: Provide static inline helper function ndr_PyLong_FromUnsignedLongLong
This should isolate any coverity warnings on 64-bit platforms
(where LONG_MAX is larger than any possible 32 bit value) to
a single spot, or possibly eliminate it.
This is needed for the unsigned 64 bit case, and on 32 bit
systems, as PyInt_FromLong is limited to a signed "long" int.
The compiler should be able to eliminate many of these calls
with the embedded type knowlege.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit c2f4e324d9c1ced2e1da859594ef67ae9f645919
Author: Andrew Bartlett <abartlet at samba.org>
Date: Fri Aug 28 11:46:56 2015 +1200
pidl/python: Calculate maximum integer values using a lookup table
This avoids a << of 64 bits in the unused end of the conditional expression.
This was flagged by Coverity and the fix was suggested by metze.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429
Andrew Bartlett
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
-----------------------------------------------------------------------
Summary of changes:
pidl/lib/Parse/Pidl/Samba4/Python.pm | 67 ++++++++++++++++++++++++++++++++----
python/samba/tests/dcerpc/integer.py | 34 +++++++++++++++++-
2 files changed, 94 insertions(+), 7 deletions(-)
Changeset truncated at 500 lines:
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index ad9ff88..180b6b2 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -974,7 +974,7 @@ sub ConvertObjectFromPythonData($$$$$$;$)
|uid_t|gid_t)$/x) {
$self->pidl("{");
$self->indent;
- $self->pidl("const unsigned long long uint_max = (sizeof($target) == 8) ? UINT64_MAX : (unsigned long long)((1ULL << (sizeof($target) * 8)) - 1);");
+ $self->pidl("const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof($target));");
$self->pidl("if (PyLong_Check($cvar)) {");
$self->indent;
$self->pidl("unsigned long long test_var;");
@@ -1025,7 +1025,7 @@ sub ConvertObjectFromPythonData($$$$$$;$)
if ($ctype_alias =~ /^(dlong|char|int[0-9]*|time_t)$/x) {
$self->pidl("{");
$self->indent;
- $self->pidl("const long long int_max = (long long)((1ULL << (sizeof($target) * 8 - 1)) - 1);");
+ $self->pidl("const long long int_max = ndr_sizeof2intmax(sizeof($target));");
$self->pidl("const long long int_min = -int_max - 1;");
$self->pidl("if (PyLong_Check($cvar)) {");
$self->indent;
@@ -1280,11 +1280,11 @@ sub ConvertScalarToPython($$$)
$ctypename = expandAlias($ctypename);
if ($ctypename =~ /^(int64|dlong)$/) {
- return "($cvar > LONG_MAX || $cvar < LONG_MIN) ? PyLong_FromLongLong($cvar) : PyInt_FromLong($cvar)";
+ return "ndr_PyLong_FromLongLong($cvar)";
}
if ($ctypename =~ /^(uint64|hyper|NTTIME_hyper|NTTIME|NTTIME_1sec|udlong|udlongr|uid_t|gid_t)$/) {
- return "$cvar > LONG_MAX ? PyLong_FromUnsignedLongLong($cvar) : PyInt_FromLong($cvar)";
+ return "ndr_PyLong_FromUnsignedLongLong($cvar)";
}
if ($ctypename =~ /^(char|int|int8|int16|int32|time_t)$/) {
@@ -1296,7 +1296,7 @@ sub ConvertScalarToPython($$$)
# possibly 64 bit unsigned long. (enums are signed in C,
# unsigned in NDR)
if ($ctypename =~ /^(uint32|uint3264)$/) {
- return "(uint32_t)$cvar > LONG_MAX ? PyLong_FromUnsignedLong((uint32_t)$cvar) : PyInt_FromLong((uint32_t)$cvar)";
+ return "ndr_PyLong_FromUnsignedLongLong((uint32_t)$cvar)";
}
if ($ctypename =~ /^(uint|uint8|uint16|uint1632)$/) {
@@ -1498,6 +1498,61 @@ sub Parse($$$$$)
#include \"$hdr\"
#include \"$ndr_hdr\"
+/*
+ * These functions are here to ensure they can be optomised out by
+ * the compiler based on the constant input values
+ */
+
+static inline unsigned long long ndr_sizeof2uintmax(size_t var_size)
+{
+ switch (var_size) {
+ case 8:
+ return UINT64_MAX;
+ case 4:
+ return UINT32_MAX;
+ case 2:
+ return UINT16_MAX;
+ case 1:
+ return UINT8_MAX;
+ }
+
+ return 0;
+}
+
+static inline long long ndr_sizeof2intmax(size_t var_size)
+{
+ switch (var_size) {
+ case 8:
+ return INT64_MAX;
+ case 4:
+ return INT32_MAX;
+ case 2:
+ return INT16_MAX;
+ case 1:
+ return INT8_MAX;
+ }
+
+ return 0;
+}
+
+static inline PyObject *ndr_PyLong_FromLongLong(long long v)
+{
+ if (v > LONG_MAX || v < LONG_MIN) {
+ return PyLong_FromLongLong(v);
+ } else {
+ return PyInt_FromLong(v);
+ }
+}
+
+static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
+{
+ if (v > LONG_MAX) {
+ return PyLong_FromUnsignedLongLong(v);
+ } else {
+ return PyInt_FromLong(v);
+ }
+}
+
");
foreach my $x (@$ndr) {
@@ -1577,7 +1632,7 @@ sub Parse($$$$$)
my $py_obj;
my ($ctype, $cvar) = @{$h->{'val'}};
if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) {
- $py_obj = "$cvar > LONG_MAX ? PyLong_FromUnsignedLongLong($cvar) : PyInt_FromLong($cvar)";
+ $py_obj = "ndr_PyLong_FromUnsignedLongLong($cvar)";
} elsif ($cvar =~ /^".*"$/) {
$py_obj = "PyString_FromString($cvar)";
} else {
diff --git a/python/samba/tests/dcerpc/integer.py b/python/samba/tests/dcerpc/integer.py
index 1a392ee..ca5d571 100644
--- a/python/samba/tests/dcerpc/integer.py
+++ b/python/samba/tests/dcerpc/integer.py
@@ -17,7 +17,7 @@
"""Tests for integer handling in PIDL generated bindings samba.dcerpc.*"""
-from samba.dcerpc import server_id, misc, srvsvc
+from samba.dcerpc import server_id, misc, srvsvc, samr
import samba.tests
class IntegerTests(samba.tests.TestCase):
@@ -30,6 +30,7 @@ class IntegerTests(samba.tests.TestCase):
def test_int_into_hyper(self):
s = server_id.server_id()
s.unique_id = 1
+ self.assertEquals(s.unique_id, 1)
def test_negative_int_into_hyper(self):
s = server_id.server_id()
@@ -52,6 +53,7 @@ class IntegerTests(samba.tests.TestCase):
def test_int_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
s.timezone = 5
+ self.assertEquals(s.timezone, 5)
def test_uint32_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
@@ -62,6 +64,7 @@ class IntegerTests(samba.tests.TestCase):
def test_long_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
s.timezone = 5L
+ self.assertEquals(s.timezone, 5)
def test_larger_long_int_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
@@ -72,6 +75,7 @@ class IntegerTests(samba.tests.TestCase):
def test_larger_int_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
s.timezone = 2147483647
+ self.assertEquals(s.timezone, 2147483647)
def test_float_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
@@ -88,6 +92,7 @@ class IntegerTests(samba.tests.TestCase):
def test_negative_int_into_int32(self):
s = srvsvc.NetRemoteTODInfo()
s.timezone = -2147483648
+ self.assertEquals(s.timezone, -2147483648)
def test_negative_into_uint32(self):
s = server_id.server_id()
@@ -128,6 +133,7 @@ class IntegerTests(samba.tests.TestCase):
def test_enum_into_uint16(self):
g = misc.GUID()
g.time_mid = misc.SEC_CHAN_DOMAIN
+ self.assertEquals(g.time_mid, misc.SEC_CHAN_DOMAIN)
def test_bitmap_into_uint16(self):
g = misc.GUID()
@@ -146,6 +152,32 @@ class IntegerTests(samba.tests.TestCase):
g.time_mid = misc.SV_TYPE_DOMAIN_ENUM
self.assertRaises(OverflowError, assign)
+ def test_hyper_into_int64(self):
+ s = samr.DomInfo1()
+ def assign():
+ s.max_password_age = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
+ self.assertRaises(OverflowError, assign)
+
+ def test_int_into_int64(self):
+ s = samr.DomInfo1()
+ s.max_password_age = 5
+ self.assertEquals(s.max_password_age, 5)
+
+ def test_negative_int_into_int64(self):
+ s = samr.DomInfo1()
+ s.max_password_age = -5
+ self.assertEquals(s.max_password_age, -5)
+
+ def test_larger_int_into_int64(self):
+ s = samr.DomInfo1()
+ s.max_password_age = server_id.NONCLUSTER_VNN
+ self.assertEquals(s.max_password_age, 0xFFFFFFFFL)
+
+ def test_larger_negative_int_into_int64(self):
+ s = samr.DomInfo1()
+ s.max_password_age = -2147483649
+ self.assertEquals(s.max_password_age, -2147483649L)
+
def test_int_list_over_list(self):
g = misc.GUID()
g.node = [5, 0, 5, 0, 7, 4]
--
Samba Shared Repository
More information about the samba-cvs
mailing list