forked from lix-project/lix
2cd468874f
Because config.h can #define things like _FILE_OFFSET_BITS=64 and not every compilation unit includes config.h, we currently compile half of Nix with _FILE_OFFSET_BITS=64 and other half with _FILE_OFFSET_BITS unset. This causes major havoc with the Settings class on e.g. 32-bit ARM, where different compilation units disagree with the struct layout. E.g.: diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc @@ -166,6 +166,8 @@ void Settings::update() _get(useSubstitutes, "build-use-substitutes"); + fprintf(stderr, "at Settings::update(): &useSubstitutes = %p\n", &nix::settings.useSubstitutes); _get(buildUsersGroup, "build-users-group"); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -138,6 +138,8 @@ void RemoteStore::initConnection(Connection & conn) void RemoteStore::setOptions(Connection & conn) { + fprintf(stderr, "at RemoteStore::setOptions(): &useSubstitutes = %p\n", &nix::settings.useSubstitutes); conn.to << wopSetOptions Gave me: at Settings::update(): &useSubstitutes = 0xb6e5c5cb at RemoteStore::setOptions(): &useSubstitutes = 0xb6e5c5c7 That was not a fun one to debug!
153 lines
3.1 KiB
C++
153 lines
3.1 KiB
C++
#pragma once
|
||
|
||
|
||
#include "ref.hh"
|
||
|
||
#include <string>
|
||
#include <list>
|
||
#include <set>
|
||
#include <memory>
|
||
|
||
#include <boost/format.hpp>
|
||
|
||
/* Before 4.7, gcc's std::exception uses empty throw() specifiers for
|
||
* its (virtual) destructor and what() in c++11 mode, in violation of spec
|
||
*/
|
||
#ifdef __GNUC__
|
||
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
|
||
#define EXCEPTION_NEEDS_THROW_SPEC
|
||
#endif
|
||
#endif
|
||
|
||
|
||
namespace nix {
|
||
|
||
|
||
/* Inherit some names from other namespaces for convenience. */
|
||
using std::string;
|
||
using std::list;
|
||
using std::set;
|
||
using std::vector;
|
||
using boost::format;
|
||
|
||
|
||
struct FormatOrString
|
||
{
|
||
string s;
|
||
FormatOrString(const string & s) : s(s) { };
|
||
FormatOrString(const format & f) : s(f.str()) { };
|
||
FormatOrString(const char * s) : s(s) { };
|
||
};
|
||
|
||
|
||
/* A helper for formatting strings. ‘fmt(format, a_0, ..., a_n)’ is
|
||
equivalent to ‘boost::format(format) % a_0 % ... %
|
||
... a_n’. However, ‘fmt(s)’ is equivalent to ‘s’ (so no %-expansion
|
||
takes place). */
|
||
|
||
inline void formatHelper(boost::format & f)
|
||
{
|
||
}
|
||
|
||
template<typename T, typename... Args>
|
||
inline void formatHelper(boost::format & f, T x, Args... args)
|
||
{
|
||
formatHelper(f % x, args...);
|
||
}
|
||
|
||
inline std::string fmt(const std::string & s)
|
||
{
|
||
return s;
|
||
}
|
||
|
||
inline std::string fmt(const char * s)
|
||
{
|
||
return s;
|
||
}
|
||
|
||
inline std::string fmt(const FormatOrString & fs)
|
||
{
|
||
return fs.s;
|
||
}
|
||
|
||
template<typename... Args>
|
||
inline std::string fmt(const std::string & fs, Args... args)
|
||
{
|
||
boost::format f(fs);
|
||
formatHelper(f, args...);
|
||
return f.str();
|
||
}
|
||
|
||
|
||
/* BaseError should generally not be caught, as it has Interrupted as
|
||
a subclass. Catch Error instead. */
|
||
class BaseError : public std::exception
|
||
{
|
||
protected:
|
||
string prefix_; // used for location traces etc.
|
||
string err;
|
||
public:
|
||
unsigned int status = 1; // exit status
|
||
|
||
template<typename... Args>
|
||
BaseError(unsigned int status, Args... args)
|
||
: err(fmt(args...))
|
||
, status(status)
|
||
{
|
||
}
|
||
|
||
template<typename... Args>
|
||
BaseError(Args... args)
|
||
: err(fmt(args...))
|
||
{
|
||
}
|
||
|
||
#ifdef EXCEPTION_NEEDS_THROW_SPEC
|
||
~BaseError() throw () { };
|
||
const char * what() const throw () { return err.c_str(); }
|
||
#else
|
||
const char * what() const noexcept { return err.c_str(); }
|
||
#endif
|
||
|
||
const string & msg() const { return err; }
|
||
const string & prefix() const { return prefix_; }
|
||
BaseError & addPrefix(const FormatOrString & fs);
|
||
};
|
||
|
||
#define MakeError(newClass, superClass) \
|
||
class newClass : public superClass \
|
||
{ \
|
||
public: \
|
||
using superClass::superClass; \
|
||
};
|
||
|
||
MakeError(Error, BaseError)
|
||
|
||
class SysError : public Error
|
||
{
|
||
public:
|
||
int errNo;
|
||
|
||
template<typename... Args>
|
||
SysError(Args... args)
|
||
: Error(addErrno(fmt(args...)))
|
||
{ }
|
||
|
||
private:
|
||
|
||
std::string addErrno(const std::string & s);
|
||
};
|
||
|
||
|
||
typedef list<string> Strings;
|
||
typedef set<string> StringSet;
|
||
|
||
|
||
/* Paths are just strings. */
|
||
typedef string Path;
|
||
typedef list<Path> Paths;
|
||
typedef set<Path> PathSet;
|
||
|
||
|
||
}
|