From: Charles Mills Date: 2004-05-20T14:58:58+09:00 Subject: mkmf.rb - check_sizeof() crashes my extconf.rb script. $ echo 'check_sizeof("short")' | ruby -r mkmf - checking size of short... 2 /usr/local/lib/ruby/1.8/mkmf.rb:570:in `check_sizeof': undefined local variable or method `r' for main:Object (NameError) from -:1 ------ ## Looking at the source, seems like size should be returned not r: def check_sizeof(type, header = nil, &b) expr = "sizeof(#{type})" m = "checking size of #{type}... " message "%s", m Logging::message "check_sizeof: %s--------------------\n", m if size = try_constant(expr, header, &b) $defs.push(format("-DSIZEOF_%s", type.upcase)) end message(a = size ? "#{size}\n" : "failed\n") Logging::message "-------------------- %s\n", a r end ------ Other problems with check_sizeof(): the line: $defs.push(format("-DSIZEOF_%s", type.upcase)) should probably be: $defs.push(format("-DSIZEOF_%s=%i", type.upcase, size)) or (taken from latest source) $defs.push(format("-DSIZEOF_%s=%i", type.upcase.tr_s("^A-Z0-9_", "_"), size)) ----- This leads to a problem with create_header() Looks like the regexp on line 619 /^-D(.*)(?:=(.*))?/ used to parse $defs should be /^-D([^=]+)(=(.*))?/ and line 620 changed to: hfile.print "#define #$1 #{$3 || 1}\n" from hfile.print "#define #$1 #{$2 || 1}\n" ---- using irb: > '-DSIZEOF_INT=4' =~ /^-D(.*)(?:=(.*))?/ # old regexp => 0 > puts $1, $2, $3 SIZEOF_INT=4 nil nil => nil > '-DSIZEOF_INT=4' =~ /^-D([^=]+)(=(.*))?/ # possible replacement => 0 > puts $1, $2, $3 SIZEOF_INT =4 4 => nil > '-DHAVE_STRING_H' =~ /^-D([^=]+)(=(.*))?/ # possible replacement => 0 > puts $1, $2, $3 HAVE_STRING_H nil nil => nil ------------ Charlie