Skip to content

Commit d74dc6d

Browse files
committed
Implement rb_imemo_tmpbuf_auto_free_pointer() which is needed by Ripper
1 parent b2aa192 commit d74dc6d

File tree

6 files changed

+31
-27
lines changed

6 files changed

+31
-27
lines changed

lib/cext/include/internal.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@ typedef struct rb_imemo_tmpbuf_struct {
6565
size_t cnt; /* buffer size in VALUE */
6666
} rb_imemo_tmpbuf_t;
6767

68-
#define rb_imemo_tmpbuf_auto_free_pointer() rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0)
69-
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
68+
VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
69+
void* rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
7070

71-
static inline
72-
void* rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr) {
73-
return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
74-
}
71+
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
7572

7673
#if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
7774
#define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size)

lib/truffle/truffle/cext.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,4 +1785,23 @@ def rb_sprintf(format, *args)
17851785
def test_cext_wrap(value)
17861786
Primitive.cext_wrap(value)
17871787
end
1788+
1789+
# An object that once unreachable frees the associated native pointer using ruby_xfree()
1790+
class IMemoTmpBufAutoFree
1791+
def pointer=(address)
1792+
ObjectSpace.define_finalizer(self, self.class.free(address))
1793+
end
1794+
1795+
def self.free(address)
1796+
-> _id { LIBTRUFFLERUBY.ruby_xfree(address) }
1797+
end
1798+
end
1799+
1800+
def rb_imemo_tmpbuf_auto_free_pointer
1801+
IMemoTmpBufAutoFree.new
1802+
end
1803+
1804+
def rb_imemo_tmpbuf_set_ptr(obj, ptr)
1805+
obj.pointer = ptr
1806+
end
17881807
end

src/main/c/cext/alloc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ void rb_mem_clear(VALUE *mem, long n) {
7474
mem[i] = Qnil;
7575
}
7676
}
77+
78+
VALUE rb_imemo_tmpbuf_auto_free_pointer(void) {
79+
return RUBY_CEXT_INVOKE("rb_imemo_tmpbuf_auto_free_pointer");
80+
}
81+
82+
void* rb_imemo_tmpbuf_set_ptr(VALUE imemo, void *ptr) {
83+
polyglot_invoke(RUBY_CEXT, "rb_imemo_tmpbuf_set_ptr", rb_tr_unwrap(imemo), ptr);
84+
return ptr;
85+
}

test/mri/excludes/Ripper/TestInput.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
exclude :test_aryptn, "needs investigation"
21
exclude :test_block_variables, "needs investigation"
3-
exclude :test_event_coverage, "needs investigation"

test/mri/excludes/TestRipper/Sexp.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)