зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
37db97c0e1
Коммит
bb6e6903ca
|
@ -1,4 +1,8 @@
|
|||
Sun Jan 17 14:18:01 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Sun Jan 17 14:23:23 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/iconv/iconv.c (iconv_convert): suppress a warning.
|
||||
|
||||
* lib/mkmf.rb (check_signedness): new method.
|
||||
|
||||
* lib/mkmf.rb (have_header, create_header): use String#tr_cpp.
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ conf = with_config("config-charset", enable_config("config-charset", conf))
|
|||
|
||||
if have_func("iconv", "iconv.h") or
|
||||
have_library("iconv", "iconv", "iconv.h")
|
||||
check_signedness("size_t")
|
||||
if checking_for("const of iconv() 2nd argument") do
|
||||
create_tmpsrc(cpp_include("iconv.h") + "---> iconv(cd,0,0,0,0) <---")
|
||||
src = xpopen(cpp_command("")) {|f|f.read}
|
||||
|
|
|
@ -464,7 +464,11 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
|
|||
errmsg[0] = 0;
|
||||
error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
|
||||
|
||||
if (0 <= outlen && outlen <= sizeof(buffer)) {
|
||||
if (
|
||||
#if SIGNEDNESS_OF_SIZE_T < 0
|
||||
0 <= outlen &&
|
||||
#endif
|
||||
outlen <= sizeof(buffer)) {
|
||||
outlen = sizeof(buffer) - outlen;
|
||||
if (NIL_P(error) || /* something converted */
|
||||
outlen > (size_t)(inptr - tmpstart) || /* input can't contain output */
|
||||
|
|
41
lib/mkmf.rb
41
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче