Skip to content

Fiddle::Function fixes#2

Merged
headius merged 6 commits intoheadius:fiddle-fixesfrom
danini-the-panini:ds-fiddle-function-fixes
Mar 13, 2017
Merged

Fiddle::Function fixes#2
headius merged 6 commits intoheadius:fiddle-fixesfrom
danini-the-panini:ds-fiddle-function-fixes

Conversation

@danini-the-panini
Copy link
Copy Markdown

@danini-the-panini danini-the-panini commented Mar 12, 2017

Fixes jruby#4518

Convert pointer-type arguments to actual pointers when calling a Fiddle::Function.

Also, I added a clause to raise when attempting to pass an IO object to a Fiddle::Function. This is because, currently, this action causes a Segfault. Raising merely avoids this scenario for now. We will have to rectify this issue in the future, but currently this isn't causing any loss in functionality as far as I can tell.

I also implemented Fiddle::Pointer#-@ and Fiddle::Pointer#+@ because I noticed they were missing.

Daniel Smith added 4 commits March 12, 2017 12:10
Previous commit broke this functionality by only allowing Fiddle::Pointer types.
This should be supported in future. Currently, attempting to convert IO to pointer causes a Segfault. Raising to avoid this for now.
Daniel Smith added 2 commits March 12, 2017 13:59
Accidentally left them in in last commit
Previously, `Fiddle::Pointer`s passed to `Fiddle::Function#call` were actually being silently converted to `FFI::Pointer`s because `FFI::Function#call` calls `#to_ptr`, which coincidentally (or not) returns the underlying `FFI::Pointer`. I now convert these pointers explicitely and remove the `#to_ptr` method.
@headius headius merged commit 358e8d8 into headius:fiddle-fixes Mar 13, 2017
@danini-the-panini danini-the-panini deleted the ds-fiddle-function-fixes branch March 14, 2017 07:12
headius pushed a commit that referenced this pull request Nov 29, 2018
  1. lexically contained closures will return since it knows it is safe to do so (e.g. nonlocal -> local return conversion)
  2. other closures will copy to the return value of the method and jump to the end of the method

I believe #2 is wrong and it is not currently possible to hit with the limitations in what we will inline.  I still added it as it seemed like some code should be there to handle this scenario when/if we decide to support it.  I think the premise of what #2 does is right; but I do not see how we can guarantee where we jump to could possibly have the same variable in a return instr (or copy to some other significant variable).

For posterity, if I delete #1 and run the following script I feel this should still work but it doesn't:

```ruby
def try_fdopen()
  1.times do
    return :exit_closure
  end
  :exit_try_fdopen
end


def foo
  i = 0
  while i < 1000 do
    p try_fdopen
    i += 1
  end
end


foo
```
headius pushed a commit that referenced this pull request Sep 23, 2021
implement Enumerable#tally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants