[PATCHES] begone python long

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Thu Oct 4 02:40:45 UTC 2018


Tim was fixing the (py3-incompatible, py2-wrong) use of Python long()
for a C binding that took C longs which it then squeezed into time_t,
and I thought I'd look for other python longs. There aren't many, if we
neglect third_party/. After this there will be one, but Python 3 won't
see it.

cheers,
Douglas

>> From 776db91a42b2e271cf59935fbdf890d30af8819b Mon Sep 17 00:00:00 2001
>> From: Tim Beale <timbeale at catalyst.net.nz>
>> Date: Thu, 4 Oct 2018 14:37:44 +1300
>> Subject: [PATCH 4/4] netcmd: Change Py3 incompatible long() for tombstone
>>  expunge
>>
>> The code to expunge tombstones uses long(), which is not Python3
>> compatible. Python3 uses int() instead, and works out how big it needs
>> to be.
>>
>> Python 2.6 appears to work differently for int(), but as long as we
>> stop running 'make test' on Python 2.6 by 2038, then we should be OK
>> (the integer won't overflow).
> 
> It is not just 'make test' in this case, because this is samba-tool.
> 
> On the other hand, using Python 2.6 in 2038 is not sufficient to cause
> a problem -- only a 32 bit machine will suffer. What is more the
> function this is used in (py_dsdb_garbage_collect_tombstones(),
> source4/dsdb/pydsdb.c:1225) takes a C long, which is the underlying
> type of a Python 2.6 int, so it is better to use the Python int in any
> case. (Python 3 ints and 2.6 longs are of indefinite length, which
> will end up being truncated at the C layer to the sizes of long thence
> time_t, undefined-ly in the C fashion, making the Python 2.6 int
> semantics look better and better).
> 

-------------- next part --------------
From 322f32d233e251155e919ebfa91058c863f7aaef Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 4 Oct 2018 15:29:02 +1300
Subject: [PATCH 1/2] python/upgradehelpers: use int not long for PY3

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/upgradehelpers.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/python/samba/upgradehelpers.py b/python/samba/upgradehelpers.py
index 804d820c886..efc0356d25f 100644
--- a/python/samba/upgradehelpers.py
+++ b/python/samba/upgradehelpers.py
@@ -28,7 +28,7 @@ import re
 import shutil
 import samba
 
-from samba.compat import cmp_fn
+from samba.compat import cmp_fn, PY3
 from samba import Ldb, version, ntacls
 from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE
 import ldb
@@ -831,7 +831,9 @@ def int64range2str(value):
     :param value: The int64 range
     :return: A string of the representation of the range
     """
-
-    lvalue = long(value)
+    if PY3:
+        lvalue = int(value)
+    else:
+        lvalue = long(value)
     str = "%d-%d" % (lvalue &0xFFFFFFFF, lvalue >>32)
     return str
-- 
2.17.1


From f18d3dff0f4f3389e794d0988afa2c1b0946ca10 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 4 Oct 2018 15:30:21 +1300
Subject: [PATCH 2/2] tests/python/ldap: use int instead of long for time_t

Python int is at least a C long; Python long disappears in Py3.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/ldap.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/dsdb/tests/python/ldap.py b/source4/dsdb/tests/python/ldap.py
index 37ccfb4edc7..6a5e34be72b 100755
--- a/source4/dsdb/tests/python/ldap.py
+++ b/source4/dsdb/tests/python/ldap.py
@@ -1675,8 +1675,8 @@ objectGUID: bd3480c9-58af-4cd8-92df-bc4a18b6e44d
             "objectclass": "container",
             "uSNCreated": "1",
             "uSNChanged": "1",
-            "whenCreated": timestring(long(time.time())),
-            "whenChanged": timestring(long(time.time()))})
+            "whenCreated": timestring(int(time.time())),
+            "whenChanged": timestring(int(time.time()))})
 
         res = ldb.search("cn=ldaptestcontainer," + self.base_dn,
                          scope=SCOPE_BASE,
-- 
2.17.1



More information about the samba-technical mailing list