bit2fasm: close the temporary bits file before bitread writes it

The temporary bits file was created with NamedTemporaryFile() and kept
open while the bitread subprocess wrote to it by name. On Windows that
is a sharing violation (the open handle blocks the child's write), so
bit2fasm always failed there. Create the file with delete=False, close
it immediately, and unlink it via the ExitStack instead.

No behaviour change on POSIX beyond the file being closed while
bitread runs.
This commit is contained in:
Carlos Venegas Arrabé 2026-07-30 16:19:15 +02:00
parent 6731005c1e
commit 19d29f9c84
No known key found for this signature in database
GPG Key ID: EC73A5348B584C4C
1 changed files with 6 additions and 1 deletions

View File

@ -108,7 +108,12 @@ def main():
if args.bits_file:
bits_file = stack.enter_context(open(args.bits_file, 'wb'))
else:
bits_file = stack.enter_context(tempfile.NamedTemporaryFile())
# On Windows an open NamedTemporaryFile cannot be re-opened by
# the bitread subprocess (sharing violation): create it closed
# and clean it up ourselves.
bits_file = tempfile.NamedTemporaryFile(delete=False)
bits_file.close()
stack.callback(os.unlink, bits_file.name)
bit_to_bits(
bitread=args.bitread,