Skip to content

Commit

Permalink
Merge pull request #2311 from alcroito/fix_browse_python_3_11
Browse files Browse the repository at this point in the history
Fix browse to work with python 3.11
  • Loading branch information
jhasse authored Aug 23, 2023
2 parents 36843d3 + 6783497 commit 22b778c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/browse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ void RunBrowsePython(State* state, const char* ninja_command,
close(pipefd[0]);

// Write the script file into the stdin of the Python process.
ssize_t len = write(pipefd[1], kBrowsePy, sizeof(kBrowsePy));
if (len < (ssize_t)sizeof(kBrowsePy))
// Only write n - 1 bytes, because Python 3.11 does not allow null
// bytes in source code anymore, so avoid writing the null string
// terminator.
// See https://github.com/python/cpython/issues/96670
auto kBrowsePyLength = sizeof(kBrowsePy) - 1;
ssize_t len = write(pipefd[1], kBrowsePy, kBrowsePyLength);
if (len < (ssize_t)kBrowsePyLength)
perror("ninja: write");
close(pipefd[1]);
exit(0);
Expand Down

0 comments on commit 22b778c

Please sign in to comment.