diff options
| author | Congcong Kuo <congcong.kuo@gmail.com> | 2025-10-20 11:39:00 +0800 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-11-12 18:34:06 +0100 |
| commit | d1a9fb85a4d46722f06d01bde6f61acae3d9ea7a (patch) | |
| tree | 30aeae6c569b01d614ecc38a3e4eb86321a53ecd /nix/libutil | |
| parent | 6fe5e7f70714735a7a365c73965fc0bfdb3f9f31 (diff) | |
daemon: Use inline functions and variables instead of extern
Avoid separate declarations and definitions for so-called 'global' objects.
* nix/libstore/derivations.{cc, hh} (drvHashes): Use inline instead of separate
declaration and definition.
* nix/libstore/globals.{cc, hh} (settings, nixVersion): Same.
* nix/libstore/local-store.hh (drvsLogDir, deduplicationMinSize): Same.
* nix/libstore/optimise-store.cc (deduplicationMinSize): Same.
* nix/libstore/store-api.{cc, hh} (store): Same.
* nix/libutil/archive.{cc, hh} (defaultPathFilter): Same.
* nix/libutil/hash.{cc, hh} (base32Chars): Same and modify header files.
* nix/libutil/util.{cc, hh} (logType, verbosity, _writeToStderr,
_isInterrupted): Same.
* nix/local.mk: Modified according to the rename of shared.hh.
* nix/nix-daemon/guix-daemon.cc (blockInt, argvSaved, run): Same and
modify header files.
* nix/nix-daemon/nix-daemon.cc: Modify header files.
* nix/nix-daemon/shared.hh: Renamed to nix-daemon.hh
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'nix/libutil')
| -rw-r--r-- | nix/libutil/archive.cc | 2 | ||||
| -rw-r--r-- | nix/libutil/archive.hh | 2 | ||||
| -rw-r--r-- | nix/libutil/hash.cc | 4 | ||||
| -rw-r--r-- | nix/libutil/hash.hh | 7 | ||||
| -rw-r--r-- | nix/libutil/util.cc | 7 | ||||
| -rw-r--r-- | nix/libutil/util.hh | 8 |
6 files changed, 8 insertions, 22 deletions
diff --git a/nix/libutil/archive.cc b/nix/libutil/archive.cc index fa9f4398e3c..938fe8d4492 100644 --- a/nix/libutil/archive.cc +++ b/nix/libutil/archive.cc | |||
| @@ -24,8 +24,6 @@ static string archiveVersion1 = "nix-archive-1"; | |||
| 24 | 24 | ||
| 25 | static string caseHackSuffix = "~nix~case~hack~"; | 25 | static string caseHackSuffix = "~nix~case~hack~"; |
| 26 | 26 | ||
| 27 | PathFilter defaultPathFilter; | ||
| 28 | |||
| 29 | 27 | ||
| 30 | static void dumpContents(const Path & path, size_t size, | 28 | static void dumpContents(const Path & path, size_t size, |
| 31 | Sink & sink) | 29 | Sink & sink) |
diff --git a/nix/libutil/archive.hh b/nix/libutil/archive.hh index 9b83a5f288f..03716ab469f 100644 --- a/nix/libutil/archive.hh +++ b/nix/libutil/archive.hh | |||
| @@ -50,7 +50,7 @@ struct PathFilter | |||
| 50 | virtual bool operator () (const Path & path) { return true; } | 50 | virtual bool operator () (const Path & path) { return true; } |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | extern PathFilter defaultPathFilter; | 53 | inline PathFilter defaultPathFilter; |
| 54 | 54 | ||
| 55 | void dumpPath(const Path & path, Sink & sink, | 55 | void dumpPath(const Path & path, Sink & sink, |
| 56 | PathFilter & filter = defaultPathFilter); | 56 | PathFilter & filter = defaultPathFilter); |
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 57b369d4a9b..ac9eb14514b 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc | |||
| @@ -103,10 +103,6 @@ unsigned int hashLength32(const Hash & hash) | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | 105 | ||
| 106 | // omitted: E O U T | ||
| 107 | const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; | ||
| 108 | |||
| 109 | |||
| 110 | string printHash32(const Hash & hash) | 106 | string printHash32(const Hash & hash) |
| 111 | { | 107 | { |
| 112 | Hash hash2(hash); | 108 | Hash hash2(hash); |
diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh index 1a6b35f074b..cedb5077c16 100644 --- a/nix/libutil/hash.hh +++ b/nix/libutil/hash.hh | |||
| @@ -2,14 +2,15 @@ | |||
| 2 | 2 | ||
| 3 | #include <gcrypt.h> | 3 | #include <gcrypt.h> |
| 4 | 4 | ||
| 5 | #include "archive.hh" | ||
| 5 | #include "types.hh" | 6 | #include "types.hh" |
| 6 | #include "serialise.hh" | 7 | #include "serialise.hh" |
| 7 | 8 | ||
| 8 | 9 | ||
| 9 | namespace nix { | 10 | namespace nix { |
| 10 | 11 | ||
| 11 | 12 | // omitted: E O U T | |
| 12 | extern const string base32Chars; | 13 | inline const string base32Chars {"0123456789abcdfghijklmnpqrsvwxyz"}; |
| 13 | 14 | ||
| 14 | typedef enum { | 15 | typedef enum { |
| 15 | htUnknown = 0, | 16 | htUnknown = 0, |
| @@ -79,8 +80,6 @@ Hash hashFile(HashType ht, const Path & path); | |||
| 79 | 80 | ||
| 80 | /* Compute the hash of the given path. The hash is defined as | 81 | /* Compute the hash of the given path. The hash is defined as |
| 81 | (essentially) hashString(ht, dumpPath(path)). */ | 82 | (essentially) hashString(ht, dumpPath(path)). */ |
| 82 | struct PathFilter; | ||
| 83 | extern PathFilter defaultPathFilter; | ||
| 84 | typedef std::pair<Hash, unsigned long long> HashResult; | 83 | typedef std::pair<Hash, unsigned long long> HashResult; |
| 85 | HashResult hashPath(HashType ht, const Path & path, | 84 | HashResult hashPath(HashType ht, const Path & path, |
| 86 | PathFilter & filter = defaultPathFilter); | 85 | PathFilter & filter = defaultPathFilter); |
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 22022db51a5..ed1a371dfe1 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc | |||
| @@ -600,9 +600,6 @@ void createSymlink(const Path & target, const Path & link) | |||
| 600 | } | 600 | } |
| 601 | 601 | ||
| 602 | 602 | ||
| 603 | LogType logType = ltPretty; | ||
| 604 | Verbosity verbosity = lvlInfo; | ||
| 605 | |||
| 606 | static int nestingLevel = 0; | 603 | static int nestingLevel = 0; |
| 607 | 604 | ||
| 608 | 605 | ||
| @@ -691,9 +688,6 @@ void writeToStderr(const string & s) | |||
| 691 | } | 688 | } |
| 692 | 689 | ||
| 693 | 690 | ||
| 694 | void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0; | ||
| 695 | |||
| 696 | |||
| 697 | void readFull(int fd, unsigned char * buf, size_t count) | 691 | void readFull(int fd, unsigned char * buf, size_t count) |
| 698 | { | 692 | { |
| 699 | while (count) { | 693 | while (count) { |
| @@ -1250,7 +1244,6 @@ void keepOnExec(int fd) | |||
| 1250 | ////////////////////////////////////////////////////////////////////// | 1244 | ////////////////////////////////////////////////////////////////////// |
| 1251 | 1245 | ||
| 1252 | 1246 | ||
| 1253 | volatile sig_atomic_t _isInterrupted = 0; | ||
| 1254 | 1247 | ||
| 1255 | void _interrupted() | 1248 | void _interrupted() |
| 1256 | { | 1249 | { |
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 436c378cb6e..42cb60ea0d4 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh | |||
| @@ -132,8 +132,8 @@ typedef enum { | |||
| 132 | ltFlat /* no nesting */ | 132 | ltFlat /* no nesting */ |
| 133 | } LogType; | 133 | } LogType; |
| 134 | 134 | ||
| 135 | extern LogType logType; | 135 | inline LogType logType {ltPretty}; |
| 136 | extern Verbosity verbosity; /* suppress msgs > this */ | 136 | inline Verbosity verbosity {lvlInfo}; /* suppress msgs > this */ |
| 137 | 137 | ||
| 138 | class Nest | 138 | class Nest |
| 139 | { | 139 | { |
| @@ -167,7 +167,7 @@ void warnOnce(bool & haveWarned, std::string_view fs); | |||
| 167 | 167 | ||
| 168 | void writeToStderr(const string & s); | 168 | void writeToStderr(const string & s); |
| 169 | 169 | ||
| 170 | extern void (*_writeToStderr) (const unsigned char * buf, size_t count); | 170 | inline void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0; |
| 171 | 171 | ||
| 172 | 172 | ||
| 173 | /* Wrappers arount read()/write() that read/write exactly the | 173 | /* Wrappers arount read()/write() that read/write exactly the |
| @@ -323,7 +323,7 @@ void commonChildInit(Pipe & logPipe); | |||
| 323 | 323 | ||
| 324 | /* User interruption. */ | 324 | /* User interruption. */ |
| 325 | 325 | ||
| 326 | extern volatile sig_atomic_t _isInterrupted; | 326 | inline volatile sig_atomic_t _isInterrupted = 0; |
| 327 | 327 | ||
| 328 | void _interrupted(); | 328 | void _interrupted(); |
| 329 | 329 | ||
