-
-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Add POSIX and Pointer nodes for File.readlink
- Loading branch information
Showing
3 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
*/ | ||
package org.jruby.truffle.nodes.rubinius; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import jnr.constants.platform.Fcntl; | ||
|
@@ -18,6 +19,7 @@ | |
import org.jruby.truffle.nodes.core.CoreMethod; | ||
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.control.RaiseException; | ||
import org.jruby.truffle.runtime.core.RubyBasicObject; | ||
import org.jruby.truffle.runtime.core.RubyNilClass; | ||
import org.jruby.truffle.runtime.core.RubyString; | ||
|
@@ -201,6 +203,31 @@ public RubyBasicObject memset(RubyBasicObject pointer, int c, long length) { | |
|
||
} | ||
|
||
@CoreMethod(names = "readlink", isModuleFunction = true, required = 3) | ||
public abstract static class ReadlinkNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode { | ||
|
||
public ReadlinkNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
@Specialization | ||
public int readlink(RubyString path, RubyBasicObject pointer, int bufsize) { | ||
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize()); | ||
final long address = getAddress(pointer); | ||
final byte[] buffer = new byte[bufsize]; | ||
final int result = posix().readlink(pathString, buffer, bufsize); | ||
if (result == -1) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this)); | ||
} | ||
for (int n = 0; n < buffer.length; n++) { | ||
UnsafeHolder.U.putInt(address + n * Unsafe.ARRAY_BYTE_INDEX_SCALE, buffer[n]); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nirvdrum
Contributor
|
||
} | ||
return result; | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "link", isModuleFunction = true, required = 2) | ||
public abstract static class LinkNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode { | ||
|
||
|
I think you want
putByte
here. It probably ends up being okay because you work your way forward, butputInt
will end up writing over 4 byte slots allocated in the array, as far as I can tell.