summaryrefslogtreecommitdiff
path: root/nix/libutil
diff options
context:
space:
mode:
authorCongcong Kuo <congcong.kuo@gmail.com>2025-10-20 11:39:00 +0800
committerLudovic Courtès <ludo@gnu.org>2025-11-12 18:34:06 +0100
commitd1a9fb85a4d46722f06d01bde6f61acae3d9ea7a (patch)
tree30aeae6c569b01d614ecc38a3e4eb86321a53ecd /nix/libutil
parent6fe5e7f70714735a7a365c73965fc0bfdb3f9f31 (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.cc2
-rw-r--r--nix/libutil/archive.hh2
-rw-r--r--nix/libutil/hash.cc4
-rw-r--r--nix/libutil/hash.hh7
-rw-r--r--nix/libutil/util.cc7
-rw-r--r--nix/libutil/util.hh8
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
25static string caseHackSuffix = "~nix~case~hack~"; 25static string caseHackSuffix = "~nix~case~hack~";
26 26
27PathFilter defaultPathFilter;
28
29 27
30static void dumpContents(const Path & path, size_t size, 28static 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
53extern PathFilter defaultPathFilter; 53inline PathFilter defaultPathFilter;
54 54
55void dumpPath(const Path & path, Sink & sink, 55void 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
107const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz";
108
109
110string printHash32(const Hash & hash) 106string 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
9namespace nix { 10namespace nix {
10 11
11 12// omitted: E O U T
12extern const string base32Chars; 13inline const string base32Chars {"0123456789abcdfghijklmnpqrsvwxyz"};
13 14
14typedef enum { 15typedef 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)). */
82struct PathFilter;
83extern PathFilter defaultPathFilter;
84typedef std::pair<Hash, unsigned long long> HashResult; 83typedef std::pair<Hash, unsigned long long> HashResult;
85HashResult hashPath(HashType ht, const Path & path, 84HashResult 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
603LogType logType = ltPretty;
604Verbosity verbosity = lvlInfo;
605
606static int nestingLevel = 0; 603static int nestingLevel = 0;
607 604
608 605
@@ -691,9 +688,6 @@ void writeToStderr(const string & s)
691} 688}
692 689
693 690
694void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0;
695
696
697void readFull(int fd, unsigned char * buf, size_t count) 691void 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
1253volatile sig_atomic_t _isInterrupted = 0;
1254 1247
1255void _interrupted() 1248void _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
135extern LogType logType; 135inline LogType logType {ltPretty};
136extern Verbosity verbosity; /* suppress msgs > this */ 136inline Verbosity verbosity {lvlInfo}; /* suppress msgs > this */
137 137
138class Nest 138class Nest
139{ 139{
@@ -167,7 +167,7 @@ void warnOnce(bool & haveWarned, std::string_view fs);
167 167
168void writeToStderr(const string & s); 168void writeToStderr(const string & s);
169 169
170extern void (*_writeToStderr) (const unsigned char * buf, size_t count); 170inline 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
326extern volatile sig_atomic_t _isInterrupted; 326inline volatile sig_atomic_t _isInterrupted = 0;
327 327
328void _interrupted(); 328void _interrupted();
329 329