diff --git a/cmd/joj3/conf/model.go b/cmd/joj3/conf/model.go index 031fd14..ae5e33e 100644 --- a/cmd/joj3/conf/model.go +++ b/cmd/joj3/conf/model.go @@ -16,7 +16,7 @@ type ConfStage struct { } Parsers []struct { Name string - With interface{} + With any } } diff --git a/internal/executor/local/executor.go b/internal/executor/local/executor.go index 7679cef..565c0be 100644 --- a/internal/executor/local/executor.go +++ b/internal/executor/local/executor.go @@ -113,10 +113,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) { if err := syscall.Getrlimit(syscall.RLIMIT_CPU, ¤t); err != nil { return nil, nil, fmt.Errorf("getrlimit RLIMIT_CPU failed: %w", err) } - userTimeLimit := (uint64(cmd.CPULimit) + 1e9 - 1) / 1e9 // ns to s - if userTimeLimit > current.Max { - userTimeLimit = current.Max - } + userTimeLimit := min((uint64(cmd.CPULimit)+1e9-1)/1e9, current.Max) // ns to s rlimits = append(rlimits, syscall.Rlimit{ Cur: userTimeLimit, Max: current.Max, @@ -128,10 +125,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) { if err := syscall.Getrlimit(syscall.RLIMIT_DATA, ¤t); err != nil { return nil, nil, fmt.Errorf("getrlimit RLIMIT_DATA failed: %w", err) } - userMemLimit := cmd.MemoryLimit - if userMemLimit > current.Max { - userMemLimit = current.Max - } + userMemLimit := min(cmd.MemoryLimit, current.Max) rlimits = append(rlimits, syscall.Rlimit{ Cur: userMemLimit, Max: current.Max, @@ -143,10 +137,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) { if err := syscall.Getrlimit(syscall.RLIMIT_STACK, ¤t); err != nil { return nil, nil, fmt.Errorf("getrlimit RLIMIT_STACK failed: %w", err) } - userStackLimit := cmd.StackLimit - if userStackLimit > current.Max { - userStackLimit = current.Max - } + userStackLimit := min(cmd.StackLimit, current.Max) rlimits = append(rlimits, syscall.Rlimit{ Cur: userStackLimit, Max: current.Max, diff --git a/internal/executor/sandbox/executor.go b/internal/executor/sandbox/executor.go index f58e48f..dda11bb 100644 --- a/internal/executor/sandbox/executor.go +++ b/internal/executor/sandbox/executor.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "maps" "github.com/criyle/go-judge/pb" "github.com/joint-online-judge/JOJ3/internal/stage" @@ -46,9 +47,7 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { } results := convertPBResult(pbRet.Results) for _, result := range results { - for fileName, fileID := range result.FileIDs { - e.cachedMap[fileName] = fileID - } + maps.Copy(e.cachedMap, result.FileIDs) } return results, nil } diff --git a/internal/parser/clangtidy/formatter.go b/internal/parser/clangtidy/formatter.go index 85ad3c2..46b6225 100644 --- a/internal/parser/clangtidy/formatter.go +++ b/internal/parser/clangtidy/formatter.go @@ -7,14 +7,14 @@ import ( // Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py type JsonMessage struct { - Type string `json:"type"` - CheckName string `json:"checkname"` - Description string `json:"description"` - Content map[string]interface{} `json:"content"` - Categories []string `json:"categories"` - Location map[string]interface{} `json:"location"` - Trace map[string]interface{} `json:"trace"` - Severity string `json:"severity"` + Type string `json:"type"` + CheckName string `json:"checkname"` + Description string `json:"description"` + Content map[string]any `json:"content"` + Categories []string `json:"categories"` + Location map[string]any `json:"location"` + Trace map[string]any `json:"trace"` + Severity string `json:"severity"` } func format(messages []ClangMessage) []JsonMessage { @@ -49,7 +49,7 @@ func messagesToText(messages []ClangMessage) []string { return textLines } -func extractContent(message ClangMessage) map[string]interface{} { +func extractContent(message ClangMessage) map[string]any { detailLines := "" for _, line := range message.detailsLines { if line == "" { @@ -63,7 +63,7 @@ func extractContent(message ClangMessage) map[string]interface{} { } detailLines += (line + "\n") } - result := map[string]interface{}{ + result := map[string]any{ "body": "```\n" + detailLines + "```", } return result @@ -140,18 +140,18 @@ func extractCategories(message ClangMessage) []string { return removeDuplicates(categories) } -func extractLocation(message ClangMessage) map[string]interface{} { - location := map[string]interface{}{ +func extractLocation(message ClangMessage) map[string]any { + location := map[string]any{ "path": message.filepath, - "lines": map[string]interface{}{ + "lines": map[string]any{ "begin": message.line, }, } return location } -func extractOtherLocations(message ClangMessage) []map[string]interface{} { - locationList := []map[string]interface{}{} +func extractOtherLocations(message ClangMessage) []map[string]any { + locationList := []map[string]any{} for _, child := range message.children { locationList = append(locationList, extractLocation(child)) locationList = append(locationList, extractOtherLocations(child)...) @@ -159,8 +159,8 @@ func extractOtherLocations(message ClangMessage) []map[string]interface{} { return locationList } -func extractTrace(message ClangMessage) map[string]interface{} { - result := map[string]interface{}{ +func extractTrace(message ClangMessage) map[string]any { + result := map[string]any{ "locations": extractOtherLocations(message), } return result diff --git a/internal/parser/cppcheck/parser.go b/internal/parser/cppcheck/parser.go index 64a09de..b1560d7 100644 --- a/internal/parser/cppcheck/parser.go +++ b/internal/parser/cppcheck/parser.go @@ -21,8 +21,8 @@ func (*CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.Par // stdout := executorResult.Files[conf.Stdout] stderr := executorResult.Files[conf.Stderr] records := make([]Record, 0) - lines := strings.Split(stderr, "\n") - for _, line := range lines { + lines := strings.SplitSeq(stderr, "\n") + for line := range lines { if strings.TrimSpace(line) == "" { continue }