# 1.9.2 breaks ncurses (STR2CSTR) - pls help

**URL:** <https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655>\
**Category:** Ruby\
**Created:** [August 21, 2010, 8:17am UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655 "2010-08-21T08:17:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 8:17am UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/1 "2010-08-21T08:17:29Z")

</div>

I am on Snow Leopard, installed 1.9.2 using rvm.

Here is the runtime error I get from ncurses-0.9.1:

dyld: lazy symbol binding failed: Symbol not found: \_STR2CSTR  
Referenced from:  
/Users/rahul/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site\_ruby/1.9.1/x86\_64-darwin10/ncurses.bundle  
Expected in: flat namespace dyld:  
Symbol not found: \_STR2CSTR  
Referenced from:  
/Users/rahul/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site\_ruby/1.9.1/x86\_64-darwin10/ncurses.bundle  
Expected in: flat namespace  
Trace/BPT trap

Someone told me that STR2CSTR has been removed. Could someone tell me  
what I should replace STR2CSTR with in the ncurses code, or what to do.  
I am not familiar with the Ruby-C interface, and would appreciate some  
pointers.

thanks,  
rahul  
p.s. I am using an older version of ncurses, since i can’t get 1.2.4 to  
compile or run on Snow Leopard.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 8:35am UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/2 "2010-08-21T08:35:44Z")

</div>

---- On Sat, 21 Aug 2010 08:17:32 +0200 R… Kumar 1.9.1 OSX wrote ----

> Someone told me that STR2CSTR has been removed. Could someone tell me  
> what I should replace STR2CSTR with in the ncurses code, or what to do.  
> I am not familiar with the Ruby-C interface, and would appreciate some  
> pointers.

Actually STR2CSTR was marked as obsolete in 1.8 and removed in 1.9.1.

ruby.h:

/\* obsolete API - use StringValue() _/  
char rb\_str2cstr \_((VALUE,long));  
/_ obsolete API - use StringValuePtr() \*/  
#define STR2CSTR(x) rb\_str2cstr((VALUE)(x),0)

Basically just replace STR2CSTR by StringValuePtr or define this macro.

Wbr

Christoph

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 11:46am UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/3 "2010-08-21T11:46:43Z")

</div>

Christoph K. wrote:

> ---- On Sat, 21 Aug 2010 08:17:32 +0200 R… Kumar 1.9.1 OSX wrote ----
> 
> > Someone told me that STR2CSTR has been removed. Could someone tell me  
> > what I should replace STR2CSTR with in the ncurses code, or what to do.  
> > I am not familiar with the Ruby-C interface, and would appreciate some  
> > pointers.
> 
> Actually STR2CSTR was marked as obsolete in 1.8 and removed in 1.9.1.
> 
> ruby.h:
> 
> /\* obsolete API - use StringValue() _/  
> char rb\_str2cstr \_((VALUE,long));  
> /_ obsolete API - use StringValuePtr() \*/  
> #define STR2CSTR(x) rb\_str2cstr((VALUE)(x),0)
> 
> Basically just replace STR2CSTR by StringValuePtr or define this macro.
> 
> Wbr
> 
> Christoph

I’ve tried various combinations. I either get runtime errors relating to  
rb\_str2ctr or just make errors.

1. $ perl -p -i.b -e ‘s/STR2CSTR/StringValuePtr/g’ \*.c  
$ make

form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_typeâ€™:  
form\_wrap.c:626: error: lvalue required as unary â€˜&â€™ operand  
form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_foreâ€™:  
form\_wrap.c:698: warning: implicit conversion shortens 64-bit value into  
a 32-bit value  
form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_backâ€™:  
form\_wrap.c:712: warning: implicit conversion shortens 64-bit value into  
a 32-bit value  
form\_wrap.c: In function â€˜make\_argâ€™:  
form\_wrap.c:1134: warning: format not a string literal and no format  
arguments  
make: \*\*\* [form\_wrap.o] Error 1

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 12:10pm UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/4 "2010-08-21T12:10:50Z")

</div>

Christoph K. wrote:

> ---- On Sat, 21 Aug 2010 08:17:32 +0200 R… Kumar 1.9.1 OSX wrote ----
> 
> > Someone told me that STR2CSTR has been removed. Could someone tell me  
> > what I should replace STR2CSTR with in the ncurses code, or what to do.  
> > I am not familiar with the Ruby-C interface, and would appreciate some  
> > pointers.
> 
> Actually STR2CSTR was marked as obsolete in 1.8 and removed in 1.9.1.
> 
> ruby.h:
> 
> /\* obsolete API - use StringValue() _/  
> char rb\_str2cstr \_((VALUE,long));  
> /_ obsolete API - use StringValuePtr() \*/  
> #define STR2CSTR(x) rb\_str2cstr((VALUE)(x),0)
> 
> Basically just replace STR2CSTR by StringValuePtr or define this macro.
> 
> Wbr
> 
> Christoph

On a fresh copy I placed the above lines, in the ncurse\_wrap.h file.  
“make” worked, I created a gem and installed the gem. (I placed the  
lines above #include \<ruby.h\> else i get compilation errors.)

Upon execution of any sample I get: dyld: lazy symbol binding failed:  
Symbol not found: \_rb\_str2cstr

Perhaps, I am placing these lines in the wrong place. I tried placing in  
the .c file but i get the same run time error.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/5 "2010-08-21T13:39:29Z")

</div>

On Sat, Aug 21, 2010 at 7:10 PM, R… Kumar 1.9.1 OSX  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Christoph K. wrote:
> 
> > ---- On Sat, 21 Aug 2010 08:17:32 +0200 R… Kumar 1.9.1 OSX Â wrote ----
> > 
> > > Someone told me that STR2CSTR has been removed. Could someone tell me  
> > > what I should replace STR2CSTR with in the ncurses code, or what to do.  
> > > I am not familiar with the Ruby-C interface, and would appreciate some  
> > > pointers.

> **[GitHub - seanohalpin/ffi-ncurses: Interface to ncurses using Ruby FFI...](https://github.com/seanohalpin/ffi-ncurses)**
>
> Interface to ncurses using Ruby FFI (Foreign Function Interface) - GitHub - seanohalpin/ffi-ncurses: Interface to ncurses using Ruby FFI (Foreign Function Interface)

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 4:37pm UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/6 "2010-08-21T16:37:44Z")

</div>

Michael F. wrote:

> On Sat, Aug 21, 2010 at 7:10 PM, R… Kumar 1.9.1 OSX  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Christoph K. wrote:
> > 
> > > ---- On Sat, 21 Aug 2010 08:17:32 +0200 R… Kumar 1.9.1 OSX Â wrote ----
> > > 
> > > > Someone told me that STR2CSTR has been removed. Could someone tell me  
> > > > what I should replace STR2CSTR with in the ncurses code, or what to do.  
> > > > I am not familiar with the Ruby-C interface, and would appreciate some  
> > > > pointers.
> 
> [GitHub - seanohalpin/ffi-ncurses: Interface to ncurses using Ruby FFI (Foreign Function Interface)](http://github.com/seanohalpin/ffi-ncurses)

Is anything other than ncurses port required to be installed ?

I get:  
$ ruby example.rb

.rvm/gems/ruby-1.9.2-head/gems/ffi-0.6.3/lib/ffi/library.rb:61:in `block  
in ffi\_lib’: Could not open library ‘libncurses.so.5’:  
dlopen(libncurses.so.5, 5): image not found. Could not open library  
‘libncurses.so.5.dylib’: dlopen(libncurses.so.5.dylib, 5): image not  
found (LoadError)

$ mdfind -name ‘libncurses.’  
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/libncurses.5.4.dylib  
/usr/lib/libncurses.5.4.dylib  
/usr/lib/libncurses.5.dylib  
/opt/local/lib/libncurses.5.dylib  
/opt/local/lib/libncurses.a

$ port installed | grep ncurse  
ncurses @5.7\_0+darwin\_10 (active)  
ncursesw @5.7\_0+darwin\_10 (active)

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 7:37pm UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/7 "2010-08-21T19:37:06Z")

</div>

On Sat, Aug 21, 2010 at 11:37 PM, R… Kumar 1.9.1 OSX  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [GitHub - seanohalpin/ffi-ncurses: Interface to ncurses using Ruby FFI (Foreign Function Interface)](http://github.com/seanohalpin/ffi-ncurses)
> 
> Is anything other than ncurses port required to be installed ?

Seems like it’s a bit outdated, I fixed that for you:

> **[GitHub - manveru/ffi-ncurses: Interface to ncurses using Ruby FFI (Foreign...](https://github.com/manveru/ffi-ncurses)**
>
> Interface to ncurses using Ruby FFI (Foreign Function Interface) - GitHub - manveru/ffi-ncurses: Interface to ncurses using Ruby FFI (Foreign Function Interface)

Not sure if that works on OSX, but I’m hopeful 🙂

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 21, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/8 "2010-08-21T23:44:54Z")

</div>

R… Kumar 1.9.1 OSX wrote:

> I’ve tried various combinations. I either get runtime errors relating to  
> rb\_str2ctr or just make errors.
> 
> 1. $ perl -p -i.b -e ‘s/STR2CSTR/StringValuePtr/g’ \*.c  
> $ make
> 
> form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_typeâ€™:  
> form\_wrap.c:626: error: lvalue required as unary â€˜&â€™ operand  
> form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_foreâ€™:  
> form\_wrap.c:698: warning: implicit conversion shortens 64-bit value into  
> a 32-bit value  
> form\_wrap.c: In function â€˜rbncurs\_c\_set\_field\_backâ€™:  
> form\_wrap.c:712: warning: implicit conversion shortens 64-bit value into  
> a 32-bit value  
> form\_wrap.c: In function â€˜make\_argâ€™:  
> form\_wrap.c:1134: warning: format not a string literal and no format  
> arguments  
> make: \*\*\* [form\_wrap.o] Error 1

Unfortunately replacing STR2CSTR with StringValuePtr is not enough as  
outlined in  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/105048](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/105048). You  
have to make two additional changes:

## $ diff form\_wrap.c form\_wrap.c.b 626,627c626 \< VALUE tmp = rb\_ary\_entry(arg3, (long)i); \< list[i] = StringValuePtr(tmp);

> ```
> list[i] = STR2CSTR(rb_ary_entry(arg3, (long)i));
> 
> ```

…

and

## $ diff ncurses\_wrap.c ncurses\_wrap.c.b … 2244,2245d2243 \< VALUE tmp = rb\_funcall3(rb\_mKernel, rb\_intern(“sprintf”), argc-1, \< argv + 1); 2247c2245,2246 \< (VALUE)StringValuePtr(tmp));

> ```
> STR2CSTR(rb_funcall3(rb_mKernel, rb_intern("sprintf"), argc-1,
> argv + 1)));
> 
> ```

…

Then run

make  
make install

within the installed ncurses gem. After these changes I was able to run  
the 2 testcases test1.rb and test2.rb of rbcurse-1.1.3.

ruby test1.rb

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [August 22, 2010, 9:04am UTC](https://www.ruby-forum.com/t/1-9-2-breaks-ncurses-str2cstr-pls-help/193655/9 "2010-08-22T09:04:31Z")

</div>

Ralf Papenkordt wrote:

> ## $ diff ncurses\_wrap.c ncurses\_wrap.c.b … 2244,2245d2243 \< VALUE tmp = rb\_funcall3(rb\_mKernel, rb\_intern(“sprintf”), argc-1, \< argv + 1); 2247c2245,2246 \< (VALUE)StringValuePtr(tmp));
> 
> > ```
> > STR2CSTR(rb_funcall3(rb_mKernel, rb_intern("sprintf"), argc-1,
> > argv + 1)));
> > 
> > ```
> 
> …

Thanks a lot, Ralf. Working fine 🙂

I wish i could take over maintenance of this gem, but I know very basic  
C only.
