str = ARGV[0] || ""
str_dup = str.dup()
require 'gtk’
style = Gtk::Style.new()
style.font.string_width(str)
style.font.string_width(str_dup)
[sky@wizard build]# ./ruby /tmp/bla.rb '‘
Gdk-CRITICAL **: file gdkfont.c: line 319 (gdk_string_width):
assertion `string != NULL’ failed.
[sky@wizard build]# ./ruby -w /tmp/bla.rb ‘’
/tmp/bla.rb:6: [BUG] Segmentation fault
ruby 1.8.0 (2002-12-28) [i386-freebsd4]
Abort trap (core dumped)
But…
[sky@wizard build]# ./ruby -w /tmp/bla.rb
[sky@wizard build]# ./ruby /tmp/bla.rb
looks like bad interaction between zero-length ARGV and
String::dup() (or incomplete String object setup/initialization?
or verbosity -w setup?)
Fix (perhaps just workaround?)
string.c , function str_alloc()
— string.c.orig Sun Dec 29 04:21:06 2002
+++ string.c Sun Dec 29 04:16:17 2002
@@ -45,8 +45,8 @@
OBJSETUP(str, klass, T_STRING);
str->ptr = 0;
- str->len = 0;
- str->aux.capa = 0;
-
str->len = -1;
-
str->aux.capa = -1;
return (VALUE)str;
}
[sky@wizard build]# ./ruby /tmp/bla.rb ‘’
[sky@wizard build]# ./ruby -w /tmp/bla.rb ‘’
[sky@wizard build]# ./ruby /tmp/bla.rb
[sky@wizard build]# ./ruby -w /tmp/bla.rb ‘’
all test runs fine.
Ariff Abdullah wrote:
str = ARGV[0] || “”
str_dup = str.dup()
require ‘gtk’
style = Gtk::Style.new()
style.font.string_width(str)
style.font.string_width(str_dup)
I ran this through my Linux box without any problems.
ruby 1.8.0 (2002-12-26) [i386-linux-gnu]
ruby-gtk-0.30-1
p.s. First time I’ve seen another Malaysian on the list… 
···
–
Wai-Sun “Squidster” Chia
Consulting & Integration
Linux/Unix/Web Developer Dude
“Just Another Ruby Miner”
Here is the poc:
poc.c :-
#include “ruby.h”
#include <stdio.h>
VALUE poC;
static VALUE
poc_run(self, str)
VALUE self, str;
{
const char *dummy = STR2CSTR(str);
if (dummy) {
printf(“OK : "%s"\n”, dummy);
} else {
printf(“Where am I ?!?!?!?\n”);
}
return self;
}
void
Init_poc()
{
poC = rb_define_class(“Poc”, rb_cObject);
rb_define_singleton_method(poC, “run”, poc_run, 1);
}
extconf.rb :-
require ‘mkmf’
create_makefile(“poc”)
and the poc_test.rb :-
require ‘poc’
a = ARGV[0] || ‘’
b = a.dup()
Poc.run(b)
and now…
[sky@wizard poc]# ./poc_test.rb
OK : “”
[sky@wizard poc]# ./poc_test.rb " "
OK : " "
[sky@wizard poc]# ./poc_test.rb “a”
OK : “a”
[sky@wizard poc]# ./poc_test.rb “”
./poc_test.rb:41: [BUG] Segmentation fault
ruby 1.8.0 (2002-12-28) [i386-freebsd4]
Abort trap (core dumped)
[root@wizard poc]#
str.len = 0 (string.c , str_alloc()) , str.ptr = 0 ?
···
nobu.nokada@softhome.net wrote:
Hi,
At Sun, 29 Dec 2002 05:21:43 +0900, > Ariff Abdullah wrote:
[sky@wizard build]# ./ruby /tmp/bla.rb ‘’
Gdk-CRITICAL **: file gdkfont.c: line 319 (gdk_string_width):
assertion `string != NULL’ failed.
Update ruby-gtk. In 1.8, extension libraries have to consider
the case RSTRING(string)->ptr is NULL.
dummy = StringValuePtr(str) !!!
/* obsolete API - use StringValuePtr() */
#define STR2CSTR(x) rb_str2cstr((VALUE)(x),0)
ah… now I get it…
thanks anyway…
Ariff Abdullah wrote:
···
Here is the poc:
poc.c :-
#include “ruby.h”
#include <stdio.h>
VALUE poC;
static VALUE
poc_run(self, str)
VALUE self, str;
{
const char *dummy = STR2CSTR(str);
if (dummy) {
printf(“OK : "%s"\n”, dummy);
} else {
printf(“Where am I ?!?!?!?\n”);
}
return self;
}
void
Init_poc()
{
poC = rb_define_class(“Poc”, rb_cObject);
rb_define_singleton_method(poC, “run”, poc_run, 1);
}
extconf.rb :-
require ‘mkmf’
create_makefile(“poc”)
and the poc_test.rb :-
require ‘poc’
a = ARGV[0] || ‘’
b = a.dup()
Poc.run(b)
and now…
[sky@wizard poc]# ./poc_test.rb
OK : “”
[sky@wizard poc]# ./poc_test.rb " "
OK : " "
[sky@wizard poc]# ./poc_test.rb “a”
OK : “a”
[sky@wizard poc]# ./poc_test.rb “”
./poc_test.rb:41: [BUG] Segmentation fault
ruby 1.8.0 (2002-12-28) [i386-freebsd4]
Abort trap (core dumped)
[root@wizard poc]#
str.len = 0 (string.c , str_alloc()) , str.ptr = 0 ?
nobu.nokada@softhome.net wrote:
Hi,
At Sun, 29 Dec 2002 05:21:43 +0900, >> Ariff Abdullah wrote:
[sky@wizard build]# ./ruby /tmp/bla.rb ‘’
Gdk-CRITICAL **: file gdkfont.c: line 319 (gdk_string_width):
assertion `string != NULL’ failed.
Update ruby-gtk. In 1.8, extension libraries have to consider
the case RSTRING(string)->ptr is NULL.
Here’s a SPEC file for building a RPM for ruby-dbi. Should work for most
RPM-based Linux distros…
ruby-dbi.spec (1.57 KB)
···
–
Wai-Sun “Squidster” Chia
Consulting & Integration
Linux/Unix/Web Developer Dude
“Just Another Ruby Miner”