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: 68d97798bef9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bad6bd324634
Choose a head ref
  • 7 commits
  • 14 files changed
  • 1 contributor

Commits on Aug 29, 2017

  1. Copy the full SHA
    fea8b07 View commit details
  2. Copy the full SHA
    4d8e4c3 View commit details
  3. Copy the full SHA
    e961d34 View commit details
  4. Copy the full SHA
    3cc8e37 View commit details
  5. Copy the full SHA
    4b749c3 View commit details
  6. follow casing rulez; deprecate JRuby::Util which is no longer used

    ... esp. since all of the meta methods are on JRuby module as well
    kares committed Aug 29, 2017
    Copy the full SHA
    ed222fd View commit details
  7. refactor JRuby::CONFIG into being the RubyInstanceConfig object

    also introduced security_restricted helpers + adjusted jruby.rb for doc
    kares committed Aug 29, 2017
    Copy the full SHA
    bad6bd3 View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4246,10 +4246,10 @@ public void setDoNotReverseLookupEnabled(boolean b) {
doNotReverseLookupEnabled = b;
}

private ThreadLocal<Map<Object, Object>> inspect = new ThreadLocal<Map<Object, Object>>();
private final ThreadLocal<Map<Object, Object>> inspect = new ThreadLocal<>();
public void registerInspecting(Object obj) {
Map<Object, Object> val = inspect.get();
if (val == null) inspect.set(val = new IdentityHashMap<Object, Object>());
if (val == null) inspect.set(val = new IdentityHashMap<>(8));
val.put(obj, null);
}

69 changes: 69 additions & 0 deletions core/src/main/java/org/jruby/ext/jruby/CoreExt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
**** 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 The JRuby Team
*
* 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.jruby;

import org.jruby.Ruby;
import org.jruby.RubyFixnum;
import org.jruby.RubyInteger;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

/**
* Native part for `require 'jruby/core_ext.rb'`.
*
* @author kares
*/
public abstract class CoreExt {

public static void loadStringExtensions(Ruby runtime) {
runtime.getString().defineAnnotatedMethods(String.class);
}

public static class String {

@JRubyMethod
public static RubyFixnum unseeded_hash(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
if (!(recv instanceof RubyString)) {
throw runtime.newTypeError(recv, runtime.getString());
}

return runtime.newFixnum(((RubyString) recv).unseededStrHashCode(runtime));
}

@JRubyMethod(name = "alloc", meta = true)
public static RubyString alloc(ThreadContext context, IRubyObject recv, IRubyObject size) {
return RubyString.newStringLight(context.runtime, RubyInteger.fix2int(size));
}

}

}
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.Visibility;

public abstract class JRubyExecutionContextLocal extends RubyObject {
private IRubyObject default_value;
@@ -49,8 +48,8 @@ public JRubyExecutionContextLocal(Ruby runtime, RubyClass type) {
default_proc = null;
}

@JRubyMethod(name = "initialize", required = 0, optional = 1, visibility = Visibility.PRIVATE)
public IRubyObject rubyInitialize(ThreadContext context, IRubyObject[] args, Block block) {
@JRubyMethod(name = "initialize", optional = 1, visibility = Visibility.PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
if (block.isGiven()) {
if (args.length != 0) {
throw context.runtime.newArgumentError("wrong number of arguments");
@@ -66,21 +65,17 @@ public IRubyObject rubyInitialize(ThreadContext context, IRubyObject[] args, Blo
throw context.runtime.newArgumentError("wrong number of arguments");
}
}
return context.runtime.getNil();
return context.nil;
}

@JRubyMethod(name = "default", required = 0)
public IRubyObject getDefault(ThreadContext context) {
@JRubyMethod(name = "default")
public IRubyObject getDefault() {
return default_value;
}

@JRubyMethod(name = "default_proc", required = 0)
public IRubyObject getDefaultProc(ThreadContext context) {
if (default_proc != null) {
return default_proc;
} else {
return context.runtime.getNil();
}
@JRubyMethod(name = "default_proc")
public IRubyObject getDefaultProc() {
return (default_proc != null) ? default_proc : getRuntime().getNil();
}

@JRubyMethod(name = "value", required = 0)
@@ -91,16 +86,16 @@ public IRubyObject getValue(ThreadContext context) {
value = contextVariables.get(this);
if (value != null) {
return value;
} else if (default_proc != null) {
}
if (default_proc != null) {
// pre-set for the sake of terminating recursive calls
contextVariables.put(this, context.runtime.getNil());
contextVariables.put(this, context.nil);
final IRubyObject new_value;
new_value = default_proc.call(context, IRubyObject.NULL_ARRAY, null, Block.NULL_BLOCK);
contextVariables.put(this, new_value);
return new_value;
} else {
return default_value;
}
return default_value;
}

@JRubyMethod(name = "value=", required = 1)
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@

@JRubyClass(name = "JRuby::FiberLocal")
public final class JRubyFiberLocal extends JRubyExecutionContextLocal {
public static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {

static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass type) {
return new JRubyFiberLocal(runtime, type);
}
71 changes: 47 additions & 24 deletions core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@

import org.jcodings.specific.ASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyBoolean;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.RubyString;
@@ -49,9 +50,11 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
import org.jruby.util.ByteList;
import org.jruby.util.ClasspathLauncher;

import java.io.ByteArrayInputStream;

@@ -68,24 +71,30 @@ public void load(Ruby runtime, boolean wrap) {
// load Ruby parts of the 'jruby' library
runtime.getLoadService().loadFromClassLoader(runtime.getJRubyClassLoader(), "jruby/jruby.rb", false);

// define JRuby module
RubyModule jrubyModule = runtime.getOrCreateModule("JRuby");
RubyModule JRuby = runtime.getOrCreateModule("JRuby");

jrubyModule.defineAnnotatedMethods(JRubyLibrary.class);
jrubyModule.defineAnnotatedMethods(JRubyUtilLibrary.class);
JRuby.defineAnnotatedMethods(JRubyLibrary.class);
JRuby.defineAnnotatedMethods(JRubyUtilLibrary.class);

RubyClass threadLocalClass = jrubyModule.defineClassUnder("ThreadLocal", runtime.getObject(), JRubyThreadLocal.ALLOCATOR);
threadLocalClass.defineAnnotatedMethods(JRubyExecutionContextLocal.class);
JRuby.defineClassUnder("ThreadLocal", runtime.getObject(), JRubyThreadLocal.ALLOCATOR)
.defineAnnotatedMethods(JRubyExecutionContextLocal.class);

RubyClass fiberLocalClass = jrubyModule.defineClassUnder("FiberLocal", runtime.getObject(), JRubyFiberLocal.ALLOCATOR);
fiberLocalClass.defineAnnotatedMethods(JRubyExecutionContextLocal.class);
JRuby.defineClassUnder("FiberLocal", runtime.getObject(), JRubyFiberLocal.ALLOCATOR)
.defineAnnotatedMethods(JRubyExecutionContextLocal.class);

RubyModule config = jrubyModule.defineModuleUnder("CONFIG");
config.getSingletonClass().defineAnnotatedMethods(JRubyConfig.class);
/**
* JRuby::CONFIG ~ shortcut for JRuby.runtime.instance_config
* @since 9.2
*/
IRubyObject config = Java.getInstance(runtime, runtime.getInstanceConfig());
config.getMetaClass().defineAlias("rubygems_disabled?", "isDisableGems");
config.getMetaClass().defineAlias("did_you_mean_disabled?", "isDisableDidYouMean");
JRuby.setConstant("CONFIG", config);
}

@Deprecated // old JRuby.defineModuleUnder("CONFIG")
public static class JRubyConfig {
@JRubyMethod(name = "rubygems_disabled?")
// @JRubyMethod(name = "rubygems_disabled?")
public static IRubyObject rubygems_disabled_p(ThreadContext context, IRubyObject self) {
return context.runtime.newBoolean(context.runtime.getInstanceConfig().isDisableGems());
}
@@ -115,19 +124,6 @@ public static IRubyObject runtime(ThreadContext context, IRubyObject recv) {
return Java.wrapJavaObject(context.runtime, context.runtime); // context.nil.getRuntime()
}

/**
* JRuby.config a shortcut for JRuby.runtime.instance_config
* @param context
* @param recv
* @return a wrapped RubyInstanceConfig
* @since 9.2
*/
// TODO needs to get fine tuned considering there's a CONFIG constant already
// @JRubyMethod(module = true)
public static IRubyObject config(ThreadContext context, IRubyObject recv) {
return Java.wrapJavaObject(context.runtime, context.runtime.getInstanceConfig());
}

/**
* Unwrap the given Java-integration-wrapped object, returning the unwrapped
* object. If the wrapped object is not a Ruby object, an error will raise.
@@ -178,6 +174,19 @@ public static IRubyObject set_context_class_loader(ThreadContext context, IRubyO
return Java.wrapJavaObject(context.runtime, loader); // reference0
}

@JRubyMethod(name = "security_restricted?", module = true)
public static RubyBoolean is_security_restricted(IRubyObject recv) {
final Ruby runtime = recv.getRuntime();
return RubyBoolean.newBoolean(runtime, Ruby.isSecurityRestricted());
}

// NOTE: its probably too late to set this when jruby library is booted (due the java library) ?
@JRubyMethod(name = "security_restricted=", module = true)
public static IRubyObject set_security_restricted(IRubyObject recv, IRubyObject arg) {
Ruby.setSecurityRestricted(arg.isTrue());
return is_security_restricted(recv);
}

/**
* Provide the "identity" hash code that System.identityHashCode would produce.
*
@@ -190,6 +199,14 @@ public static IRubyObject identity_hash(ThreadContext context, IRubyObject recv,
return context.runtime.newFixnum(System.identityHashCode(obj));
}

@JRubyMethod(module = true) // for RubyGems' JRuby defaults
public static IRubyObject classpath_launcher(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
String launcher = runtime.getInstanceConfig().getEnvironment().get("RUBY");
if ( launcher == null ) launcher = ClasspathLauncher.jrubyCommand(runtime);
return runtime.newString(launcher);
}


@JRubyMethod(module = true, name = "parse", alias = "ast_for", required = 1, optional = 3)
public static IRubyObject parse(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
@@ -284,4 +301,10 @@ public static IRubyObject compile(ThreadContext context, IRubyObject recv, IRuby
}, Block.NULL_BLOCK);
}

@JRubyMethod(module = true, visibility = Visibility.PRIVATE)
public static IRubyObject load_string_ext(ThreadContext context, IRubyObject recv) {
CoreExt.loadStringExtensions(context.runtime);
return context.nil;
}

}
29 changes: 16 additions & 13 deletions core/src/main/java/org/jruby/ext/jruby/JRubyObjectInputStream.java
Original file line number Diff line number Diff line change
@@ -15,16 +15,19 @@
import org.jruby.runtime.Visibility;

public class JRubyObjectInputStream extends RubyObject {

JRubyObjectInputStreamImpl impl;
private static final ObjectAllocator JROIS_ALLOCATOR = new ObjectAllocator() {

private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new JRubyObjectInputStream(runtime, klass);
return new JRubyObjectInputStream(runtime, klass);
}
};

public static RubyClass createJRubyObjectInputStream(Ruby runtime) {
RubyClass result = runtime.defineClass("JRubyObjectInputStream",runtime.getObject(),JROIS_ALLOCATOR);
result.defineAnnotatedMethods(JRubyObjectInputStream.class);
return result;
RubyClass result = runtime.defineClass("JRubyObjectInputStream",runtime.getObject(), ALLOCATOR);
result.defineAnnotatedMethods(JRubyObjectInputStream.class);
return result;
}

@JRubyMethod(name = "new", rest = true, meta = true)
@@ -36,14 +39,14 @@ public static IRubyObject newInstance(IRubyObject recv, IRubyObject[] args, Bloc


public JRubyObjectInputStream(Ruby runtime, RubyClass rubyClass) {
super(runtime,rubyClass);
super(runtime,rubyClass);
}

@JRubyMethod(name="initialize",required=1, visibility = Visibility.PRIVATE)
public IRubyObject initialize(IRubyObject wrappedStream) {
InputStream stream = (InputStream)wrappedStream.toJava(InputStream.class);
InputStream stream = (InputStream) wrappedStream.toJava(InputStream.class);
try {
impl = new JRubyObjectInputStreamImpl(getRuntime(),stream);
impl = new JRubyObjectInputStreamImpl(getRuntime(), stream);
} catch (IOException ioe) {
throw getRuntime().newIOErrorFromException(ioe);
}
@@ -53,7 +56,7 @@ public IRubyObject initialize(IRubyObject wrappedStream) {
@JRubyMethod(name="read_object", alias="readObject")
public IRubyObject readObject() {
try {
return Java.getInstance(getRuntime(),impl.readObject());
return Java.getInstance(getRuntime(), impl.readObject());
} catch (IOException ioe) {
throw getRuntime().newIOErrorFromException(ioe);
} catch (ClassNotFoundException cnfe) {
@@ -73,15 +76,15 @@ public IRubyObject close() {
}

static class JRubyObjectInputStreamImpl extends ObjectInputStream {
protected Ruby runtime;
protected final Ruby runtime;

public JRubyObjectInputStreamImpl(Ruby rt,InputStream in) throws IOException {
public JRubyObjectInputStreamImpl(Ruby runtime, InputStream in) throws IOException {
super(in);
runtime = rt;
this.runtime = runtime;
}
@Override
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
return Class.forName(desc.getName(),true,runtime.getJRubyClassLoader());
return Class.forName(desc.getName(), true, runtime.getJRubyClassLoader());
}
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ext/jruby/JRubyThreadLocal.java
Original file line number Diff line number Diff line change
@@ -36,8 +36,7 @@

@JRubyClass(name = "JRuby::ThreadLocal")
public final class JRubyThreadLocal extends JRubyExecutionContextLocal {
public static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {

static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass type) {
return new JRubyThreadLocal(runtime, type);
}
Loading