Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 810d366417eb
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 08f348c930cd
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 11, 2017

  1. Copy the full SHA
    29c6009 View commit details
  2. Copy the full SHA
    08f348c View commit details
Showing with 31 additions and 5 deletions.
  1. +1 −1 core/pom.rb
  2. +1 −1 core/pom.xml
  3. +9 −1 core/src/main/java/org/jruby/RubyProcess.java
  4. +20 −2 core/src/main/java/org/jruby/RubyTime.java
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@
jar 'com.github.jnr:jnr-enxio:0.14', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-unixsocket:0.15', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.33', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.34-SNAPSHOT', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-constants:0.9.6', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-ffi:2.1.2'
jar 'com.github.jnr:jffi:${jffi.version}'
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.33</version>
<version>3.0.34-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>jnr-ffi</artifactId>
10 changes: 9 additions & 1 deletion core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
import jnr.ffi.byref.IntByReference;
import jnr.posix.RLimit;
import jnr.posix.Times;
import jnr.posix.Timeval;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
@@ -1449,7 +1450,14 @@ private static long getTimeForClock(IRubyObject _clock_id, Ruby runtime) throws
if (_clock_id.toString().equals(CLOCK_MONOTONIC)) {
nanos = System.nanoTime();
} else if (_clock_id.toString().equals(CLOCK_REALTIME)) {
nanos = System.currentTimeMillis() * 1000000;
POSIX posix = runtime.getPosix();
if (posix.isNative()) {
Timeval tv = posix.allocateTimeval();
posix.gettimeofday(tv);
nanos = tv.sec() * 1_000_000_000 + tv.usec() * 1000;
} else {
nanos = System.currentTimeMillis() * 1000000;
}
} else {
throw runtime.newErrnoEINVALError("clock_gettime");
}
22 changes: 20 additions & 2 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import jnr.posix.POSIX;
import jnr.posix.Timeval;
import org.jcodings.specific.USASCIIEncoding;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -390,9 +392,25 @@ public RubyTime(Ruby runtime, RubyClass rubyClass, DateTime dt) {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
DateTimeZone dtz = getLocalTimeZone(runtime);
DateTime dt = new DateTime(dtz);
long msecs;
long nsecs;
POSIX posix = runtime.getPosix();
if (posix.isNative()) {
Timeval tv = posix.allocateTimeval();
posix.gettimeofday(tv);

long secs = tv.sec();
long usecs = tv.usec();

msecs = secs * 1000 + (usecs / 1000);
nsecs = usecs % 1000 * 1000;
} else {
msecs = System.currentTimeMillis();
nsecs = 0;
}
DateTime dt = new DateTime(msecs, dtz);
RubyTime rt = new RubyTime(runtime, klass, dt);
rt.setNSec(0);
rt.setNSec(nsecs);

return rt;
}