Project

General

Profile

Actions

Feature #10195

closed

Alternative to rb_proc_new that provides access to self, super and passed block

Added by cstrahan (Charles Strahan) over 9 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:64713]

Description

I'm developing a Haskell binding to the Ruby C API. Unfortunately, rb_proc_new
does not provide any means of accessing super, self and/or any passed block. A
better alternative to rb_proc_new would make it possible to create procs from
C/Haskell/etc that can access self/super/&block.

I'm currently hacking around this lacking in the C API by creating a closure
from the Ruby side that closes over self et al - a trampoline of sorts:

  rupee_proc_constructor_with_super = rb_eval_string_protect(
      "Proc.new {|callable|\n"
      "  su = if defined?(super)\n"
      "         Proc.new {|*args,&blk| super(*args,&blk) }\n"
      "       else\n"
      "         nil\n"
      "       end\n"
      "  Proc.new {|*args,&blk|\n"
      "    callable.call(self, su, *args, &blk)\n"
      "  }\n"
      "}",
      &status);

From the Haskell side, I then pass in the callable' object, where callable#call`
is implemented in Haskell. This is pretty clunky/slow, and also creates
unintuitive behavior from the Haskell side. It would be ideal for the C API to
support this natively.

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r48349.


test_bmethod.rb: super in bmethod test

  • test/-ext-/proc/test_bmethod.rb (test_super_in_bmethod): super
    in bmethod test for [Feature #10195].

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Closed to Open

Fixed a bug that bound proc method couldn't call rb_call_super().

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Closed

Applied in changeset r48350.


test_bmethod.rb: block in bmethod test

  • test/-ext-/proc/test_bmethod.rb (test_super_in_bmethod): block
    in bmethod test for [Feature #10195].

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Description updated (diff)
  • Status changed from Closed to Open

Passed block is passed as the fifth argument, as the test in r48350.

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Closed

Applied in changeset r48461.


ext/-test-/proc/super.c: rename

  • ext/-test-/proc/super.c: renamed the file and maker method.
    [Feature #10195]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0