Skip to content

Commit

Permalink
Merge pull request #2051 from hzeller/20231214-use-deleter-struct
Browse files Browse the repository at this point in the history
Use a deleter type insteadl of function pointer to close FILE.
  • Loading branch information
hzeller authored Dec 14, 2023
2 parents f82756d + 8af0921 commit d73cde5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion verilog/tools/kythe/kzip_creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr int kKZipCompressionLevel = 9;
} // namespace

KzipCreator::KzipCreator(absl::string_view output_path)
: zip_file_(fopen(std::string(output_path).c_str(), "wb"), &fclose),
: zip_file_(fopen(std::string(output_path).c_str(), "wb")),
archive_(kKZipCompressionLevel, [this](absl::string_view s) {
return fwrite(s.data(), 1, s.size(), zip_file_.get()) == s.size();
}) {
Expand Down
5 changes: 4 additions & 1 deletion verilog/tools/kythe/kzip_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class KzipCreator final {
const ::kythe::proto::IndexedCompilation &unit);

private:
std::unique_ptr<FILE, decltype(&fclose)> zip_file_;
struct file_closer {
void operator()(FILE *f) const noexcept { fclose(f); }
};
std::unique_ptr<FILE, file_closer> zip_file_;
verible::zip::Encoder archive_;
};

Expand Down

0 comments on commit d73cde5

Please sign in to comment.