-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into new_reify_classes
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
Showing
58 changed files
with
12,017 additions
and
9,360 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
1,103 changes: 556 additions & 547 deletions
1,103
core/src/main/java/org/jruby/ext/ripper/RipperParser.java
Large diffs are not rendered by default.
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
7,638 changes: 3,747 additions & 3,891 deletions
7,638
core/src/main/java/org/jruby/ext/ripper/YyTables.java
Large diffs are not rendered by default.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
core/src/main/java/org/jruby/ext/securerandom/RubySecureRandom.java
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 |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 1.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 1.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Copyright (C) 2017 JRuby Community | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
package org.jruby.ext.securerandom; | ||
|
||
import org.jruby.RubyBignum; | ||
import org.jruby.RubyFixnum; | ||
import org.jruby.RubyFloat; | ||
import org.jruby.RubyInteger; | ||
import org.jruby.RubyRange; | ||
import org.jruby.RubyString; | ||
import org.jruby.anno.JRubyMethod; | ||
import org.jruby.anno.JRubyModule; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.ConvertBytes; | ||
|
||
import java.math.BigInteger; | ||
import java.security.SecureRandom; | ||
|
||
/** | ||
* securerandom.rb native parts. | ||
*/ | ||
@JRubyModule(name = "SecureRandom") | ||
public class RubySecureRandom { | ||
|
||
@JRubyMethod(meta = true, name = "random_bytes") | ||
public static IRubyObject random_bytes(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, nextBytes(context, 16)); | ||
} | ||
|
||
@JRubyMethod(meta = true, name = "random_bytes", alias = "gen_random") // gen_random for 'better' compat (not-used) | ||
public static IRubyObject random_bytes(ThreadContext context, IRubyObject self, IRubyObject n) { | ||
return RubyString.newStringNoCopy(context.runtime, nextBytes(context, n)); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
public static IRubyObject hex(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.twosComplementToHexBytes(nextBytes(context, 16), false)); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
public static IRubyObject hex(ThreadContext context, IRubyObject self, IRubyObject n) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.twosComplementToHexBytes(nextBytes(context, n), false)); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
public static IRubyObject uuid(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.bytesToUUIDBytes(nextBytes(context, 16), false)); | ||
} | ||
|
||
private static byte[] nextBytes(ThreadContext context, IRubyObject n) { | ||
return nextBytes(context, n.isNil() ? 16 : n.convertToInteger().getIntValue()); | ||
} | ||
|
||
private static byte[] nextBytes(ThreadContext context, int size) { | ||
if (size < 0) throw context.runtime.newArgumentError("negative argument: " + size); | ||
|
||
byte[] bytes = new byte[size]; | ||
getSecureRandom(context).nextBytes(bytes); | ||
|
||
return bytes; | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
public static IRubyObject random_number(ThreadContext context, IRubyObject self) { | ||
return randomDouble(context); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
public static IRubyObject random_number(ThreadContext context, IRubyObject self, IRubyObject n) { | ||
if (n instanceof RubyFixnum) { | ||
final long bound = ((RubyFixnum) n).getLongValue(); | ||
return ( bound < 0 ) ? randomDouble(context) : randomFixnum(context, 0, bound - 1); | ||
} | ||
if (n instanceof RubyFloat) { | ||
final double bound = ((RubyFloat) n).getDoubleValue(); | ||
return ( bound < 0 ) ? randomDouble(context) : randomDouble(context, 0, bound - Double.MIN_VALUE); | ||
} | ||
if (n instanceof RubyBignum) { | ||
final BigInteger bound = ((RubyBignum) n).getBigIntegerValue(); | ||
return ( bound.signum() < 0 ) ? randomDouble(context) : randomBignum(context, 0, bound); | ||
} | ||
|
||
if (n instanceof RubyRange) { | ||
final IRubyObject beg = ((RubyRange) n).begin(context); | ||
final IRubyObject end = ((RubyRange) n).end(context); | ||
final boolean exclude = ((RubyRange) n).isExcludeEnd(); | ||
|
||
if (beg instanceof RubyFixnum && end instanceof RubyFixnum) { | ||
long lower = ((RubyFixnum) beg).getLongValue(); | ||
long upper = ((RubyFixnum) end).getLongValue(); | ||
if ( lower > upper ) return randomDouble(context); | ||
if ( exclude ) upper--; // rand(2) never returns 2 but rand(0..2) does | ||
return randomFixnum(context, lower, upper); | ||
} | ||
if (beg instanceof RubyInteger && end instanceof RubyInteger) { | ||
BigInteger lower = ((RubyInteger) beg).getBigIntegerValue(); | ||
BigInteger upper = ((RubyInteger) end).getBigIntegerValue(); | ||
if ( lower.compareTo(upper) > 0 ) return randomDouble(context); | ||
if ( ! exclude ) upper = upper.add(BigInteger.ONE); | ||
return randomBignum(context, lower, upper); | ||
} | ||
if (beg instanceof RubyFloat && end instanceof RubyFloat) { | ||
double lower = ((RubyFloat) beg).getDoubleValue(); | ||
double upper = ((RubyFloat) end).getDoubleValue(); | ||
if ( lower > upper ) return randomDouble(context); | ||
if ( exclude ) upper = upper - Double.MIN_VALUE; | ||
return randomDouble(context, lower, upper); | ||
} | ||
} | ||
|
||
throw context.runtime.newArgumentError("invalid argument - " + n.anyToString()); | ||
} | ||
|
||
private static RubyFixnum randomFixnum(final ThreadContext context, final long lower, final long upper) { | ||
double rnd = getSecureRandom(context).nextDouble(); | ||
rnd = rnd * upper + (1.0 - rnd) * lower + rnd; | ||
return context.runtime.newFixnum((long) Math.floor(rnd)); | ||
} | ||
|
||
// NOTE: upper is exclusive here compared to others | ||
private static RubyBignum randomBignum(final ThreadContext context, final Number lower, final BigInteger upperExc) { | ||
BigInteger lowerBig = lower instanceof BigInteger ? (BigInteger) lower : BigInteger.valueOf(lower.longValue()); | ||
BigInteger bound = upperExc.subtract(lowerBig); | ||
BigInteger rnd = nextBigInteger(getSecureRandom(context), bound, bound.bitLength()); | ||
return RubyBignum.newBignum(context.runtime, rnd.add(lowerBig)); | ||
} | ||
|
||
private static final int BI_ADD_BITS = 96; // 8+4 random bytes 'wasted' | ||
|
||
// <0, bound) | ||
private static BigInteger nextBigInteger(final SecureRandom random, final BigInteger bound, final int bits) { | ||
BigInteger val = new BigInteger(bits + BI_ADD_BITS, random); | ||
BigInteger rnd = val.mod(bound); | ||
|
||
if (val.add(bound).subtract(rnd).subtract(BigInteger.ONE).bitLength() >= bits + BI_ADD_BITS) { | ||
return nextBigInteger(random, bound, bits); // highly unlikely to recurse at all | ||
} | ||
return rnd; | ||
} | ||
|
||
private static RubyFloat randomDouble(final ThreadContext context, final double lower, final double upper) { | ||
double rnd = getSecureRandom(context).nextDouble(); | ||
return context.runtime.newFloat( rnd * upper + (1.0 - rnd) * lower ); | ||
} | ||
|
||
private static RubyFloat randomDouble(final ThreadContext context) { | ||
return context.runtime.newFloat( getSecureRandom(context).nextDouble() ); | ||
} | ||
|
||
private static SecureRandom getSecureRandom(ThreadContext context) { | ||
return context.getSecureRandom(); | ||
} | ||
|
||
} |
52 changes: 24 additions & 28 deletions
52
core/src/main/java/org/jruby/ext/securerandom/SecureRandomLibrary.java
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 |
---|---|---|
@@ -1,52 +1,48 @@ | ||
package org.jruby.ext.securerandom; | ||
|
||
import org.jruby.RubyString; | ||
import org.jruby.anno.JRubyMethod; | ||
import org.jruby.Ruby; | ||
import org.jruby.RubyModule; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.ConvertBytes; | ||
import org.jruby.runtime.load.Library; | ||
|
||
/** | ||
* Created by headius on 1/14/14. | ||
*/ | ||
public class SecureRandomLibrary { | ||
@JRubyMethod(meta = true) | ||
public class SecureRandomLibrary implements Library { | ||
|
||
public static void load(Ruby runtime) { | ||
RubyModule SecureRandom = runtime.defineModule("SecureRandom"); | ||
SecureRandom.defineAnnotatedMethods(RubySecureRandom.class); | ||
} | ||
|
||
public void load(Ruby runtime, boolean wrap) { | ||
SecureRandomLibrary.load(runtime); | ||
} | ||
|
||
@Deprecated | ||
public static IRubyObject random_bytes(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, nextBytes(context, 16)); | ||
return RubySecureRandom.random_bytes(context, self); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
@Deprecated | ||
public static IRubyObject random_bytes(ThreadContext context, IRubyObject self, IRubyObject n) { | ||
return RubyString.newStringNoCopy(context.runtime, nextBytes(context, n)); | ||
return RubySecureRandom.random_bytes(context, self, n); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
@Deprecated | ||
public static IRubyObject hex(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.twosComplementToHexBytes(nextBytes(context, 16), false)); | ||
return RubySecureRandom.hex(context, self); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
@Deprecated | ||
public static IRubyObject hex(ThreadContext context, IRubyObject self, IRubyObject n) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.twosComplementToHexBytes(nextBytes(context, n), false)); | ||
return RubySecureRandom.hex(context, self, n); | ||
} | ||
|
||
@JRubyMethod(meta = true) | ||
@Deprecated | ||
public static IRubyObject uuid(ThreadContext context, IRubyObject self) { | ||
return RubyString.newStringNoCopy(context.runtime, ConvertBytes.bytesToUUIDBytes(nextBytes(context, 16), false)); | ||
return RubySecureRandom.hex(context, self); | ||
} | ||
|
||
private static byte[] nextBytes(ThreadContext context, IRubyObject n) { | ||
int size = n.isNil() ? 16 : (int) n.convertToInteger().getLongValue(); | ||
|
||
return nextBytes(context, size); | ||
} | ||
|
||
private static byte[] nextBytes(ThreadContext context, int size) { | ||
if (size < 0) throw context.runtime.newArgumentError("negative argument: " + size); | ||
|
||
byte[] bytes = new byte[size]; | ||
context.getSecureRandom().nextBytes(bytes); | ||
|
||
return bytes; | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* IMPORTANT: must compile with JFlex 1.4, JFlex 1.4.3 seems buggy with look-ahead */ | ||
|
||
package org.jruby.lexer; | ||
|
||
import org.jruby.util.StrptimeToken; | ||
|
||
%% | ||
%public | ||
%class StrptimeLexer | ||
//%debug | ||
%unicode | ||
%type org.jruby.util.StrptimeToken | ||
%{ | ||
StringBuilder stringBuf = new StringBuilder(); | ||
|
||
public StrptimeToken rawString() { | ||
String str = stringBuf.toString(); | ||
stringBuf.setLength(0); | ||
return StrptimeToken.str(str); | ||
} | ||
|
||
public StrptimeToken directive(char c) { | ||
StrptimeToken token; | ||
if (c == 'z') { | ||
int colons = yylength()-1; // can only be colons except the 'z' | ||
return StrptimeToken.zoneOffsetColons(colons); | ||
} else if ((token = StrptimeToken.format(c)) != null) { | ||
return token; | ||
} else { | ||
return StrptimeToken.special(c); | ||
} | ||
} | ||
%} | ||
|
||
Flags = [-_0#\^]+ | ||
Width = [1-9][0-9]* | ||
|
||
// See RubyDateFormatter.main to generate this | ||
// Chars are sorted by | ruby -e 'p STDIN.each_char.sort{|a,b|a.casecmp(b).tap{|c|break a<=>b if c==0}}.join' | ||
Conversion = [\+AaBbCcDdeFGgHhIjkLlMmNnPpQRrSsTtUuVvWwXxYyZz] | {IgnoredModifier} | {Zone} | ||
// From MRI strftime.c | ||
IgnoredModifier = E[CcXxYy] | O[deHIMmSUuVWwy] | ||
Zone = :{1,3} z | ||
|
||
SimpleDirective = "%" | ||
LiteralPercent = "%%" | ||
Unknown = .|\n | ||
|
||
%xstate CONVERSION | ||
|
||
%% | ||
|
||
<YYINITIAL> { | ||
{LiteralPercent} { return StrptimeToken.str("%"); } | ||
{SimpleDirective} / {Conversion} { yybegin(CONVERSION); } | ||
} | ||
|
||
<CONVERSION> {Conversion} { yybegin(YYINITIAL); return directive(yycharat(yylength()-1)); } | ||
|
||
/* fallback */ | ||
{Unknown} / [^%] { stringBuf.append(yycharat(0)); } | ||
{Unknown} { stringBuf.append(yycharat(0)); return rawString(); } |
Large diffs are not rendered by default.
Oops, something went wrong.
1,158 changes: 584 additions & 574 deletions
1,158
core/src/main/java/org/jruby/parser/RubyParser.java
Large diffs are not rendered by default.
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
7,864 changes: 3,986 additions & 3,878 deletions
7,864
core/src/main/java/org/jruby/parser/YyTables.java
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 1.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 1.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
package org.jruby.util; | ||
|
||
import org.jruby.RubyBignum; | ||
import org.jruby.RubyFixnum; | ||
import org.jruby.RubyRational; | ||
import org.jruby.RubyString; | ||
import org.jruby.runtime.ThreadContext; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import static org.jruby.util.StrptimeParser.FormatBag.has; | ||
|
||
/** | ||
* This class has {@code StrptimeParser} and provides methods that are calls from JRuby. | ||
*/ | ||
public class RubyDateParser { | ||
private final StrptimeParser strptimeParser; | ||
|
||
public RubyDateParser() { | ||
this.strptimeParser = new StrptimeParser(); | ||
} | ||
|
||
/** | ||
* Date._strptime method in JRuby 9.1.5.0's lib/ruby/stdlib/date/format.rb is replaced | ||
* with this method. This is Java implementation of date__strptime method in MRI 2.3.1's | ||
* ext/date/date_strptime.c. | ||
* @see https://github.com/jruby/jruby/blob/036ce39f0476d4bd718e23e64caff36bb50b8dbc/lib/ruby/stdlib/date/format.rb | ||
* @see https://github.com/ruby/ruby/blob/394fa89c67722d35bdda89f10c7de5c304a5efb1/ext/date/date_strptime.c | ||
*/ | ||
|
||
public HashMap<String, Object> parse(ThreadContext context, final RubyString format, final RubyString text) { | ||
final boolean tainted = text.isTaint(); | ||
final List<StrptimeToken> compiledPattern = strptimeParser.compilePattern(format.asJavaString()); | ||
final StrptimeParser.FormatBag bag = strptimeParser.parse(compiledPattern, text.asJavaString()); | ||
if (bag != null) { | ||
return convertFormatBagToHash(context, bag, tainted); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private HashMap<String, Object> convertFormatBagToHash(ThreadContext context, StrptimeParser.FormatBag bag, boolean tainted) { | ||
final HashMap<String, Object> map = new HashMap<>(); | ||
|
||
if (has(bag.getMDay())) { | ||
map.put("mday", bag.getMDay()); | ||
} | ||
if (has(bag.getWDay())) { | ||
map.put("wday", bag.getWDay()); | ||
} | ||
if (has(bag.getCWDay())) { | ||
map.put("cwday", bag.getCWDay()); | ||
} | ||
if (has(bag.getYDay())) { | ||
map.put("yday", bag.getYDay()); | ||
} | ||
if (has(bag.getCWeek())) { | ||
map.put("cweek", bag.getCWeek()); | ||
} | ||
if (has(bag.getCWYear())) { | ||
map.put("cwyear", bag.getCWYear()); | ||
} | ||
if (has(bag.getMin())) { | ||
map.put("min", bag.getMin()); | ||
} | ||
if (has(bag.getMon())) { | ||
map.put("mon", bag.getMon()); | ||
} | ||
if (has(bag.getHour())) { | ||
map.put("hour", bag.getHour()); | ||
} | ||
if (has(bag.getYear())) { | ||
map.put("year", bag.getYear()); | ||
} | ||
if (has(bag.getSec())) { | ||
map.put("sec", bag.getSec()); | ||
} | ||
if (has(bag.getWNum0())) { | ||
map.put("wnum0", bag.getWNum0()); | ||
} | ||
if (has(bag.getWNum1())) { | ||
map.put("wnum1", bag.getWNum1()); | ||
} | ||
if (bag.getZone() != null) { | ||
final RubyString zone = RubyString.newString(context.getRuntime(), bag.getZone()); | ||
if (tainted) { | ||
zone.taint(context); | ||
} | ||
map.put("zone", zone); | ||
int offset = TimeZoneConverter.dateZoneToDiff(bag.getZone()); | ||
if (offset != Integer.MIN_VALUE) { | ||
map.put("offset", offset); | ||
} | ||
} | ||
if (has(bag.getSecFraction())) { | ||
final RubyBignum secFraction = RubyBignum.newBignum(context.getRuntime(), bag.getSecFraction()); | ||
final RubyFixnum secFractionSize = RubyFixnum.newFixnum(context.getRuntime(), (long)Math.pow(10, bag.getSecFractionSize())); | ||
map.put("sec_fraction", RubyRational.newRationalCanonicalize(context, secFraction, secFractionSize)); | ||
} | ||
if (bag.has(bag.getSeconds())) { | ||
if (has(bag.getSecondsSize())) { | ||
final RubyBignum seconds = RubyBignum.newBignum(context.getRuntime(), bag.getSeconds()); | ||
final RubyFixnum secondsSize = RubyFixnum.newFixnum(context.getRuntime(), (long)Math.pow(10, bag.getSecondsSize())); | ||
map.put("seconds", RubyRational.newRationalCanonicalize(context, seconds, secondsSize)); | ||
} else { | ||
map.put("seconds", bag.getSeconds()); | ||
} | ||
} | ||
if (has(bag.getMerid())) { | ||
map.put("_merid", bag.getMerid()); | ||
} | ||
if (has(bag.getCent())) { | ||
map.put("_cent", bag.getCent()); | ||
} | ||
if (bag.getLeftover() != null) { | ||
final RubyString leftover = RubyString.newString(context.getRuntime(), bag.getLeftover()); | ||
if (tainted) { | ||
leftover.taint(context); | ||
} | ||
map.put("leftover", leftover); | ||
} | ||
|
||
return map; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 1.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 1.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
package org.jruby.util; | ||
|
||
/** | ||
* This class is ported from RubyDateFormatter.Format in JRuby 9.1.5.0. | ||
* @see https://github.com/jruby/jruby/blob/036ce39f0476d4bd718e23e64caff36bb50b8dbc/core/src/main/java/org/jruby/util/RubyDateFormatter.java | ||
*/ | ||
enum StrptimeFormat { | ||
FORMAT_STRING, // raw string, no formatting | ||
FORMAT_SPECIAL, // composition of other formats | ||
|
||
FORMAT_WEEK_LONG, // %A | ||
FORMAT_WEEK_SHORT, // %a | ||
FORMAT_MONTH_LONG, // %B | ||
FORMAT_MONTH_SHORT, // %b, %h | ||
FORMAT_CENTURY, // %C | ||
FORMAT_DAY, // %d | ||
FORMAT_DAY_S, // %e | ||
FORMAT_WEEKYEAR, // %G | ||
FORMAT_WEEKYEAR_SHORT, // %g | ||
FORMAT_HOUR, // %H | ||
FORMAT_HOUR_M, // %I | ||
FORMAT_DAY_YEAR, // %j | ||
FORMAT_HOUR_BLANK, // %k | ||
FORMAT_MILLISEC, // %L | ||
FORMAT_HOUR_S, // %l | ||
FORMAT_MINUTES, // %M | ||
FORMAT_MONTH, // %m | ||
FORMAT_NANOSEC, // %N | ||
FORMAT_MERIDIAN_LOWER_CASE, // %P | ||
FORMAT_MERIDIAN, // %p | ||
FORMAT_MICROSEC_EPOCH, // %Q Only for Date/DateTime from here | ||
FORMAT_SECONDS, // %S | ||
FORMAT_EPOCH, // %s | ||
FORMAT_WEEK_YEAR_S, // %U | ||
FORMAT_DAY_WEEK2, // %u | ||
FORMAT_WEEK_WEEKYEAR, // %V | ||
FORMAT_WEEK_YEAR_M, // %W | ||
FORMAT_DAY_WEEK, // %w | ||
FORMAT_YEAR_LONG, // %Y | ||
FORMAT_YEAR_SHORT, // %y | ||
|
||
FORMAT_COLON_ZONE_OFF, // %z, %:z, %::z, %:::z must be given number of colons as data | ||
|
||
FORMAT_ZONE_ID; // %Z Change between Time and Date | ||
} |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/***** BEGIN LICENSE BLOCK ***** | ||
* Version: EPL 1.0/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Eclipse Public | ||
* License Version 1.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of | ||
* the License at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Software distributed under the License is distributed on an "AS | ||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* rights and limitations under the License. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either of the GNU General Public License Version 2 or later (the "GPL"), | ||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the EPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the EPL, the GPL or the LGPL. | ||
***** END LICENSE BLOCK *****/ | ||
package org.jruby.util; | ||
|
||
import static org.jruby.util.StrptimeFormat.*; | ||
|
||
/** | ||
* This class is ported from RubyDateFormatter.Token in JRuby 9.1.5.0. | ||
* @see https://github.com/jruby/jruby/blob/036ce39f0476d4bd718e23e64caff36bb50b8dbc/core/src/main/java/org/jruby/util/RubyDateFormatter.java | ||
*/ | ||
public class StrptimeToken { | ||
static final StrptimeToken[] CONVERSION2TOKEN = new StrptimeToken[256]; | ||
|
||
static { | ||
CONVERSION2TOKEN['A'] = new StrptimeToken(FORMAT_WEEK_LONG); | ||
CONVERSION2TOKEN['a'] = new StrptimeToken(FORMAT_WEEK_SHORT); | ||
CONVERSION2TOKEN['B'] = new StrptimeToken(FORMAT_MONTH_LONG); | ||
CONVERSION2TOKEN['b'] = new StrptimeToken(FORMAT_MONTH_SHORT); | ||
CONVERSION2TOKEN['h'] = CONVERSION2TOKEN['b']; | ||
CONVERSION2TOKEN['C'] = new StrptimeToken(FORMAT_CENTURY); | ||
CONVERSION2TOKEN['d'] = new StrptimeToken(FORMAT_DAY); | ||
CONVERSION2TOKEN['e'] = new StrptimeToken(FORMAT_DAY_S); | ||
CONVERSION2TOKEN['G'] = new StrptimeToken(FORMAT_WEEKYEAR); | ||
CONVERSION2TOKEN['g'] = new StrptimeToken(FORMAT_WEEKYEAR_SHORT); | ||
CONVERSION2TOKEN['H'] = new StrptimeToken(FORMAT_HOUR); | ||
CONVERSION2TOKEN['I'] = new StrptimeToken(FORMAT_HOUR_M); | ||
CONVERSION2TOKEN['j'] = new StrptimeToken(FORMAT_DAY_YEAR); | ||
CONVERSION2TOKEN['k'] = new StrptimeToken(FORMAT_HOUR_BLANK); | ||
CONVERSION2TOKEN['L'] = new StrptimeToken(FORMAT_MILLISEC); | ||
CONVERSION2TOKEN['l'] = new StrptimeToken(FORMAT_HOUR_S); | ||
CONVERSION2TOKEN['M'] = new StrptimeToken(FORMAT_MINUTES); | ||
CONVERSION2TOKEN['m'] = new StrptimeToken(FORMAT_MONTH); | ||
CONVERSION2TOKEN['N'] = new StrptimeToken(FORMAT_NANOSEC); | ||
CONVERSION2TOKEN['P'] = new StrptimeToken(FORMAT_MERIDIAN_LOWER_CASE); | ||
CONVERSION2TOKEN['p'] = new StrptimeToken(FORMAT_MERIDIAN); | ||
CONVERSION2TOKEN['Q'] = new StrptimeToken(FORMAT_MICROSEC_EPOCH); | ||
CONVERSION2TOKEN['S'] = new StrptimeToken(FORMAT_SECONDS); | ||
CONVERSION2TOKEN['s'] = new StrptimeToken(FORMAT_EPOCH); | ||
CONVERSION2TOKEN['U'] = new StrptimeToken(FORMAT_WEEK_YEAR_S); | ||
CONVERSION2TOKEN['u'] = new StrptimeToken(FORMAT_DAY_WEEK2); | ||
CONVERSION2TOKEN['V'] = new StrptimeToken(FORMAT_WEEK_WEEKYEAR); | ||
CONVERSION2TOKEN['W'] = new StrptimeToken(FORMAT_WEEK_YEAR_M); | ||
CONVERSION2TOKEN['w'] = new StrptimeToken(FORMAT_DAY_WEEK); | ||
CONVERSION2TOKEN['Y'] = new StrptimeToken(FORMAT_YEAR_LONG); | ||
CONVERSION2TOKEN['y'] = new StrptimeToken(FORMAT_YEAR_SHORT); | ||
} | ||
|
||
private final StrptimeFormat format; | ||
private final Object data; | ||
|
||
StrptimeToken(StrptimeFormat format) { | ||
this(format, null); | ||
} | ||
|
||
StrptimeToken(StrptimeFormat formatString, Object data) { | ||
this.format = formatString; | ||
this.data = data; | ||
} | ||
|
||
public static StrptimeToken str(String str) { | ||
return new StrptimeToken(StrptimeFormat.FORMAT_STRING, str); | ||
} | ||
|
||
public static StrptimeToken format(char c) { | ||
return CONVERSION2TOKEN[c]; | ||
} | ||
|
||
public static StrptimeToken zoneOffsetColons(int colons) { | ||
return new StrptimeToken(StrptimeFormat.FORMAT_COLON_ZONE_OFF, colons); | ||
} | ||
|
||
public static StrptimeToken special(char c) { | ||
return new StrptimeToken(StrptimeFormat.FORMAT_SPECIAL, c); | ||
} | ||
|
||
/** | ||
* Gets the data. | ||
* @return Returns a Object | ||
*/ | ||
Object getData() { | ||
return data; | ||
} | ||
|
||
/** | ||
* Gets the format. | ||
* @return Returns a int | ||
*/ | ||
StrptimeFormat getFormat() { | ||
return format; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "<Token "+format+ " "+data+">"; | ||
} | ||
} |
474 changes: 474 additions & 0 deletions
474
core/src/main/java/org/jruby/util/TimeZoneConverter.java
Large diffs are not rendered by default.
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
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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class MethodVisibility | ||
|
||
private | ||
|
||
def priv_method; false end | ||
|
||
def publ_method; true end | ||
public :publ_method | ||
|
||
def prot_method; end | ||
protected :prot_method | ||
|
||
public | ||
|
||
def hello(arg = there) | ||
"Hello #{arg}" | ||
end | ||
|
||
def there | ||
@there ||= 'World!' | ||
end | ||
private :there | ||
|
||
protected | ||
|
||
java_signature 'public int protMethodWithJSign(String)' | ||
def prot_method_with_java_signature(str_arg) | ||
return str_arg.size | ||
end | ||
|
||
end |
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
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
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
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 |
---|---|---|
|
@@ -44,4 +44,4 @@ class Y | |
def test_include_order | ||
assert_equal Y.new.foo, [:Z, :A, :Q] | ||
end | ||
end | ||
end |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
jruby/test_command_line_switches | ||
jruby/test_launching_by_shell_script | ||
jruby/test_ffi_pointer_leak | ||
# only run when executed with jruby-complete.jar (jruby_complete_jar_extended profile) | ||
jruby/test_jar_complete |