]> granicus.if.org Git - python/commitdiff
Merged revisions 80786 via svnmerge from
authorRonald Oussoren <ronaldoussoren@mac.com>
Wed, 5 May 2010 15:33:55 +0000 (15:33 +0000)
committerRonald Oussoren <ronaldoussoren@mac.com>
Wed, 5 May 2010 15:33:55 +0000 (15:33 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r80786 | ronald.oussoren | 2010-05-05 17:32:33 +0200 (Wed, 05 May 2010) | 16 lines

  Merged revisions 80784 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r80784 | ronald.oussoren | 2010-05-05 16:48:37 +0200 (Wed, 05 May 2010) | 9 lines

    The C function used by uuid.uuid4 is broken on
    OSX 10.6 in that after os.fork() the parent and
    child generate the same sequence of UUIDs.

    This patch falls back to the the Python implementation
    on OSX 10.6 or later.

    Fixes issue #8621.
  ........
................

Lib/test/test_uuid.py
Lib/uuid.py
Misc/NEWS

index 696ffb18110a373eb865f939419e9abbbb3ef9d6..a1663c5596eb441f91d4307da9485d133185f9d1 100644 (file)
@@ -451,6 +451,34 @@ class TestUUID(TestCase):
             equal(u, uuid.UUID(v))
             equal(str(u), v)
 
+    def testIssue8621(self):
+        import os
+        import sys
+        if os.name != 'posix':
+            return
+
+        # On at least some versions of OSX uuid.uuid4 generates
+        # the same sequence of UUIDs in the parent and any
+        # children started using fork.
+        fds = os.pipe()
+        pid = os.fork()
+        if pid == 0:
+            os.close(fds[0])
+            value = uuid.uuid4()
+            os.write(fds[1], value.hex.encode('latin1'))
+            os._exit(0)
+
+        else:
+            os.close(fds[1])
+            parent_value = uuid.uuid4().hex
+            os.waitpid(pid, 0)
+            child_value = os.read(fds[0], 100).decode('latin1')
+
+            self.assertNotEqual(parent_value, child_value)
+
+
+
+
 
 def test_main():
     support.run_unittest(TestUUID)
index d50550abc126699bfbdf9d9cdf9d209a11eebe8b..8161d58c4769676c405e3ea5e16b6a2ee1118474 100644 (file)
@@ -427,6 +427,19 @@ try:
         if hasattr(lib, 'uuid_generate_time'):
             _uuid_generate_time = lib.uuid_generate_time
 
+    # The uuid_generate_* functions are broken on MacOS X 10.6, as noted
+    # in issue #8621 the function generates the same sequence of values
+    # in the parent process and all children created using fork (unless
+    # those children use exec as well).
+    #
+    # Assume that the uuid_generate functions are broken from 10.6 onward,
+    # the test can be adjusted when a later version is fixed.
+    import sys
+    if sys.platform == 'darwin':
+        import os
+        if int(os.uname()[2].split('.')[0]) >= 10:
+            _uuid_generate_random = _uuid_generate_time = None
+
     # On Windows prior to 2000, UuidCreate gives a UUID containing the
     # hardware address.  On Windows 2000 and later, UuidCreate makes a
     # random UUID and UuidCreateSequential gives a UUID containing the
index f04412179f6a9c84d7c1661e2defa748565f680e..d819e273be9b4ecd1893e2bc5cd46fed6e233767 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8621: uuid.uuid4() returned the same sequence of values in the
+  parent and any children created using ``os.fork`` on MacOS X 10.6.
+
 - Issue #8567: Fix precedence of signals in Decimal module: when a
   Decimal operation raises multiple signals and more than one of those
   signals is trapped, the specification determines the order in which