ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:25501] [Bug #2069] Segfault in rb_enc_associate()
@ 2009-09-09 15:25 Jiri Zajpt
  2009-09-11  2:08 ` [ruby-core:25526] " Nobuyoshi Nakada
  0 siblings, 1 reply; 2+ messages in thread
From: Jiri Zajpt @ 2009-09-09 15:25 UTC (permalink / raw
  To: ruby-core

Bug #2069: Segfault in rb_enc_associate()
http://redmine.ruby-lang.org/issues/show/2069

Author: Jiri Zajpt
Status: Open, Priority: High
ruby -v: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10] 

I am having problem with using mysql-ruby driver on Snow Leopard. It segfaults in rb_enc_associate() used by rb_external_str_new_with_enc() function, so I came up with following short example (it also segfaults):

example source code ---------------------------------------------------------------------

#include <ruby.h>

void
Init_jzexp()
{
    const char* c_str = "test";
    VALUE string = rb_external_str_new_with_enc(c_str, strlen(c_str), rb_utf8_encoding());
}

- example source code -------------------------------------------------------------------


gdb output ---------------------------------------------------------------------

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000301f98
0x0000000100006a9b in rb_enc_associate ()
(gdb) where
#0  0x0000000100006a9b in rb_enc_associate ()
#1  0x00000001000ce236 in rb_external_str_new_with_enc ()
#2  0x0000000100004654 in dln_load ()
#3  0x00000001000fcba4 in rb_vm_call_cfunc ()
#4  0x00000001000309c3 in rb_require_safe ()
#5  0x00000001000fca01 in vm_call_cfunc ()
#6  0x00000001000fe2b0 in vm_call_method ()
#7  0x00000001000ff1ec in vm_exec_core ()
#8  0x00000001001043fe in vm_exec ()
#9  0x0000000100104540 in rb_iseq_eval_main ()
#10 0x000000010002df02 in ruby_exec_node ()
#11 0x000000010002f434 in ruby_run_node ()
#12 0x0000000100000ecf in main ()

- gdb output -------------------------------------------------------------------


----------------------------------------
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:25526] Re: [Bug #2069] Segfault in rb_enc_associate()
  2009-09-09 15:25 [ruby-core:25501] [Bug #2069] Segfault in rb_enc_associate() Jiri Zajpt
@ 2009-09-11  2:08 ` Nobuyoshi Nakada
  0 siblings, 0 replies; 2+ messages in thread
From: Nobuyoshi Nakada @ 2009-09-11  2:08 UTC (permalink / raw
  To: ruby-core

Hi,

At Thu, 10 Sep 2009 00:25:54 +0900,
Jiri Zajpt wrote in [ruby-core:25501]:
> ruby -v: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10] 

On darwin10, uname reports i386 but real default target is
x86_64.

> I am having problem with using mysql-ruby driver on Snow
> Leopard. It segfaults in rb_enc_associate() used by
> rb_external_str_new_with_enc() function, so I came up with
> following short example (it also segfaults):

It's a bug of that driver.

> example source code ---------------------------------------------------------------------
> 
> #include <ruby.h>
#include <ruby/encoding.h>

> void
> Init_jzexp()
> {
>     const char* c_str = "test";
>     VALUE string = rb_external_str_new_with_enc(c_str, strlen(c_str), rb_utf8_encoding());

You should have got warning messages here. 

rb_utf8_encoding() returns the pointer to utf-8 rb_encoding,
but undeclared functions are counted as int, and int is smaller
than pointer on x86_64.  Therefore only lower 32bit of the
pointer is used and extended to 64bit, and results a wrong
value.

-- 
Nobu Nakada

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-11  2:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-09 15:25 [ruby-core:25501] [Bug #2069] Segfault in rb_enc_associate() Jiri Zajpt
2009-09-11  2:08 ` [ruby-core:25526] " Nobuyoshi Nakada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).