Skip to content

Commit

Permalink
Showing 71 changed files with 1,305 additions and 545 deletions.
2 changes: 1 addition & 1 deletion lib/ruby/truffle/jruby+truffle/gem_ci/activemodel.rb
Original file line number Diff line number Diff line change
@@ -8,5 +8,5 @@

has_to_succeed setup

result run(%w[--require-pattern test/**/*_test.rb -r exclude_tests -- -I test -e nil], raise: false)
result run(%w[--require-pattern test/**/*_test.rb -- -I test -e nil], raise: false)

118 changes: 25 additions & 93 deletions lib/ruby/truffle/jruby+truffle/gem_configurations/activemodel.yaml
Original file line number Diff line number Diff line change
@@ -37,106 +37,39 @@
end
end
require 'active_model'
require 'active_model/secure_password'
module ActiveModel
module SecurePassword
extend ActiveSupport::Concern
module InstanceMethodsOnActivation
def authenticate(unencrypted_password)
password_digest == unencrypted_password && self
require 'bcrypt'
module BCrypt
class Engine
def self.hash_secret(secret, salt, _ = nil)
if valid_secret?(secret)
if valid_salt?(salt)
Truffle::Gem::BCrypt.hashpw(secret.to_s, salt.to_s)
else
raise Errors::InvalidSalt.new("invalid salt")
end
else
raise Errors::InvalidSecret.new("invalid secret")
end
end
attr_reader :password
def password=(unencrypted_password)
self.password_digest = unencrypted_password
def self.generate_salt(cost = self.cost)
cost = cost.to_i
if cost > 0
if cost < MIN_COST
cost = MIN_COST
end
Truffle::Gem::BCrypt.gensalt(cost)
else
raise Errors::InvalidCost.new("cost must be numeric and > 0")
end
end
end
end
bcrypt.rb: |
puts 'bcrypt stubbed'
module BCrypt
module Password
def self.create(password, *args)
password
end
end
module Engine
MIN_COST = nil
end
end
java.rb: nil
bcrypt_ext.rb: nil
bundler.rb: "module Bundler; def self.setup; end; end"
# mock method_source gem
# method_source.rb: nil
exclude_tests.rb: |
failures = { AttributeMethodsTest: [:"test_#define_attribute_methods_generates_attribute_methods",
:"test_#define_attribute_methods_generates_attribute_methods_with_spaces_in_their_names",
:"test_#define_attribute_methods_works_passing_multiple_arguments"],
SecurePasswordTest: [:test_Password_digest_cost_can_be_set_to_bcrypt_min_cost_to_speed_up_tests,
:test_Password_digest_cost_defaults_to_bcrypt_default_cost_when_min_cost_is_false,
:test_Password_digest_cost_honors_bcrypt_cost_attribute_when_min_cost_is_false,
:test_create_a_new_user_with_validation_and_a_blank_password_confirmation,
:test_create_a_new_user_with_validation_and_a_spaces_only_password,
:test_create_a_new_user_with_validation_and_an_incorrect_password_confirmation,
:test_create_a_new_user_with_validation_and_password_length_greater_than_72,
:test_setting_a_blank_password_should_not_change_an_existing_password,
:test_updating_an_existing_user_with_validation_and_a_blank_password,
:test_updating_an_existing_user_with_validation_and_a_blank_password_and_password_confirmation,
:test_updating_an_existing_user_with_validation_and_a_blank_password_confirmation,
:test_updating_an_existing_user_with_validation_and_a_spaces_only_password,
:test_updating_an_existing_user_with_validation_and_an_incorrect_password_confirmation,
:test_updating_an_existing_user_with_validation_and_password_length_greater_than_72],
I18nValidationTest: [:test_validates_acceptance_of_finds_custom_model_key_translation_when_accepted,
:test_validates_acceptance_of_finds_custom_model_key_translation_with_interpolation_when_accepted,
:test_validates_acceptance_of_finds_global_default_key_translation_when_accepted,
:test_validates_confirmation_of_finds_custom_model_key_translation_when_confirmation,
:test_validates_confirmation_of_finds_custom_model_key_translation_with_interpolation_when_confirmation,
:test_validates_confirmation_of_finds_global_default_key_translation_when_confirmation,
:test_validates_exclusion_of_finds_custom_model_key_translation_when_exclusion,
:test_validates_exclusion_of_finds_custom_model_key_translation_with_interpolation_when_exclusion,
:test_validates_exclusion_of_finds_global_default_key_translation_when_exclusion,
:test_validates_format_of_finds_custom_model_key_translation_when_invalid,
:test_validates_format_of_finds_custom_model_key_translation_with_interpolation_when_invalid,
:test_validates_format_of_finds_global_default_key_translation_when_invalid,
:test_validates_inclusion_of_finds_custom_model_key_translation_when_inclusion,
:test_validates_inclusion_of_finds_custom_model_key_translation_with_interpolation_when_inclusion,
:test_validates_inclusion_of_finds_global_default_key_translation_when_inclusion,
:test_validates_length_of_finds_custom_model_key_translation_when_too_long,
:test_validates_length_of_finds_custom_model_key_translation_when_too_short,
:test_validates_length_of_finds_custom_model_key_translation_when_wrong_length,
:test_validates_length_of_finds_custom_model_key_translation_with_interpolation_when_too_long,
:test_validates_length_of_finds_custom_model_key_translation_with_interpolation_when_too_short,
:test_validates_length_of_finds_custom_model_key_translation_with_interpolation_when_wrong_length,
:test_validates_length_of_finds_global_default_key_translation_when_too_long,
:test_validates_length_of_finds_global_default_key_translation_when_too_short,
:test_validates_length_of_finds_global_default_key_translation_when_wrong_length,
:test_validates_numericality_of_finds_custom_model_key_translation_when_less_than,
:test_validates_numericality_of_finds_custom_model_key_translation_when_not_a_number,
:test_validates_numericality_of_finds_custom_model_key_translation_when_not_an_integer,
:test_validates_numericality_of_finds_custom_model_key_translation_when_odd,
:test_validates_numericality_of_finds_custom_model_key_translation_with_interpolation_when_less_than,
:test_validates_numericality_of_finds_custom_model_key_translation_with_interpolation_when_not_a_number,
:test_validates_numericality_of_finds_custom_model_key_translation_with_interpolation_when_not_an_integer,
:test_validates_numericality_of_finds_custom_model_key_translation_with_interpolation_when_odd,
:test_validates_numericality_of_finds_global_default_key_translation_when_less_than,
:test_validates_numericality_of_finds_global_default_key_translation_when_not_a_number,
:test_validates_numericality_of_finds_global_default_key_translation_when_not_an_integer,
:test_validates_numericality_of_finds_global_default_key_translation_when_odd,
:test_validates_presence_of_finds_custom_model_key_translation_when_blank,
:test_validates_presence_of_finds_custom_model_key_translation_with_interpolation_when_blank,
:test_validates_presence_of_finds_global_default_key_translation_when_blank],
NumericalityValidationTest: [:test_validates_numericality_with_equal_to] }
Truffle.exclude_rspec_examples failures

# do not let bundler to install db gem group
:without:
@@ -149,6 +82,5 @@
- rubygems
- shims
- openssl-stubs
- truffle/exclude_rspec_examples
:environment:
N: 1
4 changes: 2 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/Layouts.java
Original file line number Diff line number Diff line change
@@ -66,8 +66,7 @@
import org.jruby.truffle.core.rubinius.IOBufferLayoutImpl;
import org.jruby.truffle.core.rubinius.IOLayout;
import org.jruby.truffle.core.rubinius.IOLayoutImpl;
import org.jruby.truffle.core.rubinius.PointerLayout;
import org.jruby.truffle.core.rubinius.PointerLayoutImpl;
import org.jruby.truffle.extra.ffi.PointerLayout;
import org.jruby.truffle.core.rubinius.RandomizerLayout;
import org.jruby.truffle.core.rubinius.RandomizerLayoutImpl;
import org.jruby.truffle.core.rubinius.StatLayout;
@@ -84,6 +83,7 @@
import org.jruby.truffle.core.time.TimeLayoutImpl;
import org.jruby.truffle.core.tracepoint.TracePointLayout;
import org.jruby.truffle.core.tracepoint.TracePointLayoutImpl;
import org.jruby.truffle.extra.ffi.PointerLayoutImpl;
import org.jruby.truffle.stdlib.bigdecimal.BigDecimalLayout;
import org.jruby.truffle.stdlib.bigdecimal.BigDecimalLayoutImpl;
import org.jruby.truffle.stdlib.digest.DigestLayout;
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ private static void addMethod(RubyContext context, DynamicObject module, RubyRoo
private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails) {
final CoreMethod method = methodDetails.getMethodAnnotation();

final SourceSection sourceSection = SourceSection.createUnavailable(null, String.format("%s#%s", methodDetails.getClassAnnotation().value(), method.names()[0]));
final SourceSection sourceSection = SourceSection.createUnavailable("core", String.format("%s#%s", methodDetails.getClassAnnotation().value(), method.names()[0]));

final int required = method.required();
final int optional = method.optional();
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.core.rubinius.IOBufferPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.IOPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.NativeFunctionPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.PointerPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RandomizerPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.RegexpPrimitiveNodesFactory;
import org.jruby.truffle.core.rubinius.StatPrimitiveNodesFactory;
@@ -37,6 +36,7 @@
import org.jruby.truffle.core.symbol.SymbolNodesFactory;
import org.jruby.truffle.core.thread.ThreadNodesFactory;
import org.jruby.truffle.core.time.TimeNodesFactory;
import org.jruby.truffle.extra.ffi.PointerPrimitiveNodesFactory;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;

5 changes: 5 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@
import org.jruby.truffle.debug.TruffleDebugNodesFactory;
import org.jruby.truffle.extra.AttachmentsInternalNodesFactory;
import org.jruby.truffle.extra.TruffleGraalNodesFactory;
import org.jruby.truffle.gem.bcrypt.BCryptNodesFactory;
import org.jruby.truffle.interop.CExtNodesFactory;
import org.jruby.truffle.interop.InteropNodesFactory;
import org.jruby.truffle.language.RubyGuards;
@@ -605,6 +606,9 @@ public CoreLibrary(RubyContext context) {
bigDecimalClass = defineClass(truffleModule, numericClass, "BigDecimal");
Layouts.CLASS.setInstanceFactoryUnsafe(bigDecimalClass, Layouts.BIG_DECIMAL.createBigDecimalShape(bigDecimalClass, bigDecimalClass));

final DynamicObject gem = defineModule(truffleModule, "Gem");
defineModule(gem, "BCrypt");

// Rubinius

rubiniusModule = defineModule("Rubinius");
@@ -753,6 +757,7 @@ public void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(TruffleProcessNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleDebugNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleBindingNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(BCryptNodesFactory.getFactories());

coreMethodNodeManager.allMethodInstalled();

Original file line number Diff line number Diff line change
@@ -2068,15 +2068,15 @@ public DynamicObject sortVeryShort(VirtualFrame frame, DynamicObject array, NotP
public Object sortLargeArray(VirtualFrame frame, DynamicObject array, NotProvided block,
@Cached("new()") SnippetNode snippetNode) {
return snippetNode.execute(frame,
"sorted = dup; Rubinius.privately { sorted.isort!(0, right) }; sorted",
"sorted = dup; Truffle.privately { sorted.isort!(0, right) }; sorted",
"right", getSize(array));
}

@Specialization(guards = { "!isNullArray(array)" })
public Object sortWithBlock(VirtualFrame frame, DynamicObject array, DynamicObject block,
@Cached("new()") SnippetNode snippet) {
return snippet.execute(frame,
"sorted = dup; Rubinius.privately { sorted.isort_block!(0, right, block) }; sorted",
"sorted = dup; Truffle.privately { sorted.isort_block!(0, right, block) }; sorted",
"right", getSize(array),
"block", block);
}
Original file line number Diff line number Diff line change
@@ -1233,7 +1233,7 @@ public boolean isMethodDefined(DynamicObject module, String name, boolean inheri
method = Layouts.MODULE.getFields(module).getMethod(name);
}

return method != null && !method.getVisibility().isPrivate();
return method != null && !method.getVisibility().isPrivate() && !method.isUndefined();
}

}
Original file line number Diff line number Diff line change
@@ -139,6 +139,7 @@ public Object mul(
@CoreMethod(names = {"/", "__slash__"}, required = 1)
public abstract static class DivNode extends BignumCoreMethodNode {

@TruffleBoundary
@Specialization
public Object div(DynamicObject a, long b) {
final BigInteger bBigInt = BigInteger.valueOf(b);
@@ -151,11 +152,13 @@ public Object div(DynamicObject a, long b) {
}
}

@TruffleBoundary
@Specialization
public double div(DynamicObject a, double b) {
return Layouts.BIGNUM.getValue(a).doubleValue() / b;
}

@TruffleBoundary
@Specialization(guards = "isRubyBignum(b)")
public Object div(DynamicObject a, DynamicObject b) {
final BigInteger aBigInt = Layouts.BIGNUM.getValue(a);
@@ -173,6 +176,7 @@ public Object div(DynamicObject a, DynamicObject b) {
@CoreMethod(names = {"%", "modulo"}, required = 1)
public abstract static class ModNode extends BignumCoreMethodNode {

@TruffleBoundary
@Specialization
public Object mod(DynamicObject a, long b) {
if (b == 0) {
@@ -185,6 +189,7 @@ public Object mod(DynamicObject a, long b) {
return fixnumOrBignum(Layouts.BIGNUM.getValue(a).mod(BigInteger.valueOf(b)));
}

@TruffleBoundary
@Specialization(guards = "isRubyBignum(b)")
public Object mod(DynamicObject a, DynamicObject b) {
final BigInteger bigint = Layouts.BIGNUM.getValue(b);
10 changes: 3 additions & 7 deletions truffle/src/main/java/org/jruby/truffle/core/rope/RopeTable.java
Original file line number Diff line number Diff line change
@@ -158,19 +158,15 @@ public Rope getRope(byte[] bytes, Encoding encoding, CodeRange codeRange) {
}

public boolean contains(Rope rope) {
final Key key = new Key(rope.getBytes(), rope.getEncoding());

lock.readLock().lock();

try {
for (Map.Entry<Key, WeakReference<Rope>> entry : ropesTable.entrySet()) {
if (entry.getValue().get() == rope) {
return true;
}
}
return ropesTable.get(key) != null;
} finally {
lock.readLock().unlock();
}

return false;
}

public int getByteArrayReusedCount() {
Loading

0 comments on commit 9be859a

Please sign in to comment.