mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 09:49:36 +01:00
Use hybrid C / Pascal strings in the evaluator
Replace the null-terminated C-style strings in Value with hybrid C / Pascal strings, where the length is stored in the allocation before the data, and there is still a null byte at the end for the sake of C interopt. Co-Authored-By: Taeer Bar-Yam <taeer@bar-yam.me> Co-Authored-By: Sergei Zimmerman <sergei@zimmerman.foo>
This commit is contained in:
parent
8c113f80f3
commit
3bf8c76072
14 changed files with 279 additions and 100 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "nix/expr/value.hh"
|
||||
#include "nix/expr/static-string-data.hh"
|
||||
|
||||
#include "nix/store/tests/libstore.hh"
|
||||
#include <gtest/gtest.h>
|
||||
|
|
@ -27,17 +28,17 @@ TEST_F(ValueTest, staticString)
|
|||
{
|
||||
Value vStr1;
|
||||
Value vStr2;
|
||||
vStr1.mkStringNoCopy("foo");
|
||||
vStr2.mkStringNoCopy("foo");
|
||||
vStr1.mkStringNoCopy("foo"_sds);
|
||||
vStr2.mkStringNoCopy("foo"_sds);
|
||||
|
||||
auto sd1 = vStr1.string_view();
|
||||
auto sd2 = vStr2.string_view();
|
||||
auto & sd1 = vStr1.string_data();
|
||||
auto & sd2 = vStr2.string_data();
|
||||
|
||||
// The strings should be the same
|
||||
ASSERT_EQ(sd1, sd2);
|
||||
ASSERT_EQ(sd1.view(), sd2.view());
|
||||
|
||||
// The strings should also be backed by the same (static) allocation
|
||||
ASSERT_EQ(sd1.data(), sd2.data());
|
||||
ASSERT_EQ(&sd1, &sd2);
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue