-
Notifications
You must be signed in to change notification settings - Fork 45
Implement compaction and embedded structs #201
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,37 +182,73 @@ extract_beg_len(struct strscanner *p, long beg_i, long len) | |
| Constructor | ||
| ======================================================================= */ | ||
|
|
||
| #ifdef RUBY_TYPED_EMBEDDABLE | ||
| # define HAVE_RUBY_TYPED_EMBEDDABLE 1 | ||
| #else | ||
| # ifdef HAVE_CONST_RUBY_TYPED_EMBEDDABLE | ||
| # define RUBY_TYPED_EMBEDDABLE RUBY_TYPED_EMBEDDABLE | ||
| # define HAVE_RUBY_TYPED_EMBEDDABLE 1 | ||
| # else | ||
| # define RUBY_TYPED_EMBEDDABLE 0 | ||
| # endif | ||
| #endif | ||
|
|
||
| #ifdef HAVE_RB_GC_LOCATION | ||
| static void | ||
| strscan_compact(void *ptr) | ||
| { | ||
| struct strscanner *p = ptr; | ||
| p->str = rb_gc_location(p->str); | ||
| p->regex = rb_gc_location(p->regex); | ||
| } | ||
| #else | ||
| #define rb_gc_mark_movable rb_gc_mark | ||
| #endif | ||
|
|
||
| static void | ||
| strscan_mark(void *ptr) | ||
| { | ||
| struct strscanner *p = ptr; | ||
| rb_gc_mark(p->str); | ||
| rb_gc_mark(p->regex); | ||
| rb_gc_mark_movable(p->str); | ||
| rb_gc_mark_movable(p->regex); | ||
| } | ||
|
Comment on lines
+196
to
214
|
||
|
|
||
| static void | ||
| strscan_free(void *ptr) | ||
| { | ||
| struct strscanner *p = ptr; | ||
| onig_region_free(&(p->regs), 0); | ||
| #ifndef HAVE_RUBY_TYPED_EMBEDDABLE | ||
| ruby_xfree(p); | ||
| #endif | ||
| } | ||
|
|
||
| static size_t | ||
| strscan_memsize(const void *ptr) | ||
| { | ||
| const struct strscanner *p = ptr; | ||
| size_t size = sizeof(*p) - sizeof(p->regs); | ||
| size_t size = 0; | ||
| #ifndef HAVE_RUBY_TYPED_EMBEDDABLE | ||
| size += sizeof(struct strscanner); | ||
| #endif | ||
|
|
||
| #ifdef HAVE_ONIG_REGION_MEMSIZE | ||
| size += onig_region_memsize(&p->regs); | ||
| const struct strscanner *p = ptr; | ||
| size += onig_region_memsize(&p->regs) - sizeof(p->regs); | ||
| #endif | ||
| return size; | ||
| } | ||
|
|
||
| static const rb_data_type_t strscanner_type = { | ||
| "StringScanner", | ||
| {strscan_mark, strscan_free, strscan_memsize}, | ||
| 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | ||
| .wrap_struct_name = "StringScanner", | ||
| .function = { | ||
| .dmark = strscan_mark, | ||
| .dfree = strscan_free, | ||
| .dsize = strscan_memsize, | ||
| #ifdef HAVE_RB_GC_LOCATION | ||
| .dcompact = strscan_compact, | ||
| #endif | ||
| }, | ||
| .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE | ||
| }; | ||
|
|
||
| static VALUE | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
HAVE_CONST_RUBY_TYPED_EMBEDDABLEbranch definesRUBY_TYPED_EMBEDDABLEas itself (#define RUBY_TYPED_EMBEDDABLE RUBY_TYPED_EMBEDDABLE), which is effectively a no-op and can be confusing (and may trigger self-referential macro warnings on some toolchains). Sincehave_const("RUBY_TYPED_EMBEDDABLE")already tells you whether the identifier exists, consider simplifying this detection to only defineHAVE_RUBY_TYPED_EMBEDDABLE(and otherwise#define RUBY_TYPED_EMBEDDABLE 0) without redefining the constant name.