Skip to content

Commit

Permalink
Merge branch 'master' into add-logger-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro authored Jun 7, 2024
2 parents 45d4d16 + 4fdfab6 commit 5f12a1e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rbs (3.5.0)
rbs (3.5.1.pre.1)
logger

PATH
Expand Down
9 changes: 5 additions & 4 deletions ext/rbs_extension/location.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

VALUE RBS_Location;

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

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

loc->children->len = 0;
Expand All @@ -39,7 +40,7 @@ static void check_children_cap(rbs_loc *loc) {
} else {
if (loc->children->len == loc->children->cap) {
check_children_max(loc->children->cap + 1);
size_t s = sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * (++loc->children->cap);
size_t s = RBS_LOC_CHILDREN_SIZE(++loc->children->cap);
loc->children = realloc(loc->children, s);
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ static size_t rbs_loc_memsize(const void *ptr) {
if (loc->children == NULL) {
return sizeof(rbs_loc);
} else {
return sizeof(rbs_loc) + sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * loc->children->cap;
return sizeof(rbs_loc) + RBS_LOC_CHILDREN_SIZE(loc->children->cap);
}
}

Expand Down Expand Up @@ -129,7 +130,7 @@ static VALUE location_initialize_copy(VALUE self, VALUE other) {
self_loc->rg = other_loc->rg;
if (other_loc->children != NULL) {
rbs_loc_alloc_children(self_loc, other_loc->children->cap);
memcpy(self_loc->children, other_loc->children, sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * other_loc->children->cap);
memcpy(self_loc->children, other_loc->children, RBS_LOC_CHILDREN_SIZE(other_loc->children->cap));
}

return Qnil;
Expand Down
6 changes: 4 additions & 2 deletions ext/rbs_extension/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ typedef struct {

typedef unsigned int rbs_loc_entry_bitmap;

// The flexible array always allocates, but it's okay.
// This struct is not allocated when the `rbs_loc` doesn't have children.
typedef struct {
unsigned short len;
unsigned short cap;
rbs_loc_entry_bitmap required_p;
rbs_loc_entry entries[0];
rbs_loc_entry entries[1];
} rbs_loc_children;

typedef struct {
VALUE buffer;
range rg;
rbs_loc_children *children;
rbs_loc_children *children; // NULL when no children is allocated
} rbs_loc;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rbs/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RBS
VERSION = "3.5.0"
VERSION = "3.5.1.pre.1"
end
4 changes: 1 addition & 3 deletions steep/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
activesupport (7.1.3.4)
base64
bigdecimal
Expand Down Expand Up @@ -39,8 +38,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (3.4.4)
abbrev
rbs (3.5.0)
securerandom (0.3.1)
steep (1.6.0)
activesupport (>= 5.1)
Expand Down

0 comments on commit 5f12a1e

Please sign in to comment.