summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-24 04:13:42 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-24 04:13:42 (GMT)
commit37410aa044fd4ac665a8a8d8031bd0e165515a8e (patch)
treeec80a506e798545e18070c1e7f083f5ac8ce361f /Lib
parentfd53fd62c9d7d84b5f39fec8eab65a43d5c12be1 (diff)
downloadcpython-37410aa044fd4ac665a8a8d8031bd0e165515a8e.zip
cpython-37410aa044fd4ac665a8a8d8031bd0e165515a8e.tar.gz
cpython-37410aa044fd4ac665a8a8d8031bd0e165515a8e.tar.bz2
Make uuid.py thread-safe. Fix by Yuri Ginsburg.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/uuid.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index c52ffbb..74d4a7a 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -414,7 +414,6 @@ def _netbios_getnode():
_uuid_generate_random = _uuid_generate_time = _UuidCreate = None
try:
import ctypes, ctypes.util
- _buffer = ctypes.create_string_buffer(16)
# The uuid_generate_* routines are provided by libuuid on at least
# Linux and FreeBSD, and provided by libc on Mac OS X.
@@ -447,11 +446,13 @@ except:
def _unixdll_getnode():
"""Get the hardware address on Unix using ctypes."""
+ _buffer = ctypes.create_string_buffer(16)
_uuid_generate_time(_buffer)
return UUID(bytes=bytes_(_buffer.raw)).node
def _windll_getnode():
"""Get the hardware address on Windows using ctypes."""
+ _buffer = ctypes.create_string_buffer(16)
if _UuidCreate(_buffer) == 0:
return UUID(bytes=bytes_(_buffer.raw)).node
@@ -499,6 +500,7 @@ def uuid1(node=None, clock_seq=None):
# When the system provides a version-1 UUID generator, use it (but don't
# use UuidCreate here because its UUIDs don't conform to RFC 4122).
+ _buffer = ctypes.create_string_buffer(16)
if _uuid_generate_time and node is clock_seq is None:
_uuid_generate_time(_buffer)
return UUID(bytes=bytes_(_buffer.raw))
@@ -535,6 +537,7 @@ def uuid4():
"""Generate a random UUID."""
# When the system provides a version-4 UUID generator, use it.
+ _buffer = ctypes.create_string_buffer(16)
if _uuid_generate_random:
_uuid_generate_random(_buffer)
return UUID(bytes=bytes_(_buffer.raw))