Skip to content

Commit dc3fc7e

Browse files
committed
[GR-17457] Implement rb_imemo_tmpbuf allocation for ripper.
PullRequest: truffleruby/3319
2 parents a6d2e0b + aacb508 commit dc3fc7e

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Compatibility:
1919
* Fix `Process.wait2` to return `nil` when the `WNOHANG` flag is given and the child process is still running (@bjfish).
2020
* Disable most `nokogiri` C extension patches when system libraries are not being used (#2693, @aardvark179).
2121
* Implement `rb_gc_mark_maybe` and `rb_global_variable` to ensure `VALUE` stay live in C extensions (@aardvark179).
22+
* Implement `rb_imemo_tmpbuf` allocation for `ripper` (@aardvark179).
2223

2324
Performance:
2425

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2
1+
3

src/main/c/cext/alloc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ void* rb_imemo_tmpbuf_set_ptr(VALUE imemo, void *ptr) {
9595
polyglot_invoke(RUBY_CEXT, "rb_imemo_tmpbuf_set_ptr", rb_tr_unwrap(imemo), ptr);
9696
return ptr;
9797
}
98+
99+
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt) {
100+
/* This differs from CRuby as this does not produce an object known to the
101+
GC. This is not a problem for Ripper because we also mod that to free the
102+
heap when freeing the parser structure, but it might be a problem if other
103+
extensions use this function. */
104+
rb_imemo_tmpbuf_t *imemo = malloc(sizeof(rb_imemo_tmpbuf_t));
105+
imemo->ptr = buf;
106+
imemo->next = old_heap;
107+
imemo->cnt = cnt;
108+
return imemo;
109+
}

src/main/c/ripper/ripper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20248,8 +20248,10 @@ parser_mark(void *ptr)
2024820248
rb_gc_mark(p->debug_buffer);
2024920249
rb_gc_mark(p->debug_output);
2025020250
#ifdef YYMALLOC
20251+
#ifndef TRUFFLERUBY
2025120252
rb_gc_mark((VALUE)p->heap);
2025220253
#endif
20254+
#endif
2025320255
}
2025420256

2025520257
static void
@@ -20258,6 +20260,17 @@ parser_free(void *ptr)
2025820260
struct parser_params *p = (struct parser_params*)ptr;
2025920261
struct local_vars *local, *prev;
2026020262

20263+
#ifdef TRUFFLERUBY
20264+
rb_imemo_tmpbuf_t *heap = p->heap;
20265+
20266+
while (heap != NULL) {
20267+
if (heap->ptr != NULL) {
20268+
xfree(ptr);
20269+
}
20270+
heap = heap->next;
20271+
}
20272+
#endif
20273+
2026120274
if (p->tokenbuf) {
2026220275
ruby_sized_xfree(p->tokenbuf, p->toksiz);
2026320276
}

0 commit comments

Comments
 (0)