summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-09-06 12:43:36 -0400
committergit <svn-admin@ruby-lang.org>2023-09-07 14:01:21 +0000
commit194584f20277a63164789aa83ae3841ef6e6eb8c (patch)
tree803d88a237fd2ee871b924f2f90a649c77f9127c /test
parent0adca625ee34ced92da68ba144de32f44e7300cd (diff)
[ruby/yarp] Introduce owned constants
Before this commit, constants in the constant pool were assumed to be slices of the source string. This works in _almost_ all cases. There are times, however, when a string needs to be synthesized. This can occur when passing in locals that need to be scoped through eval, or when generating method names like `foo=`. After this commit, there is a single bit `owned` boolean on constants in the pool that indicates whether or not it is a slice of the source string. If it is not, it is assumed to be allocated memory that should be freed by the constant pool when the constant pool is freed. When serializing, the most significant bit in the location of the contents of the constant indicates whether or not it is owned. When it is, instead of 4 bytes for the source offset and 4 bytes for the length it is instead 4 bytes for the buffer offset and 4 bytes the length. The contents of the owned constants are embedded into the buffer after the constant pool itself. https://github.com/ruby/yarp/commit/461c047365
Diffstat (limited to 'test')
-rw-r--r--test/yarp/parse_serialize_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/yarp/parse_serialize_test.rb b/test/yarp/parse_serialize_test.rb
index 82a1c29d48..d3474f7104 100644
--- a/test/yarp/parse_serialize_test.rb
+++ b/test/yarp/parse_serialize_test.rb
@@ -14,6 +14,16 @@ module YARP
assert_equal __FILE__, find_file_node(result)&.filepath, "Expected the filepath to be set correctly"
end
+ def test_parse_serialize_with_locals
+ filepath = __FILE__
+ metadata = [filepath.bytesize, filepath.b, 1, 1, 1, "foo".b].pack("LA*LLLA*")
+
+ dumped = Debug.parse_serialize_file_metadata(filepath, metadata)
+ result = YARP.load(File.read(__FILE__), dumped)
+
+ assert_kind_of ParseResult, result, "Expected the return value to be a ParseResult"
+ end
+
private
def find_file_node(result)