diff options
-rw-r--r-- | array.c | 2 | ||||
-rw-r--r-- | bignum.c | 4 | ||||
-rw-r--r-- | gc.c | 2 | ||||
-rw-r--r-- | internal/numeric.h | 8 | ||||
-rw-r--r-- | numeric.c | 2 | ||||
-rw-r--r-- | regcomp.c | 2 | ||||
-rw-r--r-- | regenc.h | 7 |
7 files changed, 15 insertions, 12 deletions
@@ -1389,7 +1389,7 @@ ary_make_partial_step(VALUE ary, VALUE klass, long offset, long len, long step) } long ustep = (step < 0) ? -step : step; - len = (len + ustep - 1) / ustep; + len = roomof(len, ustep); long i; long j = offset + ((step > 0) ? 0 : (orig_len - 1)); @@ -977,7 +977,7 @@ integer_unpack_num_bdigits_small(size_t numwords, size_t wordsize, size_t nails, { /* nlp_bits stands for number of leading padding bits */ size_t num_bits = (wordsize * CHAR_BIT - nails) * numwords; - size_t num_bdigits = (num_bits + BITSPERDIG - 1) / BITSPERDIG; + size_t num_bdigits = roomof(num_bits, BITSPERDIG); *nlp_bits_ret = (int)(num_bdigits * BITSPERDIG - num_bits); return num_bdigits; } @@ -987,7 +987,7 @@ integer_unpack_num_bdigits_generic(size_t numwords, size_t wordsize, size_t nail { /* BITSPERDIG = SIZEOF_BDIGIT * CHAR_BIT */ /* num_bits = (wordsize * CHAR_BIT - nails) * numwords */ - /* num_bdigits = (num_bits + BITSPERDIG - 1) / BITSPERDIG */ + /* num_bdigits = roomof(num_bits, BITSPERDIG) */ /* num_bits = CHAR_BIT * (wordsize * numwords) - nails * numwords = CHAR_BIT * num_bytes1 - nails * numwords */ size_t num_bytes1 = wordsize * numwords; @@ -870,7 +870,7 @@ typedef struct rb_objspace { #define BASE_SLOT_SIZE sizeof(RVALUE) -#define CEILDIV(i, mod) (((i) + (mod) - 1)/(mod)) +#define CEILDIV(i, mod) roomof(i, mod) enum { HEAP_PAGE_ALIGN = (1UL << HEAP_PAGE_ALIGN_LOG), HEAP_PAGE_ALIGN_MASK = (~(~0UL << HEAP_PAGE_ALIGN_LOG)), diff --git a/internal/numeric.h b/internal/numeric.h index 19069cb3bc..89bc54b307 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -35,12 +35,16 @@ enum ruby_num_rounding_mode { RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT, }; +/* same as internal.h */ +#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) +#define roomof(x, y) (((x) + (y) - 1) / (y)) +#define type_roomof(x, y) roomof(sizeof(x), sizeof(y)) + #if SIZEOF_DOUBLE <= SIZEOF_VALUE typedef double rb_float_value_type; #else typedef struct { - VALUE values[(SIZEOF_DOUBLE + SIZEOF_VALUE - 1) / SIZEOF_VALUE]; - /* roomof() needs internal.h, and the order of some macros may matter */ + VALUE values[roomof(SIZEOF_DOUBLE, SIZEOF_VALUE)]; } rb_float_value_type; #endif @@ -1055,7 +1055,7 @@ flo_to_s(VALUE flt) { enum {decimal_mant = DBL_MANT_DIG-DBL_DIG}; enum {float_dig = DBL_DIG+1}; - char buf[float_dig + (decimal_mant + CHAR_BIT - 1) / CHAR_BIT + 10]; + char buf[float_dig + roomof(decimal_mant, CHAR_BIT) + 10]; double value = RFLOAT_VALUE(flt); VALUE s; char *p, *e; @@ -341,7 +341,7 @@ static int select_str_opcode(int mb_len, OnigDistance byte_len, int ignore_case) { int op; - OnigDistance str_len = (byte_len + mb_len - 1) / mb_len; + OnigDistance str_len = roomof(byte_len, mb_len); if (ignore_case) { switch (str_len) { @@ -125,10 +125,9 @@ typedef struct { #define POSIX_BRACKET_ENTRY_INIT(name, ctype) \ {(short int )(sizeof(name) - 1), name, (ctype)} -#ifndef numberof -# define numberof(array) (int )(sizeof(array) / sizeof((array)[0])) -#endif - +#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) +#define roomof(x, y) (((x) + (y) - 1) / (y)) +#define type_roomof(x, y) roomof(sizeof(x), sizeof(y)) #define USE_CRNL_AS_LINE_TERMINATOR #define USE_UNICODE_PROPERTIES |