Skip to content

Commit 780ec0c

Browse files
committed
Pointer#read_pointer should return a pointer with #type_size 1
* Fixes #3837
1 parent 1123b29 commit 780ec0c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Compatibility:
1717
* Fix explicitly inherited `Struct` subclasses and don't provide `#members` method (#3802, @andrykonchin).
1818
* Support Digest plugins (#1390, @nirvdrum).
1919
* Joni has been updated from 2.2.1 to 2.2.6 (@andrykonchin).
20+
* Return a pointer with `#type_size` of 1 for `Pointer#read_pointer` (@eregon).
2021

2122
Performance:
2223

src/main/java/org/truffleruby/extra/ffi/PointerNodes.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.truffle.api.dsl.ImportStatic;
4848
import com.oracle.truffle.api.dsl.Specialization;
4949
import org.truffleruby.language.objects.AllocationTracing;
50+
import org.truffleruby.language.objects.WriteObjectFieldNode;
5051

5152
@CoreModule(value = "Truffle::FFI::Pointer", isClass = true)
5253
public abstract class PointerNodes {
@@ -503,7 +504,8 @@ public abstract static class PointerReadPointerNode extends PrimitiveArrayArgume
503504

504505
@Specialization
505506
RubyPointer readPointer(long address,
506-
@Cached CheckNullPointerNode checkNullPointerNode) {
507+
@Cached CheckNullPointerNode checkNullPointerNode,
508+
@Cached WriteObjectFieldNode writeTypeSize) {
507509
final Pointer ptr = new Pointer(getContext(), address);
508510
checkNullPointerNode.execute(this, ptr);
509511
final Pointer readPointer = ptr.readPointer(getContext(), 0);
@@ -512,6 +514,10 @@ RubyPointer readPointer(long address,
512514
getLanguage().truffleFFIPointerShape,
513515
readPointer);
514516
AllocationTracing.trace(instance, this);
517+
518+
// We don't call Truffle::FFI::Pointer#initialize so we manually set it instead
519+
writeTypeSize.execute(this, instance, "@type_size", 1);
520+
515521
return instance;
516522
}
517523

0 commit comments

Comments
 (0)