Skip to content

Commit

Permalink
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@ public boolean setAutorelease(RubyBasicObject pointer, boolean autorelease) {

}

@RubiniusPrimitive(name = "pointer_set_at_offset", lowerFixnumParameters = {0, 2})
@RubiniusPrimitive(name = "pointer_set_at_offset")
@ImportStatic(RubiniusTypes.class)
public static abstract class PointerSetAtOffsetPrimitiveNode extends RubiniusPrimitiveNode {

@@ -206,11 +206,17 @@ public PointerSetAtOffsetPrimitiveNode(RubyContext context, SourceSection source
}

@Specialization(guards = "type == TYPE_INT")
public int setAtOffset(RubyBasicObject pointer, int offset, int type, int value) {
public int setAtOffsetInt(RubyBasicObject pointer, int offset, int type, int value) {
getPointer(pointer).putInt(offset, value);
return value;
}

@Specialization(guards = "type == TYPE_LONG")
public long setAtOffsetLong(RubyBasicObject pointer, int offset, int type, long value) {
getPointer(pointer).putLong(offset, value);
return value;
}

}

@RubiniusPrimitive(name = "pointer_read_pointer")

2 comments on commit fe2dad8

@nirvdrum
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisseaton Was there a reason you were lowering these to begin with? I want to make sure I don't break anything. But at the same time, lowering introduces the possibility of only writing half a word on 64-bit machines.

The case where this came up is TimeVal. Both :tv_sec and :tv_usec are longs on Linux and I had a case where values greater than 32-bits were being written. It looks like on Mac one of the fields is a long and the other is an int, according to the Rubinius config.

In any event, I can't readily test this since I don't have a Mac. Please give it a glance over.

@nirvdrum
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After contemplating a bit more, the type value should always ensure we write data with the correct width. I had convinced myself this was being decided upon by the type of value. So, I think we're all set. I restored the Fixnum lowering, but applied to offset and type (not value) in 0385b17.

Please sign in to comment.