Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix complex transi compact #547

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3bc41f4
[ruby/prism] Add macGreek encoding
kddnewton Nov 16, 2023
498b086
Skip test_ForwardingArgumentsNode
mame Nov 17, 2023
94c9f16
Refactor rb_obj_evacuate_ivs_to_hash_table
byroot Nov 16, 2023
940f2e7
size_pool_idx_for_size: Include debugging info in error message
byroot Nov 17, 2023
4a26a65
[ruby/prism] Add macTurkish
haldun Nov 16, 2023
9ba49c6
mingw.yml - remove encoding, run tests in cmd shell
MSP-Greg Nov 16, 2023
c2f2090
[ruby/prism] Do not test locale encoding on windows
kddnewton Nov 17, 2023
db4303f
[ruby/prism] Never test locale encoding
kddnewton Nov 17, 2023
e5d6b40
[ruby/prism] Do not allow trailing commas in calls without parenthesis
haldun Nov 13, 2023
85dcfef
[ruby/prism] Add macUkraine
haldun Nov 17, 2023
0a081a3
[ruby/prism] Add macRoman
haldun Nov 17, 2023
50b7b92
[ruby/prism] Add macThai
haldun Nov 17, 2023
229f6e5
[ruby/prism] Update spacing in encoding_test.rb
kddnewton Nov 17, 2023
585fdfe
[ruby/prism] add Windows-874 encoding
pcai Nov 17, 2023
cbdac2f
[ruby/prism] Silence clang analyzer warnings for the memory leaks
haldun Nov 17, 2023
7c99e43
[ruby/prism] Ensure serialized file is little endian
kddnewton Nov 13, 2023
3dd77bc
Fix corruption when out of shape during ivar remove
peterzhu2118 Nov 17, 2023
ef72970
Fix File.directory? doc hidding File::Stat#directory? doc
robotdana Nov 17, 2023
24fe22a
Fix ordering for auto compaction in get_overloaded_cme()
XrXr Nov 17, 2023
f479e62
[ruby/prism] Revert "Ensure serialized file is little endian"
kddnewton Nov 18, 2023
97fb07d
Pin object ivars while they are being copied in a hash
byroot Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ruby/prism] Ensure serialized file is little endian
  • Loading branch information
kddnewton authored and matzbot committed Nov 17, 2023
commit 7c99e43c3f050244b06dbd18de4f605ea70d234c
10 changes: 10 additions & 0 deletions prism/defines.h
Original file line number Diff line number Diff line change
@@ -74,4 +74,14 @@
# 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
8 changes: 4 additions & 4 deletions prism/templates/lib/prism/serialize.rb.erb
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 20 additions & 5 deletions prism/templates/src/serialize.c.erb
Original file line number Diff line number Diff line change
@@ -47,6 +47,21 @@ 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));
@@ -118,7 +133,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));
memcpy(buffer->value + length_offset, &length, sizeof(uint32_t));
pm_serialize_32(buffer->value + length_offset, length);
<%- end -%>
break;
}
@@ -231,7 +246,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);
memcpy(buffer->value + offset, &length, sizeof(uint32_t));
pm_serialize_32(buffer->value + offset, length);

// Now we're going to serialize the constant pool.
offset = buffer->length;
@@ -258,18 +273,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;

memcpy(buffer->value + buffer_offset, &content_offset, 4);
pm_serialize_32(buffer->value + buffer_offset, content_offset);
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);
memcpy(buffer->value + buffer_offset, &source_offset, 4);
pm_serialize_32(buffer->value + buffer_offset, source_offset);
}

// Now we can write the length of the constant into the buffer.
uint32_t constant_length = pm_sizet_to_u32(constant->length);
memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
pm_serialize_32(buffer->value + buffer_offset + 4, constant_length);
}
}
}