[Commits] (bear) Applying patch from Bug 2396 - replaces lock.c
with a pure python version
commits at osafoundation.org
commits at osafoundation.org
Mon Feb 21 16:29:00 PST 2005
Commit by: bear
Modified files:
internal/chandlerdb/setup.py 1.4 1.5
internal/chandlerdb/chandlerdb/util/lock.py 1.1 1.2
Log message:
Applying patch from Bug 2396 - replaces lock.c with a pure python version
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/chandlerdb/setup.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/internal/chandlerdb/chandlerdb/util/lock.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
Index: internal/chandlerdb/setup.py
diff -u internal/chandlerdb/setup.py:1.4 internal/chandlerdb/setup.py:1.5
--- internal/chandlerdb/setup.py:1.4 Sun Oct 17 14:33:11 2004
+++ internal/chandlerdb/setup.py Mon Feb 21 16:28:57 2005
@@ -1,6 +1,6 @@
-__revision__ = "$Revision: 1.4 $"
-__date__ = "$Date: 2004/10/17 21:33:11 $"
+__revision__ = "$Revision: 1.5 $"
+__date__ = "$Date: 2005/02/22 00:28:57 $"
__copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -23,10 +23,7 @@
'chandlerdb/util/rijndael.i'],
include_dirs=['rijndael-2.4']))
- if os.name == 'nt':
- extensions.append(Extension('chandlerdb.util.lock',
- sources=['chandlerdb/util/lock.c']))
- elif os.name == 'posix':
+ if os.name in ('nt','posix'):
modules.append('chandlerdb.util.lock')
else:
raise ValueError, 'unsupported os: %s' %(os.name)
Index: internal/chandlerdb/chandlerdb/util/lock.py
diff -u internal/chandlerdb/chandlerdb/util/lock.py:1.1 internal/chandlerdb/chandlerdb/util/lock.py:1.2
--- internal/chandlerdb/chandlerdb/util/lock.py:1.1 Sun Oct 17 11:50:55 2004
+++ internal/chandlerdb/chandlerdb/util/lock.py Mon Feb 21 16:28:58 2005
@@ -1,6 +1,42 @@
import os, errno
-from fcntl import lockf, LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN
+
+try:
+ from fcntl import lockf, LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN
+
+except ImportError:
+
+ # If fcntl is not available, we must be on Windows,
+ # so emulate the above fcntl symbols using msvcrt
+
+ import msvcrt
+
+ LOCK_SH = 0x01
+ LOCK_EX = 0x02
+ LOCK_NB = 0x04
+ LOCK_UN = 0x08
+
+ _locks = LOCK_SH | LOCK_EX | LOCK_NB
+
+ _modes = [ # Translate Posix lock flags to msvcrt flags
+ None, # 0 = no-op
+ msvcrt.LK_RLCK, # 1 = LOCK_SH
+ msvcrt.LK_LOCK, # 2 = LOCK_EX
+ None, # 3 = Error
+ None, # 4 = Error
+ msvcrt.LK_NBRLCK, # 5 = LOCK_SH+LOCK_NB
+ msvcrt.LK_NBLCK, # 6 = LOCK_EX+LOCK_NB
+ None, # 7 = Error
+ ]
+
+ def lockf(fileno,mode):
+ if mode & LOCK_UN:
+ msvcrt.locking(fileno, msvcrt.LK_UNLCK, 0)
+ if mode & _locks:
+ msmode = _modes[mode & _locks]
+ if msmode is None:
+ raise AssertionError("Invalid lock flags", mode)
+ msvcrt.locking(fileno, msmode, 0)
def open(file):
@@ -11,7 +47,7 @@
# Locks don't upgrade or downgrade on Windows, therefore this function has
# to be called with LOCK_UN in combination with a lock flag to fake
-# upgrading or downgrading of locks. See lock.c for Windows version.
+# upgrading or downgrading of locks.
def lock(fileno, mode):
if mode & ~LOCK_UN:
More information about the Commits
mailing list