summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-11-17 20:28:11 -0500
committergit <svn-admin@ruby-lang.org>2023-11-18 01:32:37 +0000
commitf479e629ab497f325091096819fa5bf60c0d03b2 (patch)
tree24553a2d1501d6ecbbc53fc0ea1930db9d75ed61
parent24fe22a5da21c9df8584a4ce6b6d1ce18ac41cc2 (diff)
[ruby/prism] Revert "Ensure serialized file is little endian"
https://github.com/ruby/prism/commit/4cec275fff
-rw-r--r--prism/defines.h10
-rw-r--r--prism/templates/lib/prism/serialize.rb.erb8
-rw-r--r--prism/templates/src/serialize.c.erb25
3 files changed, 9 insertions, 34 deletions
diff --git a/prism/defines.h b/prism/defines.h
index 28f4da11df..f89a0bed8e 100644
--- a/prism/defines.h
+++ b/prism/defines.h
@@ -74,14 +74,4 @@
# define snprintf _snprintf
#endif
-/**
- * Defined PRISM_WORDS_BIGENDIAN so we can ensure our serialization happens in
- * little endian format regardless of platform.
- */
-#if defined(WORDS_BIGENDIAN)
-# define PRISM_WORDS_BIGENDIAN
-#elif defined(AC_APPLE_UNIVERSAL_BUILD) && defined(__BIG_ENDIAN__)
-# define PRISM_WORDS_BIGENDIAN
-#endif
-
#endif
diff --git a/prism/templates/lib/prism/serialize.rb.erb b/prism/templates/lib/prism/serialize.rb.erb
index 517d4e8a24..2837504543 100644
--- a/prism/templates/lib/prism/serialize.rb.erb
+++ b/prism/templates/lib/prism/serialize.rb.erb
@@ -137,7 +137,7 @@ module Prism
comments, magic_comments, errors, warnings = load_metadata
- @constant_pool_offset = io.read(4).unpack1("L<")
+ @constant_pool_offset = io.read(4).unpack1("L")
@constant_pool = Array.new(load_varint, nil)
[load_node, comments, magic_comments, errors, warnings]
@@ -167,7 +167,7 @@ module Prism
end
def load_serialized_length
- io.read(4).unpack1("L<")
+ io.read(4).unpack1("L")
end
def load_optional_node
@@ -206,8 +206,8 @@ module Prism
unless constant
offset = constant_pool_offset + index * 8
- start = serialized.unpack1("L<", offset: offset)
- length = serialized.unpack1("L<", offset: offset + 4)
+ start = serialized.unpack1("L", offset: offset)
+ length = serialized.unpack1("L", offset: offset + 4)
constant =
if start.nobits?(1 << 31)
diff --git a/prism/templates/src/serialize.c.erb b/prism/templates/src/serialize.c.erb
index 2ecf7299c6..db4c91e0cd 100644
--- a/prism/templates/src/serialize.c.erb
+++ b/prism/templates/src/serialize.c.erb
@@ -47,21 +47,6 @@ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffe
}
}
-/**
- * Serialize a 32-bit integer to the given address always in little-endian.
- */
-static void
-pm_serialize_32(char *address, uint32_t value) {
-#ifdef PRISM_WORDS_BIGENDIAN
- address[0] = (char) ((value >> 24) & 0xFF);
- address[1] = (char) ((value >> 16) & 0xFF);
- address[2] = (char) ((value >> 8) & 0xFF);
- address[3] = (char) (value & 0xFF);
-#else
- memcpy(address, &value, sizeof(uint32_t));
-#endif
-}
-
static void
pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
pm_buffer_append_byte(buffer, (uint8_t) PM_NODE_TYPE(node));
@@ -133,7 +118,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
<%- if node.needs_serialized_length? -%>
// serialize length
uint32_t length = pm_sizet_to_u32(buffer->length - offset - sizeof(uint32_t));
- pm_serialize_32(buffer->value + length_offset, length);
+ memcpy(buffer->value + length_offset, &length, sizeof(uint32_t));
<%- end -%>
break;
}
@@ -246,7 +231,7 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
// Now we're going to serialize the offset of the constant pool back where
// we left space for it.
uint32_t length = pm_sizet_to_u32(buffer->length);
- pm_serialize_32(buffer->value + offset, length);
+ memcpy(buffer->value + offset, &length, sizeof(uint32_t));
// Now we're going to serialize the constant pool.
offset = buffer->length;
@@ -273,18 +258,18 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
assert(content_offset < owned_mask);
content_offset |= owned_mask;
- pm_serialize_32(buffer->value + buffer_offset, content_offset);
+ memcpy(buffer->value + buffer_offset, &content_offset, 4);
pm_buffer_append_bytes(buffer, constant->start, constant->length);
} else {
// Since this is a shared constant, we are going to write its
// source offset directly into the buffer.
uint32_t source_offset = pm_ptrdifft_to_u32(constant->start - parser->start);
- pm_serialize_32(buffer->value + buffer_offset, source_offset);
+ memcpy(buffer->value + buffer_offset, &source_offset, 4);
}
// Now we can write the length of the constant into the buffer.
uint32_t constant_length = pm_sizet_to_u32(constant->length);
- pm_serialize_32(buffer->value + buffer_offset + 4, constant_length);
+ memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
}
}
}