diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-17 05:23:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-17 05:23:25 +0000 |
commit | bb6e6903ca7ab0d833c2c243287be6123c8b15bd (patch) | |
tree | 39c12c52164ca7fc6ba474a221f01dd50ffa5e3d /lib | |
parent | 37db97c0e12b39c912d37b6adccbcf1112ce75ba (diff) | |
download | ruby-bb6e6903ca7ab0d833c2c243287be6123c8b15bd.tar.gz |
* ext/iconv/iconv.c (iconv_convert): suppress a warning.
* lib/mkmf.rb (check_signedness): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mkmf.rb | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 656c47314b..cccaf371d4 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -985,6 +985,11 @@ def have_const(const, headers = nil, opt = "", &b) end end +STRING_OR_FAILED_FORMAT = "%s" +def STRING_OR_FAILED_FORMAT.%(x) + x ? super : "failed" +end + # Returns the size of the given +type+. You may optionally specify additional # +headers+ to search in for the +type+. # @@ -1002,10 +1007,7 @@ def check_sizeof(type, headers = nil, opts = "", &b) prelude << "static rbcv_typedef_ *rbcv_ptr_;\n" prelude = [prelude] expr = "sizeof((*rbcv_ptr_)#{"." << member if member})" - fmt = "%s" - def fmt.%(x) - x ? super : "failed" - end + fmt = STRING_OR_FAILED_FORMAT checking_for checking_message("size of #{type}", headers), fmt do if UNIVERSAL_INTS.include?(type) type @@ -1021,6 +1023,37 @@ def check_sizeof(type, headers = nil, opts = "", &b) end end +# Returns the signedness of the given +type+. You may optionally +# specify additional +headers+ to search in for the +type+. +# +# If the +type+ is found and is a numeric type, a macro is passed as a +# preprocessor constant to the compiler using the +type+ name, in +# uppercase, prepended with 'SIGNEDNESS_OF_', followed by the +type+ +# name, followed by '=X' where 'X' is positive integer if the +type+ is +# unsigned, or negative integer if the +type+ is signed. +# +# For example, if size_t is defined as unsigned, then +# check_signedness('size_t') would returned +1 and the +# SIGNEDNESS_OF_SIZE_T=+1 preprocessor macro would be passed to the +# compiler, and SIGNEDNESS_OF_INT=-1 if check_signedness('int') is +# done. +# +def check_signedness(type, headers = nil) + signed = nil + checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do + if try_static_assert("(#{type})-1 < 0") + signed = -1 + elsif try_static_assert("(#{type})-1 > 0") + signed = +1 + else + next nil + end + $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed]) + signed < 0 ? "signed" : "unsigned" + end + signed +end + # :stopdoc: # Used internally by the what_type? method to determine if +type+ is a scalar |