File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88#include " nix/util/util.hh"
99#include " nix/util/hash.hh"
1010#include " nix/store/ssh.hh"
11+ #include " nix/util/deleter.hh"
1112
1213#include < git2/attr.h>
1314#include < git2/config.h>
Original file line number Diff line number Diff line change 1414#include " nix/util/thread-pool.hh"
1515#include " nix/util/pool.hh"
1616#include " nix/util/executable-path.hh"
17+ #include " nix/util/deleter.hh"
1718
1819#include < git2/attr.h>
1920#include < git2/blob.h>
Original file line number Diff line number Diff line change @@ -136,17 +136,6 @@ struct GitRepo
136136 virtual Hash dereferenceSingletonDirectory (const Hash & oid) = 0;
137137};
138138
139- // A helper to ensure that the `git_*_free` functions get called.
140- template <auto del>
141- struct Deleter
142- {
143- template <typename T>
144- void operator ()(T * p) const
145- {
146- del (p);
147- };
148- };
149-
150139// A helper to ensure that we don't leak objects returned by libgit2.
151140template <typename T>
152141struct Setter
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ namespace nix {
4+
5+ /* *
6+ * A helper for `std::unique_ptr` that ensures that C APIs that require manual memory management get properly freed. The
7+ * template parameter `del` is a function that takes a pointer and frees it.
8+ */
9+ template <auto del>
10+ struct Deleter
11+ {
12+ template <typename T>
13+ void operator ()(T * p) const
14+ {
15+ del (p);
16+ };
17+ };
18+
19+ } // namespace nix
Original file line number Diff line number Diff line change 1212#include " nix/util/types.hh"
1313#include " nix/util/file-descriptor.hh"
1414#include " nix/util/file-path.hh"
15+ #include " nix/util/deleter.hh"
1516
1617#include < filesystem>
1718#include < sys/types.h>
@@ -374,15 +375,7 @@ public:
374375 }
375376};
376377
377- struct DIRDeleter
378- {
379- void operator ()(DIR * dir) const
380- {
381- closedir (dir);
382- }
383- };
384-
385- typedef std::unique_ptr<DIR, DIRDeleter> AutoCloseDir;
378+ typedef std::unique_ptr<DIR, Deleter<closedir>> AutoCloseDir;
386379
387380/* *
388381 * Create a temporary directory.
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ headers = [ config_pub_h ] + files(
3131 ' config-impl.hh' ,
3232 ' configuration.hh' ,
3333 ' current-process.hh' ,
34+ ' deleter.hh' ,
3435 ' demangle.hh' ,
3536 ' english.hh' ,
3637 ' environment-variables.hh' ,
Original file line number Diff line number Diff line change 11#include " nix/cmd/command.hh"
22#include " nix/util/file-system.hh"
33#include " nix/util/signals.hh"
4- #include " nix/fetchers/git-utils .hh" // for Deleter
4+ #include " nix/util/deleter .hh"
55#include " nix/store/nar-info.hh"
66
77#include < future>
You can’t perform that action at this time.
0 commit comments