summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-04-18 16:25:00 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-04-18 16:25:00 -0400
commit17da66de237520cd3b6c307cc051c53a738598d9 (patch)
treeddd86006ea2501d5704bcb8a96a7d582f6cf3985
parent250c31a25d81339cfe928a433ada3c0f17eae580 (diff)
downloadffi-17da66de237520cd3b6c307cc051c53a738598d9.tar.gz
Remove use of RARRAY_PTR
RARRAY_PTR is bad for GC performance as it exposes the internal buffer of the array meaning that the array becomes write barrier unprotected.
-rw-r--r--ext/ffi_c/AbstractMemory.c2
-rw-r--r--ext/ffi_c/Struct.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/ext/ffi_c/AbstractMemory.c b/ext/ffi_c/AbstractMemory.c
index 3cf16a7..10ddc28 100644
--- a/ext/ffi_c/AbstractMemory.c
+++ b/ext/ffi_c/AbstractMemory.c
@@ -150,7 +150,7 @@ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
if (likely(count > 0)) checkWrite(memory); \
checkBounds(memory, off, count * sizeof(type)); \
for (i = 0; i < count; i++) { \
- type tmp = (type) VAL(toNative(RARRAY_PTR(ary)[i]), swap); \
+ type tmp = (type) VAL(toNative(RARRAY_AREF(ary, i)), swap); \
memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
} \
return self; \
diff --git a/ext/ffi_c/Struct.c b/ext/ffi_c/Struct.c
index b9b6b2c..9eb10ec 100644
--- a/ext/ffi_c/Struct.c
+++ b/ext/ffi_c/Struct.c
@@ -132,7 +132,7 @@ struct_initialize(int argc, VALUE* argv, VALUE self)
/* Call up into ruby code to adjust the layout */
if (nargs > 1) {
- VALUE rbLayout = rb_funcall2(CLASS_OF(self), id_layout, (int) RARRAY_LEN(rest), RARRAY_PTR(rest));
+ VALUE rbLayout = rb_apply(CLASS_OF(self), id_layout, rest);
RB_OBJ_WRITE(self, &s->rbLayout, rbLayout);
} else {
RB_OBJ_WRITE(self, &s->rbLayout, struct_class_layout(klass));