0

I am using many of the array methods found in array.c of the ruby codebase, but when trying to call

VALUE rIntersection = rb_ary_and(rAry1, rAry2); 

I got this error:

dyld: lazy symbol binding failed: Symbol not found: _rb_ary_and
  Referenced from: ./ext/ev/counters.bundle
  Expected in: flat namespace

In other areas of my code I am using rb_ary_sort_bang, rb_ary_clear, rb_ary_reverse, etc etc. So I'm not sure why rb_ary_and is any different.

Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114

2 Answers2

2

Have a look at http://www.ruby-doc.org/doxygen/1.8.4/array_8c-source.html (Line 2666)

There you can see that the method rb_ary_and is declared static. This means that it is only visible inside of array.c.

phlogratos
  • 13,234
  • 1
  • 32
  • 37
  • Is it considered bad form to just copy the array.c file into your project, and change the definitions to not being static? – Jeremy Smith Jul 02 '11 at 17:04
  • @Jeremy Smith: If you notice on line 3042 of the same file, the function is used when the `&` method is invoked on the array. Why not try calling that method instead? – Jeremy Jul 02 '11 at 17:17
  • @Jeremy: Yes, that would be bad form and possibly a copyright problem, it would also tie you a specific version of Ruby as the array internals are likely to change. Instead, just call the methods using the standard API. Using the standard API also means that you should be able to work with subclasses that override `&`. – mu is too short Jul 02 '11 at 17:54
  • rAry1 & rAry2 doesn't work in C. So how else would I call that method within C? – Jeremy Smith Jul 02 '11 at 18:58
1

Untested, but I would assume this would work:

rb_funcall( rAry1, rb_intern("&"), 1, rAry2 )

thomthom
  • 2,854
  • 1
  • 23
  • 53