Skip to content

Commit

Permalink
Enforce code style in memtrace_ext
Browse files Browse the repository at this point in the history
  • Loading branch information
mephi42 committed Aug 15, 2024
1 parent e2dad47 commit 6d98d9f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
24 changes: 21 additions & 3 deletions fmt
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/usr/bin/env python3
from glob import glob
import subprocess
import sys

import click

from ci import git_ls_py_files


def main():
subprocess.check_call(["black", *git_ls_py_files(), *sys.argv[1:]])
@click.command()
@click.option("--check", is_flag=True)
def main(check):
if check:
black_args = ["--check"]
clang_format_args = ["--dry-run", "-Werror"]
else:
black_args = []
clang_format_args = ["-i"]
subprocess.check_call(["black", *git_ls_py_files(), *black_args])
subprocess.check_call(
[
"clang-format",
*glob("memtrace_ext/*.cc"),
*glob("memtrace_ext/*.h"),
*clang_format_args,
]
)


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions memtrace_ext/entries.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ class HeaderEntry : public B {
.GetValue();
}
const TraceId& GetTraceId() const {
return *reinterpret_cast<const TraceId *>(
this->GetData() + kTraceIdOffset);
return *reinterpret_cast<const TraceId*>(this->GetData() + kTraceIdOffset);
}

private:
Expand Down
7 changes: 3 additions & 4 deletions memtrace_ext/memtrace_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// clang-format on

#include "./align.h"
#include "./disasm.h"
#include "./debuginfo.h"
#include "./disasm.h"
#include "./endian.h"
#include "./entries.h"
#include "./machine.h"
Expand All @@ -47,7 +47,7 @@ constexpr size_t kHostWordSize = sizeof(void*);

void HexDump(std::FILE* f, const void* buf, size_t n) {
for (size_t i = 0; i < n; i++)
std::fprintf(f, "%02x", static_cast<const std::uint8_t *>(buf)[i]);
std::fprintf(f, "%02x", static_cast<const std::uint8_t*>(buf)[i]);
}

void ReprDump(std::FILE* f, const std::uint8_t* buf, size_t n) {
Expand Down Expand Up @@ -953,8 +953,7 @@ class Trace : public TraceBase {
InsnIndexHeader header;
if ((err = ReadHeader(indexPath.Get("header").c_str(), &header)) < 0)
return err;
if (header.traceId != header_.GetTraceId())
return -EINVAL;
if (header.traceId != header_.GetTraceId()) return -EINVAL;
if ((err = insnIndex_.Init(indexPath.Get("data").c_str(),
InitMode::OpenExisting)) < 0)
return err;
Expand Down

0 comments on commit 6d98d9f

Please sign in to comment.