Beispiel #1
0
  @JRubyMethod(name = "codepoints")
  public IRubyObject codepoints(ThreadContext context, Block block) {
    Ruby runtime = context.runtime;
    runtime.getWarnings().warn("StringIO#codepoints is deprecated; use #each_codepoint");

    if (!block.isGiven()) return enumeratorize(runtime, this, "each_codepoint");

    return each_codepoint(context, block);
  }
 public static void saveToCodeCache(
     Ruby ruby, byte[] bytecode, String packageName, File cachedClassFile) {
   String codeCache = RubyInstanceConfig.JIT_CODE_CACHE;
   File codeCacheDir = new File(codeCache);
   if (!codeCacheDir.exists()) {
     ruby.getWarnings().warn("jruby.jit.codeCache directory " + codeCacheDir + " does not exist");
   } else if (!codeCacheDir.isDirectory()) {
     ruby.getWarnings()
         .warn("jruby.jit.codeCache directory " + codeCacheDir + " is not a directory");
   } else if (!codeCacheDir.canWrite()) {
     ruby.getWarnings().warn("jruby.jit.codeCache directory " + codeCacheDir + " is not writable");
   } else {
     if (!new File(codeCache, packageName).isDirectory()) {
       boolean createdDirs = new File(codeCache, packageName).mkdirs();
       if (!createdDirs) {
         ruby.getWarnings()
             .warn("could not create JIT cache dir: " + new File(codeCache, packageName));
       }
     }
     // write to code cache
     FileOutputStream fos = null;
     try {
       if (RubyInstanceConfig.JIT_LOADING_DEBUG)
         LOG.info("writing jitted code to to " + cachedClassFile);
       fos = new FileOutputStream(cachedClassFile);
       fos.write(bytecode);
     } catch (Exception e) {
       e.printStackTrace();
       // ignore
     } finally {
       try {
         fos.close();
       } catch (Exception e) {
       }
     }
   }
 }
Beispiel #3
0
  public static RubyModule getClassVariableBase(Ruby runtime, StaticScope scope) {
    RubyModule rubyClass = scope.getModule();
    while (rubyClass.isSingleton() || rubyClass == runtime.getDummy()) {
      // We ran out of scopes to check
      if (scope == null) return null;

      scope = scope.getPreviousCRefScope();
      rubyClass = scope.getModule();
      if (scope.getPreviousCRefScope() == null) {
        runtime
            .getWarnings()
            .warn(
                ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD,
                "class variable access from toplevel singleton method");
      }
    }
    return rubyClass;
  }
Beispiel #4
0
 private void warnAboutUninitializedIvar(Ruby runtime, String name) {
   runtime
       .getWarnings()
       .warning(ID.IVAR_NOT_INITIALIZED, "instance variable " + name + " not initialized");
 }
 private void blockArgWarning(Ruby ruby, int length) {
   ruby.getWarnings()
       .warn(
           ID.MULTIPLE_VALUES_FOR_BLOCK,
           "multiple values for a block parameter (" + length + " for 1)");
 }
 private IRubyObject warnMultiReturnNil(Ruby ruby) {
   ruby.getWarnings()
       .warn(ID.MULTIPLE_VALUES_FOR_BLOCK, "multiple values for a block parameter (0 for 1)");
   return ruby.getNil();
 }