From 10381074b26da703a4330272166c81984e66dd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Venegas=20Arrab=C3=A9?= Date: Thu, 30 Jul 2026 16:19:34 +0200 Subject: [PATCH] util: make OpenSafeFile work without fcntl (Windows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prjxray/util.py imported fcntl at module level, so merely importing prjxray (e.g. from fasm2frames) failed on Windows, where fcntl does not exist. The only user is OpenSafeFile's advisory flock, whose timeout also relies on SIGALRM — equally POSIX-only. Guard the import and skip the locking when fcntl is unavailable: OpenSafeFile degrades to a plain open on Windows, while POSIX behaviour is unchanged. --- prjxray/util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/prjxray/util.py b/prjxray/util.py index 615bf726..1fc1ac04 100644 --- a/prjxray/util.py +++ b/prjxray/util.py @@ -8,7 +8,12 @@ # https://opensource.org/licenses/ISC # # SPDX-License-Identifier: ISC -import fcntl +try: + import fcntl +except ImportError: + # Windows: no fcntl (and no SIGALRM); OpenSafeFile degrades to a plain + # open without inter-process locking. + fcntl = None import math import os import random @@ -47,6 +52,8 @@ class OpenSafeFile: def lock_file(self): assert self.fd is not None + if fcntl is None: + return try: signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(self.timeout) @@ -58,6 +65,8 @@ class OpenSafeFile: def unlock_file(self): assert self.fd is not None + if fcntl is None: + return fcntl.flock(self.fd.fileno(), fcntl.LOCK_UN)