Skip to content

Commit

Permalink
executors: pretend compilers are connected to a 1024x1024 pty
Browse files Browse the repository at this point in the history
Otherwise, some runtimes (namely Algol 68 Genie) may try
word-wrapping error messages to 1 column.
  • Loading branch information
Xyene committed May 26, 2024
1 parent 8887b24 commit c72b8c1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dmoj/executors/compiled_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import fcntl
import hashlib
import os
import pty
import struct
import termios
from typing import Any, Dict, IO, List, Optional, Tuple, Union

import pylru
Expand Down Expand Up @@ -126,6 +129,11 @@ def create_compile_process(self, args: List[str]) -> TracedPopen:
#
# Emulate the streams of a process connected to a terminal: stdin, stdout, and stderr are all ptys.
_master, _slave = pty.openpty()

# Some runtimes helpfully try to word-wrap error messages by determining the width of the screen. Lie and say
# we're a 1024x1024 terminal, so they don't try wrapping to 1-column width.
fcntl.ioctl(_slave, termios.TIOCSWINSZ, struct.pack('HHHH', 1024, 1024, 0, 0))

# Some runtimes *cough cough* Swift *cough cough* actually check the environment variables too.
env = self.get_compile_env() or os.environ.copy()
env['TERM'] = 'xterm'
Expand Down

0 comments on commit c72b8c1

Please sign in to comment.