Skip to content

Commit 5f12a1e

Browse files
authored
Merge branch 'master' into add-logger-dep
2 parents 45d4d16 + 4fdfab6 commit 5f12a1e

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
rbs (3.5.0)
4+
rbs (3.5.1.pre.1)
55
logger
66

77
PATH

ext/rbs_extension/location.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#define RBS_LOC_REQUIRED_P(loc, i) ((loc)->children->required_p & (1 << (i)))
44
#define RBS_LOC_OPTIONAL_P(loc, i) (!RBS_LOC_REQUIRED_P((loc), (i)))
5+
#define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1))
56

67
VALUE RBS_Location;
78

@@ -25,7 +26,7 @@ static void check_children_max(unsigned short n) {
2526
void rbs_loc_alloc_children(rbs_loc *loc, unsigned short cap) {
2627
check_children_max(cap);
2728

28-
size_t s = sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * cap;
29+
size_t s = RBS_LOC_CHILDREN_SIZE(cap);
2930
loc->children = malloc(s);
3031

3132
loc->children->len = 0;
@@ -39,7 +40,7 @@ static void check_children_cap(rbs_loc *loc) {
3940
} else {
4041
if (loc->children->len == loc->children->cap) {
4142
check_children_max(loc->children->cap + 1);
42-
size_t s = sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * (++loc->children->cap);
43+
size_t s = RBS_LOC_CHILDREN_SIZE(++loc->children->cap);
4344
loc->children = realloc(loc->children, s);
4445
}
4546
}
@@ -85,7 +86,7 @@ static size_t rbs_loc_memsize(const void *ptr) {
8586
if (loc->children == NULL) {
8687
return sizeof(rbs_loc);
8788
} else {
88-
return sizeof(rbs_loc) + sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * loc->children->cap;
89+
return sizeof(rbs_loc) + RBS_LOC_CHILDREN_SIZE(loc->children->cap);
8990
}
9091
}
9192

@@ -129,7 +130,7 @@ static VALUE location_initialize_copy(VALUE self, VALUE other) {
129130
self_loc->rg = other_loc->rg;
130131
if (other_loc->children != NULL) {
131132
rbs_loc_alloc_children(self_loc, other_loc->children->cap);
132-
memcpy(self_loc->children, other_loc->children, sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * other_loc->children->cap);
133+
memcpy(self_loc->children, other_loc->children, RBS_LOC_CHILDREN_SIZE(other_loc->children->cap));
133134
}
134135

135136
return Qnil;

ext/rbs_extension/location.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ typedef struct {
1616

1717
typedef unsigned int rbs_loc_entry_bitmap;
1818

19+
// The flexible array always allocates, but it's okay.
20+
// This struct is not allocated when the `rbs_loc` doesn't have children.
1921
typedef struct {
2022
unsigned short len;
2123
unsigned short cap;
2224
rbs_loc_entry_bitmap required_p;
23-
rbs_loc_entry entries[0];
25+
rbs_loc_entry entries[1];
2426
} rbs_loc_children;
2527

2628
typedef struct {
2729
VALUE buffer;
2830
range rg;
29-
rbs_loc_children *children;
31+
rbs_loc_children *children; // NULL when no children is allocated
3032
} rbs_loc;
3133

3234
/**

lib/rbs/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RBS
4-
VERSION = "3.5.0"
4+
VERSION = "3.5.1.pre.1"
55
end

steep/Gemfile.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
abbrev (0.1.2)
54
activesupport (7.1.3.4)
65
base64
76
bigdecimal
@@ -39,8 +38,7 @@ GEM
3938
rb-fsevent (0.11.2)
4039
rb-inotify (0.11.1)
4140
ffi (~> 1.0)
42-
rbs (3.4.4)
43-
abbrev
41+
rbs (3.5.0)
4442
securerandom (0.3.1)
4543
steep (1.6.0)
4644
activesupport (>= 5.1)

0 commit comments

Comments
 (0)