protected DynamicMessage build(ThreadContext context, int depth) { if (depth > SINK_MAXIMUM_NESTING) { throw context.runtime.newRuntimeError("Maximum recursion depth exceeded during encoding."); } for (Descriptors.FieldDescriptor fieldDescriptor : maps.keySet()) { this.builder.clearField(fieldDescriptor); RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor); for (DynamicMessage kv : maps.get(fieldDescriptor).build(context, mapDescriptor)) { this.builder.addRepeatedField(fieldDescriptor, kv); } } for (Descriptors.FieldDescriptor fieldDescriptor : repeatedFields.keySet()) { RubyRepeatedField repeatedField = repeatedFields.get(fieldDescriptor); this.builder.clearField(fieldDescriptor); for (int i = 0; i < repeatedField.size(); i++) { Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth); this.builder.addRepeatedField(fieldDescriptor, item); } } for (Descriptors.FieldDescriptor fieldDescriptor : fields.keySet()) { IRubyObject value = fields.get(fieldDescriptor); this.builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth)); } return this.builder.build(); }
@JRubyMethod(meta = true) public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) { byte[] bin = data.convertToString().getBytes(); RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); try { ret.builder.mergeFrom(bin); } catch (InvalidProtocolBufferException e) { throw context.runtime.newRuntimeError(e.getMessage()); } return ret; }
throw runtime.newRuntimeError(e.getMessage());
public boolean hasScanEvent() { if (lex_p < tokp) { throw parser.getRuntime().newRuntimeError("lex_p < tokp"); } return lex_p > tokp; }
public IRubyObject op_pow(ThreadContext context, long other) { // FIXME this needs to do the right thing for 1.9 mode before we can use it if (context.is19) throw context.runtime.newRuntimeError("bug: using direct op_pow(long) in 1.8 mode"); return powerFixnum(context, other); }
protected final void checkIterating() { if (iteratorCount > 0) { throw getRuntime().newRuntimeError("can't add a new key into hash during iteration"); } }
private void emit(ThreadContext context, Event event) { try { if (emitter == null) throw context.runtime.newRuntimeError("uninitialized emitter"); emitter.emit(event); } catch (IOException ioe) { throw context.runtime.newIOErrorFromException(ioe); } catch (EmitterException ee) { throw context.runtime.newRuntimeError(ee.toString()); } }
public void free() { if (allocation.released) { throw getRuntime().newRuntimeError("memory already freed"); } allocation.free(); }
public void free() { if (allocation.released) { throw getRuntime().newRuntimeError("memory already freed"); } allocation.free(); }
private static void generateFieldAccessors(ThreadContext context, final RubyClass klass, final Class<?> javaClass) { for ( String name : getJavaFieldNames(klass) ) { Field field; try { field = javaClass.getDeclaredField(name); } catch (NoSuchFieldException e) { throw context.runtime.newRuntimeError("no field: '" + name + "' in reified class for " + klass.getName()); } JavaProxy.installField(context, name, field, klass); } }
public void free() { if (allocation.isReleased()) { throw getRuntime().newRuntimeError("memory already freed"); } allocation.free(); sentinel = null; }
public void free() { if (allocation.isReleased()) { throw getRuntime().newRuntimeError("memory already freed"); } allocation.free(); sentinel = null; }
@JRubyMethod(name = "autorelease=") public final IRubyObject autorelease(ThreadContext context, IRubyObject autorelease) { Reaper r = reaper; if (r == null || r.released) { throw context.runtime.newRuntimeError("pointer already freed"); } r.autorelease(autorelease.isTrue()); return context.runtime.getNil(); }
@JRubyMethod() public IRubyObject block_length() { if (blockLength == 0) { throw getRuntime().newRuntimeError( this.getMetaClass() + " doesn't implement block_length()"); } return RubyFixnum.newFixnum(getRuntime(), blockLength); }
private void initEmitter(ThreadContext context, IRubyObject _encoding) { if (emitter != null) throw context.runtime.newRuntimeError("already initialized emitter"); Encoding encoding = PsychLibrary.YAMLEncoding.values()[(int)_encoding.convertToInteger().getLongValue()].encoding; Charset charset = context.runtime.getEncodingService().charsetForEncoding(encoding); emitter = new Emitter(new OutputStreamWriter(new IOOutputStream(io, encoding), charset), options); }
@JRubyMethod(module = true) public static IRubyObject peek_result(ThreadContext context, IRubyObject self) { Ruby runtime = context.runtime; if (!runtime.getCoverageData().isCoverageEnabled()) { throw runtime.newRuntimeError("coverage measurement is not enabled"); } return convertCoverageToRuby(context, runtime, runtime.getCoverageData().getCoverage()); }
@JRubyMethod(name = "free") public final IRubyObject free(ThreadContext context) { if (getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).free(); } else { throw context.runtime.newRuntimeError("cannot free non-allocated function"); } // Replace memory object with one that throws an exception on any access setMemoryIO(new FreedMemoryIO(context.runtime)); return context.nil; }
@JRubyMethod(module = true) public static IRubyObject peek_result(ThreadContext context, IRubyObject self) { Ruby runtime = context.runtime; if (!runtime.getCoverageData().isCoverageEnabled()) { throw runtime.newRuntimeError("coverage measurement is not enabled"); } return convertCoverageToRuby(context, runtime, runtime.getCoverageData().getCoverage()); }
public RubyIO(Ruby runtime, InputStream inputStream) { super(runtime, runtime.getIO()); if (inputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = MakeOpenFile(); openFile.setFD(new ChannelFD(readableChannel(inputStream), runtime.getPosix(), runtime.getFilenoUtil())); openFile.setMode(OpenFile.READABLE); }
public RubyIO(Ruby runtime, OutputStream outputStream, boolean autoclose) { super(runtime, runtime.getIO()); // We only want IO objects with valid streams (better to error now). if (outputStream == null) { throw runtime.newRuntimeError("Opening null stream"); } openFile = MakeOpenFile(); openFile.setFD(new ChannelFD(writableChannel(outputStream), runtime.getPosix(), runtime.getFilenoUtil())); openFile.setMode(OpenFile.WRITABLE | OpenFile.APPEND); openFile.setAutoclose(autoclose); }