Sync ruby/yarp to 89a00203af

This commit is contained in:
Takashi Kokubun 2023-06-22 09:23:07 -07:00
parent e8fb84265c
commit 711cabec26
7 changed files with 167 additions and 138 deletions

View File

@ -3,6 +3,19 @@
require "yarp_test_helper"
class ParseTest < Test::Unit::TestCase
# Because we're reading the snapshots from disk, we need to make sure that
# they're encoded as UTF-8. When certain settings are present this might not
# always be the case (e.g., LANG=C or -Eascii-8bit). So here we force the
# default external encoding for the duration of the test.
def setup
@previous_default_external = Encoding.default_external
ignore_warnings { Encoding.default_external = Encoding::UTF_8 }
end
def teardown
ignore_warnings { Encoding.default_external = @previous_default_external }
end
def test_Ruby_3_2_plus
assert_operator RUBY_VERSION, :>=, "3.2.0", "ParseTest requires Ruby 3.2+"
end
@ -21,7 +34,6 @@ class ParseTest < Test::Unit::TestCase
# and the line breaks based on the length of the path.
def normalize_printed(printed)
printed
.b
.gsub(
/SourceFileNode \s*
\(\s* (\d+\.\.\.\d+) \s*\) \s*
@ -75,7 +87,7 @@ class ParseTest < Test::Unit::TestCase
assert_empty result.errors, value
if File.exist?(snapshot)
normalized = normalize_printed(File.binread(snapshot))
normalized = normalize_printed(File.read(snapshot))
# If the snapshot file exists, but the printed value does not match the
# snapshot, then update the snapshot file.
@ -115,4 +127,14 @@ class ParseTest < Test::Unit::TestCase
end
end
end
private
def ignore_warnings
previous_verbosity = $VERBOSE
$VERBOSE = nil
yield
ensure
$VERBOSE = previous_verbosity
end
end

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#include "extension.h"
#include "yarp/extension.h"
static VALUE rb_cYARP;
static VALUE rb_cYARPPack;

View File

@ -1,4 +1,4 @@
#include "extension.h"
#include "yarp/extension.h"
typedef enum {
YP_ISEQ_TYPE_TOP,

View File

@ -1,4 +1,4 @@
#include "extension.h"
#include "yarp/extension.h"
VALUE rb_cYARP;
VALUE rb_cYARPToken;

View File

@ -1521,10 +1521,12 @@ yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer)
// index in the buffer.
if (constant->id != 0) {
size_t buffer_offset = offset + ((constant->id - 1) * 8);
size_t source_offset = yp_long_to_u32(constant->start - parser->start);
uint32_t source_offset = yp_long_to_u32(constant->start - parser->start);
uint32_t constant_length = yp_ulong_to_u32(constant->length);
memcpy(buffer->value + buffer_offset, &source_offset, 4);
memcpy(buffer->value + buffer_offset + 4, &constant->length, 4);
memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
}
}
}

View File

@ -7544,7 +7544,11 @@ parse_target(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_no
// If there are arguments on the call node, then it can't be a method
// call ending with = or a local variable write, so it must be a
// syntax error. In this case we'll fall through to our default
// handling.
// handling. We need to free the value that we parsed because there
// is no way for us to attach it to the tree at this point.
if (value != NULL) {
yp_node_destroy(parser, value);
}
}
/* fallthrough */
default: