Repository navigation
C API: TracePoint, debug inspector, digest plugins; capi specs pass in full #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* **************************************************************************** | ||
| * | ||
| * This source code is subject to terms and conditions of the Apache License, Version 2.0. A | ||
| * copy of the license can be found in the License.html file at the root of this distribution. | ||
| * | ||
| * ***************************************************************************/ | ||
|
|
||
| namespace IronRuby.Builtins { | ||
| /// <summary> | ||
| /// The bytes an object holds outside its slot, as a C extension's rb_data_type_t.dsize function | ||
| /// reports them. ObjectSpace.memsize_of adds it to the slot, as MRI does. | ||
| /// </summary> | ||
| public interface IMemorySized { | ||
| long ExtraMemorySize { get; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,7 +126,11 @@ internal static object InvokeMethod(CMethod/*!*/ method, RubyScope/*!*/ scope, o | |
| argv[i] = ToValue(args[i]); | ||
| } | ||
| result = CallMethod(method.Function, method.Arity, selfValue, argc, argv); | ||
| for (int i = 0; i < argc; i++) { | ||
| SyncRawFreeze(argv[i]); | ||
| } | ||
| } | ||
| SyncRawFreeze(selfValue); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synchronize the returned object's raw freeze flag. If a C method creates a string, sets Call
|
||
| return FromValue(result); | ||
| } catch (CBlockBreak b) when (b.Bfc == frame.Bfc && frame.Bfc != null) { | ||
| return b.ReturnValue; | ||
|
|
@@ -299,9 +303,18 @@ internal static object SendWith(bool publicOnly, object target, string/*!*/ name | |
| // caller's frame - $~ by Regexp#match, $_ by gets - is the Ruby frame that called the C | ||
| // method, as in CRuby (the svar of the nearest Ruby-level frame). | ||
| RubyScope scope = (_frame != null ? _frame.Scope : null) ?? _context.EmptyScope; | ||
| if (name == "binding" && _frame != null && IsKernelBinding(target)) { | ||
| // Kernel#binding would capture the frame of the C method's caller | ||
| throw RubyExceptions.CreateRuntimeError("Can't create Binding from C level function"); | ||
| } | ||
| return site.Target(site, scope, target, block, new RubyArray(args)); | ||
| } | ||
|
|
||
| private static bool IsKernelBinding(object target) { | ||
| var method = _context.ResolveMethod(target, "binding", VisibilityContext.AllVisible).Info; | ||
| return method != null && method.DeclaringModule == _context.KernelModule; | ||
| } | ||
|
|
||
| private static Proc TakePassedBlock() { | ||
| var block = _passedBlock; | ||
| _passedBlock = null; | ||
|
|
@@ -531,9 +544,16 @@ internal static void rb_iter_break() { | |
|
|
||
| internal static void rb_iter_break_value(VALUE val) { | ||
| if (_cBlockDepth == 0) { | ||
| // a break out of a Ruby block from C called inside it: IronRuby's break needs the | ||
| // block's own frame, which a C function is not given | ||
| throw RubyExceptions.CreateNotImplementedError("rb_iter_break outside a block written in C is not implemented by IronRuby's C API yet"); | ||
| // called from a Ruby block: break out of the innermost one around the call, as a | ||
| // break in eval'd code does (CRuby's rb_iter_break unwinds to the block's caller) | ||
| RubyBlockScope blockScope; | ||
| RubyMethodScope methodScope; | ||
| (_frame?.Scope ?? _context.EmptyScope).GetInnerMostBlockOrMethodScope(out blockScope, out methodScope); | ||
| if (blockScope == null) { | ||
| throw new LocalJumpError("break from proc-closure", "break", FromValue(val)); | ||
| } | ||
| var proc = blockScope.BlockFlowControl.Proc; | ||
| throw new EvalUnwinder(BlockReturnReason.Break, proc.Converter, proc.Kind, FromValue(val)); | ||
| } | ||
| throw new CIterBreak(FromValue(val)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synchronize arguments for arity -2 methods too.
If an arity -2 C method sets
FL_FREEZEon an object extracted from its argument array, this loop never runs. Onlyselfis synchronized, so the original argument remains mutable in Ruby.Retain and synchronize the argument handles for both calling conventions. Keep the array calling convention unchanged.
Synchronize C-side freeze flags on exceptional exits.
When a C method raises,
InvokeMethodskips the post-callSyncRawFreezecalls for both the arguments andself. A freeze that the C code wrote before raising is then lost on the managed side, and the Ruby rescue handler sees a mutable object. Run the argument andselfreconciliation infinallyblocks so that it runs on both normal and exceptional exits. The original exception still propagates.Suggested fix