1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

Merge pull request #10555 from jlesquembre/jl/c-api_check-init

Add isValid to nix::Value
This commit is contained in:
Robert Hensing 2024-05-01 16:33:01 +02:00 committed by GitHub
commit e17aad23d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 203 additions and 59 deletions

View file

@ -23,6 +23,7 @@ class BindingsBuilder;
typedef enum {
tUninitialized = 0,
tInt = 1,
tBool,
tString,
@ -166,7 +167,7 @@ public:
struct Value
{
private:
InternalType internalType;
InternalType internalType = tUninitialized;
friend std::string showType(const Value & v);
@ -270,6 +271,7 @@ public:
inline ValueType type(bool invalidIsThunk = false) const
{
switch (internalType) {
case tUninitialized: break;
case tInt: return nInt;
case tBool: return nBool;
case tString: return nString;
@ -294,6 +296,16 @@ public:
internalType = newType;
}
/**
* A value becomes valid when it is initialized. We don't use this
* in the evaluator; only in the bindings, where the slight extra
* cost is warranted because of inexperienced callers.
*/
inline bool isValid() const
{
return internalType != tUninitialized;
}
inline void mkInt(NixInt n)
{
finishValue(tInt, { .integer = n });