Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42c83af

Browse files
committed
The 2.0b2 change to write .pyc files in exclusive mode (if possible)
unintentionally caused them to get written in text mode under Windows. As a result, when .pyc files were later read-- in binary mode --the magic number was always wrong (note that .pyc magic numbers deliberately include \r and \n characters, so this was "good" breakage, 100% across all .pyc files, not random corruption in a subset). Fixed that.
1 parent 3cc7e4d commit 42c83af

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Python/import.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ open_exclusive(char *filename)
646646
*/
647647
int fd;
648648
(void) unlink(filename);
649-
fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC, 0666);
649+
fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC
650+
#ifdef O_BINARY
651+
|O_BINARY /* necessary for Windows */
652+
#endif
653+
654+
, 0666);
650655
if (fd < 0)
651656
return NULL;
652657
return fdopen(fd, "wb");

0 commit comments

Comments
 (0)