Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -8403,7 +8403,7 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
not_exact:
v = finish_exact_sum(n, r, v, i!=0);

if (init_is_float ? (--i, e = argv[0], true) : RB_FLOAT_TYPE_P(e)) {
if (init_is_float || RB_FLOAT_TYPE_P(e)) {
/*
* Kahan-Babuska balancing compensated summation algorithm
* See https://link.springer.com/article/10.1007/s00607-005-0139-x
Expand Down
5 changes: 5 additions & 0 deletions ext/objspace/objspace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ dump_object(VALUE obj, struct dump_config *dc)
case T_HASH:
dump_append(dc, ", \"size\":");
dump_append_sizet(dc, (size_t)RHASH_SIZE(obj));

if (RHASH_AR_TABLE_P(obj)) {
dump_append(dc, ", \"ar_table\":true");
}

if (FL_TEST(obj, RHASH_PROC_DEFAULT)) {
dump_append(dc, ", \"default\":");
dump_append_ref(dc, RHASH_IFNONE(obj));
Expand Down
65 changes: 45 additions & 20 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6226,23 +6226,28 @@ nogvl_truncate(void *ptr)
}

/*
* :markup: markdown
*
* call-seq:
* File.truncate(filepath, size) -> 0
* File.truncate(filepath, size) -> 0
*
* Adjusts the size of file +filepath+ to the given size; returns 0:
* Adjusts the size of file `filepath` to the given `size`:
*
* file = File.new('t.tmp', 'w+')
* file.write('0123456789')
* file.truncate(5)
* file.rewind
* file.read # => "01234"
* ```ruby
* filepath = '/tmp/t.tmp'
* File.write(filepath, '0123456789')
* File.read(filepath) # => "0123456789"
* File.truncate(filepath, 5)
* File.read(filepath) # => "01234"
* ```
*
* Pads on the right with null characters if necessary:
* Pads with null characters if necessary:
*
* file.truncate(10)
* file.rewind
* file.read # => "01234\u0000\u0000\u0000\u0000\u0000"
* file.close
* ```ruby
* File.truncate(filepath, 10)
* File.read(filepath) # => "01234\u0000\u0000\u0000\u0000\u0000"
* File.delete(filepath) # Clean up.
* ```
*
*/

Expand Down Expand Up @@ -6281,17 +6286,37 @@ nogvl_ftruncate(void *ptr)
}

/*
* :markup: markdown
*
* call-seq:
* file.truncate(integer) -> 0
* truncate(size) -> 0
*
* Truncates <i>file</i> to at most <i>integer</i> bytes. The file
* must be opened for writing. Not available on all platforms.
* Adjusts the size of `self` to the given `size`,
* regardless of the current [position](rdoc-ref:IO@Position);
* does not adjust the position:
*
* ```ruby
* filepath = '/tmp/t.tmp'
* file = File.new(filepath, 'w+')
* file.write('0123456789')
* file.truncate(5)
* file.pos # => 10
* file.rewind
* file.read # => "01234"
* ```
*
* Pads with null characters if necessary:
*
* ```ruby
* file.truncate(10)
* file.pos # => 5
* file.rewind
* file.read # => "01234\u0000\u0000\u0000\u0000\u0000"
* # Clean up.
* file.close
* File.delete(filepath)
* ```
*
* f = File.new("out", "w")
* f.syswrite("1234567890") #=> 10
* f.truncate(5) #=> 0
* f.close() #=> nil
* File.size("out") #=> 5
*/

static VALUE
Expand Down
1 change: 0 additions & 1 deletion gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,6 @@ gc_aligned_malloc(size_t alignment, size_t size)
#if defined __MINGW32__
res = __mingw_aligned_malloc(size, alignment);
#elif defined _WIN32
void *_aligned_malloc(size_t, size_t);
res = _aligned_malloc(size, alignment);
#elif defined(HAVE_POSIX_MEMALIGN)
if (posix_memalign(&res, alignment, size) != 0) {
Expand Down
6 changes: 3 additions & 3 deletions include/ruby/internal/attr/constexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L)

#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00)
#elif RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1

#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L)
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/internal/compiler_is/msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#elif RBIMPL_COMPILER_IS(Intel)
# define RBIMPL_COMPILER_IS_MSVC 0

#elif _MSC_VER >= 1400
#elif _MSC_VER >= 1915
# define RBIMPL_COMPILER_IS_MSVC 1
# /* _MSC_FULL_VER = XXYYZZZZZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 10000000)
Expand Down
12 changes: 6 additions & 6 deletions include/ruby/internal/has/cpp_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
# * 2019. However, they do have attributes since 2015 or so. */
# /* https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809
# define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809
# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309
# define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603
# define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603
# define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603

#elif RBIMPL_COMPILER_BEFORE(Clang, 3, 6, 0)
# /* Clang 3.6.0 introduced __has_cpp_attribute. Prior to that following
Expand Down
23 changes: 11 additions & 12 deletions include/ruby/internal/has/declspec_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_DECLSPEC_ATTRIBUTE.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/compiler_is.h"

/** Wraps (or simulates) `__has_declspec_attribute`. */
#if defined(__has_declspec_attribute)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) __has_declspec_attribute(_)
#else
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) (RBIMPL_HAS_DECLSPEC_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_align RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_empty_bases RBIMPL_COMPILER_SINCE(MSVC,19, 0, 23918)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noalias RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(MSVC,11, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_restrict RBIMPL_COMPILER_SINCE(MSVC,14, 0, 0)
# /* Note that "8, 0, 0" might be inaccurate. */
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_align RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_deprecated RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllexport RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllimport RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_empty_bases RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noalias RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noinline RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noreturn RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_restrict RBIMPL_COMPILER_IS(MSVC)
# if ! defined(__cplusplus)
# /* Clang has this in both C/C++, but MSVC has this in C++ only.*/
# undef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow
Expand Down
36 changes: 1 addition & 35 deletions include/ruby/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,7 @@ extern "C++" { /* template without extern "C++" */
#endif
#include <io.h>
#include <malloc.h>
#if defined __MINGW32__
# include <stdint.h>
#else
# if !defined(_INTPTR_T_DEFINED)
# ifdef _WIN64
typedef __int64 intptr_t;
# else
typedef int intptr_t;
# endif
# define _INTPTR_T_DEFINED
# endif
# if !defined(INTPTR_MAX)
# ifdef _WIN64
# define INTPTR_MAX 9223372036854775807I64
# else
# define INTPTR_MAX 2147483647
# endif
# define INTPTR_MIN (-INTPTR_MAX-1)
# endif
# if !defined(_UINTPTR_T_DEFINED)
# ifdef _WIN64
typedef unsigned __int64 uintptr_t;
# else
typedef unsigned int uintptr_t;
# endif
# define _UINTPTR_T_DEFINED
# endif
# if !defined(UINTPTR_MAX)
# ifdef _WIN64
# define UINTPTR_MAX 18446744073709551615UI64
# else
# define UINTPTR_MAX 4294967295U
# endif
# endif
#endif
#include <stdint.h>
#ifndef __MINGW32__
# define mode_t int
#endif
Expand Down
2 changes: 1 addition & 1 deletion internal/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "ruby/internal/config.h"
#include <limits.h> /* for CHAR_BITS */
#include <stdint.h> /* for uintptr_t */
#include "internal/compilers.h" /* for MSC_VERSION_SINCE */
#include "internal/compilers.h" /* for __has_builtin */

#ifdef _MSC_VER
# include <stdlib.h> /* for _byteswap_uint64 */
Expand Down
3 changes: 0 additions & 3 deletions internal/compilers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "ruby/internal/has/warning.h"
#include "ruby/backward/2/gcc_version_since.h"

#define MSC_VERSION_SINCE(_) RBIMPL_COMPILER_SINCE(MSVC, (_) / 100, (_) % 100, 0)
#define MSC_VERSION_BEFORE(_) RBIMPL_COMPILER_BEFORE(MSVC, (_) / 100, (_) % 100, 0)

#ifndef __has_attribute
# define __has_attribute(...) RBIMPL_HAS_ATTRIBUTE(__VA_ARGS__)
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def call(object_id)
$stderr.puts "removing #{@path}..." if $DEBUG
begin
File.unlink(@path)
rescue Errno::ENOENT
rescue Errno::ENOENT, Errno::EACCES
end
$stderr.puts "done" if $DEBUG
end
Expand Down
2 changes: 1 addition & 1 deletion parser_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "ruby/internal/config.h"
#include <limits.h> /* for CHAR_BITS */
#include <stdint.h> /* for uintptr_t */
#include "internal/compilers.h" /* for MSC_VERSION_SINCE */
#include "internal/compilers.h" /* for __has_builtin */

#ifdef _MSC_VER
# include <stdlib.h> /* for _byteswap_uint64 */
Expand Down
15 changes: 7 additions & 8 deletions pathname_builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1950,23 +1950,22 @@ def make_symlink(old) File.symlink(old, @path) end
# call-seq:
# truncate(size) -> 0
#
# Adjusts the size of file at the path in `self` to the given `size`;
# returns `0`:
# Adjusts the size of file at the path in `self` to the given `size`:
#
# ```ruby
# pn = Pathname('/tmp/t.tmp')
# pn.write('0123456789')
# pn.size # => 10
# pn.read # => "0123456789"
# pn.truncate(5)
# pn.size # => 5
# pn.read # => "01234"
# pn.read # => "01234"
# ```
#
# Pads on the right with null characters if necessary:
# Pads with null characters if necessary:
#
# ```ruby
# pn.truncate(10)
# pn.size # => 10
# pn.read # => "01234\u0000\u0000\u0000\u0000\u0000"
# pn.read # => "01234\u0000\u0000\u0000\u0000\u0000"
# pn.delete # Clean up.
# ```
#
def truncate(length) File.truncate(@path, length) end
Expand Down
12 changes: 0 additions & 12 deletions regint.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,6 @@
# include <stdio.h>
#endif

#ifndef PRIdPTR
# ifdef _WIN64
# define PRIdPTR "I64d"
# define PRIuPTR "I64u"
# define PRIxPTR "I64x"
# else
# define PRIdPTR "ld"
# define PRIuPTR "lu"
# define PRIxPTR "lx"
# endif
#endif

#ifndef PRIdPTRDIFF
# define PRIdPTRDIFF PRIdPTR
#endif
Expand Down
11 changes: 11 additions & 0 deletions test/objspace/test_objspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,17 @@ def test_dump_array
assert_not_include(info, '"embedded":true')
end

def test_dump_hash
ar_hash = {}
info = ObjectSpace.dump(ar_hash)
assert_include(info, '"ar_table":true')

st_hash = {}
9.times { |i| st_hash[i] = i }
info = ObjectSpace.dump(st_hash)
assert_not_include(info, '"ar_table":true')
end

def test_dump_object
klass = Class.new

Expand Down
3 changes: 2 additions & 1 deletion test/resolv/test_win32_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'test/unit'
require 'resolv'

if defined?(Win32::Resolv)
# JRuby loads its bundled win32/resolv, which lacks the registry access of the extension.
if defined?(Win32::Resolv) && Win32::Resolv.respond_to?(:tcpip_params, true)
class TestWin32Config < Test::Unit::TestCase
def test_get_item_property_string
# Test reading a string registry value
Expand Down
18 changes: 18 additions & 0 deletions test/ruby/test_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3752,6 +3752,11 @@ def test_sum
assert_float_equal(8.5, [3.5, 5].sum)
assert_float_equal(10.5, [2, 8.5].sum)
assert_float_equal(1_000 * 0.1, Array.new(1_000, 0.1).sum(0.0))

# Init with a float, but start with some fixnums in the array.
# Tests compensated summation fallthrough in array.c
assert_float_equal(5.0, [1, 1, 1.0, 1.0, 1.0].sum(0.0))

assert_float_equal((FIXNUM_MAX+1).to_f, [FIXNUM_MAX, 1, 0.0].sum)
assert_float_equal((FIXNUM_MAX+1).to_f, [0.0, FIXNUM_MAX+1].sum)

Expand All @@ -3769,6 +3774,19 @@ def test_sum
assert_float_equal(12.0, ary.sum {|x| yielded << x; x * 2 })
assert_equal(ary, yielded)

yielded_ctr = 0
result = %w[a b].sum(0) do
yielded_ctr += 1
end
assert_equal(result, 3)

yielded_ctr = 0.0
result = %w[a b].sum(0.0) do
yielded_ctr += 1
yielded_ctr.to_f
end
assert_equal(result, 3.0)

assert_raise(TypeError) { [Object.new].sum }

large_number = 100000000
Expand Down
Loading