rbs 3.10.1 → 3.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0e199e19fdc063a93575bc59d1daff68480bc7c678e0b9a00a20bd882c0167f
4
- data.tar.gz: 42415916b4eebb2b739ce009088fd8fcec8c02a8ad0c4169ccf57dd9b69bba79
3
+ metadata.gz: 70df198075a49a0a5368d2eee44e7027b76467fa56551b23280b5bba9b9bd823
4
+ data.tar.gz: 179815f7909503adc3b948e63f01ec185abc3da7ea1598e4847cc1d097074e3b
5
5
  SHA512:
6
- metadata.gz: a9ba79e77d4f6ca3b57f6a89e245e20edd6ceba274475ad435a4bfb45e78dc17e4ab3ca033b208279b4ee1bef0498d82459ef912bbc2dfcabb16c921f4802e72
7
- data.tar.gz: 8c8100da156288e99931d15f0a3e61439a08d51e3d85605f95770d62cdfc4e1fd3cc71ede93763ce08e480084ed8301a26b781db3988b7fc931ea727fccd7e29
6
+ metadata.gz: 99ccdcfdfe2cbf1aa0462df15cdd731b7e48e17014265da20769922ac4dedd90710b55370eff2ed0a35d1f14f9d571c6c1b9138fdd54cf9a3a73e6ba6dfd37dd
7
+ data.tar.gz: 4daa010fef1e4ab1d0fac6c6c8e1a5e4bcad2fe08ff154a4e731389a8d18cc78de30f21be6207a737e4d757d93ef2e09ef5629a65ce17fa191d14d415bcdb95a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.10.2 (2026-01-07)
4
+
5
+ This is a minor fix on arena allocator alignment.
6
+
7
+ ### Pull Requests
8
+
9
+ * Merge pull request #2788 from ruby/fix-alloc-alignment ([#2790](https://github.com/ruby/rbs/pull/2790))
10
+
3
11
  ## 3.10.1 (2026-01-07)
4
12
 
5
13
  This is a follow-up release for Ruby 4.0.0 with documentation update based on Ruby 4.0.0, and bugfixes related to set/pathname library loading.
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.10.1"
4
+ VERSION = "3.10.2"
5
5
  end
@@ -54,6 +54,12 @@ static size_t get_system_page_size(void) {
54
54
  #endif
55
55
  }
56
56
 
57
+ static inline uintptr_t rbs_align_up_uintptr(uintptr_t value, size_t alignment) {
58
+ // alignment must be a non-zero power of two
59
+ RBS_ASSERT(alignment != 0 && (alignment & (alignment - 1)) == 0, "alignment must be a non-zero power of two. alignment: %zu", alignment);
60
+ return (value + (alignment - 1)) & ~(uintptr_t) (alignment - 1);
61
+ }
62
+
57
63
  static rbs_allocator_page_t *rbs_allocator_page_new(size_t payload_size) {
58
64
  const size_t page_header_size = sizeof(rbs_allocator_page_t);
59
65
 
@@ -98,10 +104,9 @@ void *rbs_allocator_realloc_impl(rbs_allocator_t *allocator, void *ptr, size_t o
98
104
 
99
105
  // Allocates `size` bytes from `allocator`, aligned to an `alignment`-byte boundary.
100
106
  void *rbs_allocator_malloc_impl(rbs_allocator_t *allocator, size_t size, size_t alignment) {
101
- RBS_ASSERT(size % alignment == 0, "size must be a multiple of the alignment. size: %zu, alignment: %zu", size, alignment);
102
-
103
107
  if (allocator->default_page_payload_size < size) { // Big allocation, give it its own page.
104
- rbs_allocator_page_t *new_page = rbs_allocator_page_new(size);
108
+ // Add padding to ensure we can align the start pointer within this page
109
+ rbs_allocator_page_t *new_page = rbs_allocator_page_new(size + (alignment - 1));
105
110
 
106
111
  // This simple allocator can only put small allocations into the head page.
107
112
  // Naively prepending this large allocation page to the head of the allocator before the previous head page
@@ -120,21 +125,29 @@ void *rbs_allocator_malloc_impl(rbs_allocator_t *allocator, size_t size, size_t
120
125
  new_page->next = allocator->page->next;
121
126
  allocator->page->next = new_page;
122
127
 
123
- uintptr_t pointer = (uintptr_t) new_page + sizeof(rbs_allocator_page_t);
124
- return (void *) pointer;
128
+ uintptr_t base = (uintptr_t) new_page + sizeof(rbs_allocator_page_t);
129
+ uintptr_t aligned_ptr = rbs_align_up_uintptr(base, alignment);
130
+ return (void *) aligned_ptr;
125
131
  }
126
132
 
127
133
  rbs_allocator_page_t *page = allocator->page;
128
- if (page->used + size > page->size) {
134
+ uintptr_t base = (uintptr_t) page + sizeof(rbs_allocator_page_t);
135
+
136
+ // Compute aligned offset within the payload
137
+ size_t used_aligned = (size_t) (rbs_align_up_uintptr(base + page->used, alignment) - base);
138
+
139
+ if (used_aligned + size > page->size) {
129
140
  // Not enough space. Allocate a new small page and prepend it to the allocator's linked list.
130
141
  rbs_allocator_page_t *new_page = rbs_allocator_page_new(allocator->default_page_payload_size);
131
142
  new_page->next = allocator->page;
132
143
  allocator->page = new_page;
133
144
  page = new_page;
145
+ base = (uintptr_t) page + sizeof(rbs_allocator_page_t);
146
+ used_aligned = (size_t) (rbs_align_up_uintptr(base, alignment) - base); // start of fresh page (usually 0 if header is aligned)
134
147
  }
135
148
 
136
- uintptr_t pointer = (uintptr_t) page + sizeof(rbs_allocator_page_t) + page->used;
137
- page->used += size;
149
+ uintptr_t pointer = base + used_aligned;
150
+ page->used = used_aligned + size;
138
151
  return (void *) pointer;
139
152
  }
140
153
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.1
4
+ version: 3.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
@@ -563,7 +563,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
563
563
  - !ruby/object:Gem::Version
564
564
  version: '0'
565
565
  requirements: []
566
- rubygems_version: 4.0.3
566
+ rubygems_version: 3.6.9
567
567
  specification_version: 4
568
568
  summary: Type signature for Ruby.
569
569
  test_files: []