You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling nix_get_int without prior initialization with nix_init_int will result in a segmentation fault.
This is because attempts to get the type of an uninitialized value triggers a call to abort():
case tList1: case tList2: case tListN: return nList;
case tLambda: case tPrimOp: case tPrimOpApp: return nFunction;
case tExternal: return nExternal;
case tFloat: return nFloat;
case tThunk: case tApp: return nThunk;
}
if (invalidIsThunk)
return nThunk;
else
abort();
}
Describe the solution you'd like
I suggest to add an isInitialized method to Value for checking initialization in the C API. This would allow us to raise an exception instead of calling abort.
I'm happy to open a PR with these changes, but I'd like to confirm if the approach makes sense.
Add a method to check if a value has been initialized. This helps avoid
segfaults when calling `type()`.
Useful in the context of the new C API.
ClosesNixOS#10524
Add a method to check if a value has been initialized. This helps avoid
segfaults when calling `type()`.
Useful in the context of the new C API.
ClosesNixOS#10524
Add a method to check if a value has been initialized. This helps avoid
segfaults when calling `type()`.
Useful in the context of the new C API.
ClosesNixOS#10524
Is your feature request related to a problem? Please describe.
In the C API, the way we set a value is roughly like this:
Calling
nix_get_int
without prior initialization withnix_init_int
will result in a segmentation fault.This is because attempts to get the type of an uninitialized value triggers a call to
abort()
:nix/src/libexpr/value.hh
Lines 268 to 287 in 74e4bc9
Describe the solution you'd like
I suggest to add an
isInitialized
method toValue
for checking initialization in the C API. This would allow us to raise an exception instead of calling abort.I'm happy to open a PR with these changes, but I'd like to confirm if the approach makes sense.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: