summaryrefslogtreecommitdiff
path: root/pidl
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2015-09-01 14:33:35 +1200
committerStefan Metzmacher <metze@samba.org>2015-09-01 14:01:23 +0200
commitd1416d65a3cc61e4e56d1a43bb634d12f418ba0e (patch)
tree0885dd737d175b9964d0fe6e6e1585d746e4be7d /pidl
parentc2f4e324d9c1ced2e1da859594ef67ae9f645919 (diff)
downloadsamba-d1416d65a3cc61e4e56d1a43bb634d12f418ba0e.tar.gz
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@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'pidl')
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Python.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 2ace7a0d061..056ab21e9c4 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -1284,7 +1284,7 @@ sub ConvertScalarToPython($$$)
}
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)$/) {
@@ -1535,6 +1535,15 @@ static inline long long ndr_sizeof2intmax(size_t var_size)
return 0;
}
+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) {
@@ -1614,7 +1623,7 @@ static inline long long ndr_sizeof2intmax(size_t var_size)
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 {