Skip to content

Commit

Permalink
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -73,27 +73,6 @@ public Object execute(VirtualFrame frame) {
}
}

/*
* We need to intercept Rubinius::FFI::Pointer so that it allocates the
* right DynamicObject. We can't do this after the core is loaded as
* it's too late by then.
*
* I don't pretend this is an ideal solution.
*/

if (name.equals("Pointer") && getEncapsulatingSourceSection().getSource().getPath().endsWith("core/rubinius/platform/pointer.rb")) {

definingClass.unsafeSetAllocator(new Allocator() {

@Override
public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node currentNode) {
return PointerPrimitiveNodes.createPointer(rubyClass, jnr.ffi.Runtime.getSystemRuntime().getMemoryManager().newOpaquePointer(0));
}


});
}

return definingClass;
}

Original file line number Diff line number Diff line change
@@ -10,9 +10,13 @@
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.SourceSection;

import jnr.ffi.Pointer;

import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
@@ -35,6 +39,13 @@ public abstract class PointerPrimitiveNodes {
POINTER_FACTORY = RubyBasicObject.EMPTY_SHAPE.addProperty(POINTER_PROPERTY).createFactory();
}

public static class PointerAllocator implements Allocator {
@Override
public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node currentNode) {
return PointerPrimitiveNodes.createPointer(rubyClass, jnr.ffi.Runtime.getSystemRuntime().getMemoryManager().newOpaquePointer(0));
}
}

public static RubyBasicObject createPointer(RubyClass rubyClass, Pointer pointer) {
assert pointer != null;
return new RubyBasicObject(rubyClass, POINTER_FACTORY.newInstance(pointer));
Original file line number Diff line number Diff line change
@@ -351,6 +351,7 @@ public CoreLibrary(RubyContext context) {

rubiniusFFIModule = defineModule(rubiniusModule, "FFI");
defineModule(defineModule(rubiniusFFIModule, "Platform"), "POSIX");
defineClass(rubiniusFFIModule, objectClass, "Pointer", new PointerPrimitiveNodes.PointerAllocator());
defineModule(rubiniusModule, "Type");

byteArrayClass = defineClass(rubiniusModule, objectClass, "ByteArray");

0 comments on commit 6dce068

Please sign in to comment.