aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-03 11:23:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-03 11:23:48 +0000
commit9e3e0ca3fe5dbfb611445f266f30f72bc06fe3de (patch)
tree400a45f54d2cb820174d382c49d0ce4f624d99e3
parente33b7f338158ec83f4817bbb4c91248ed2b13b2d (diff)
downloadruby-9e3e0ca3fe5dbfb611445f266f30f72bc06fe3de.tar.gz
* lib/mkmf.rb (convertible_int): define printf format prefix too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--lib/mkmf.rb18
-rw-r--r--test/mkmf/test_convertible.rb6
3 files changed, 19 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 223caf31ad..236fe4c48f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
-Fri Dec 3 19:53:50 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 3 20:23:31 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/mkmf.rb (convertible_int): define printf format prefix too.
* lib/mkmf.rb (convertible_int): detect convertible integer type.
port RUBY_REPLACE_INT from configure.in.
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 5a12ed2acf..4d843b67d7 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -1162,18 +1162,18 @@ end
# compiler using the +type+ name, in uppercase.
#
# * 'TYPEOF_', followed by the +type+ name, followed by '=X' where 'X'
-# is the found _convertible_ type name.
-# * 'TYP2NUM' and 'NUM2TYP, where 'TYP' is the +type+ name in uppercase sans '_t'
-# suffix, followed by '=X' where 'X' is the macro name to convert
-# +type+ to +Integer+ object, and vice versa.
+# is the found _convertible_ type name. * 'TYP2NUM' and 'NUM2TYP,
+# where 'TYP' is the +type+ name in uppercase with replacing '_t'
+# suffix with 'T', followed by '=X' where 'X' is the macro name to
+# convert +type+ to +Integer+ object, and vice versa.
#
# For example, if foobar_t is defined as unsigned long, then
# convertible_int("foobar_t") would return "unsigned long", and define
# macros:
#
# #define TYPEOF_FOOBAR_T unsigned long
-# #define FOOBAR2NUM ULONG2NUM
-# #define NUM2FOOBAR NUM2ULONG
+# #define FOOBART2NUM ULONG2NUM
+# #define NUM2FOOBART NUM2ULONG
def convertible_int(type, headers = nil, opts = nil, &b)
type, macname = *type
checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
@@ -1188,10 +1188,12 @@ def convertible_int(type, headers = nil, opts = nil, &b)
try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, &b)
}
if compat
- macname ||= type.chomp("_t").tr_cpp
- conv = (u ? "U" : "") + (compat == "long long" ? "LL" : compat.upcase)
+ macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
+ conv = (compat == "long long" ? "LL" : compat.upcase)
compat = "#{u}#{compat}"
$defs.push(format("-DTYPEOF_%s=%s", type.tr_cpp, compat.quote))
+ $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
+ conv = (u ? "U" : "") + conv
$defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
$defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
compat
diff --git a/test/mkmf/test_convertible.rb b/test/mkmf/test_convertible.rb
index e8cc280eeb..82189ff100 100644
--- a/test/mkmf/test_convertible.rb
+++ b/test/mkmf/test_convertible.rb
@@ -17,8 +17,14 @@ class TestMkmf
open("confdefs.h", "w") {|f|
f.puts "typedef #{signed}#{type} test1_t;"
}
+ $defs.clear
assert_equal((prefix || signed)+type,
mkmf {convertible_int("test1_t", "confdefs.h")})
+ (u = signed[/^u/]) and u.upcase!
+ assert_includes($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote)
+ assert_includes($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX")
+ assert_includes($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM")
+ assert_includes($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}")
end
end
end