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
25 changes: 15 additions & 10 deletions ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "ruby.h"
#include "ruby/encoding.h"
#include "ruby/util.h"

#ifndef HAVE_RB_LEN_T
typedef long rb_len_t;
#endif

#include <math.h>
#include <time.h>
#if defined(HAVE_SYS_TIME_H)
Expand Down Expand Up @@ -4109,7 +4114,7 @@ static VALUE
rt_complete_frags(VALUE klass, VALUE hash)
{
static VALUE tab = Qnil;
long e;
rb_len_t e;
VALUE k, a, d;

if (NIL_P(tab)) {
Expand Down Expand Up @@ -4208,7 +4213,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
k = a = Qnil;

{
long i, eno = 0;
rb_len_t i, eno = 0;
VALUE t = Qnil;

e = 0;
Expand All @@ -4219,7 +4224,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
a = RARRAY_AREF(x, 1);

{
long j, n = 0;
rb_len_t j, n = 0;

for (j = 0; j < RARRAY_LEN(a); j++)
if (!NIL_P(ref_hash0(RARRAY_AREF(a, j))))
Expand Down Expand Up @@ -4250,7 +4255,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
set_hash("yday", INT2FIX(1));
}
else if (k == sym("civil")) {
long i;
rb_len_t i;

for (i = 0; i < RARRAY_LEN(a); i++) {
VALUE e = RARRAY_AREF(a, i);
Expand All @@ -4267,7 +4272,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
set_hash("mday", INT2FIX(1));
}
else if (k == sym("commercial")) {
long i;
rb_len_t i;

for (i = 0; i < RARRAY_LEN(a); i++) {
VALUE e = RARRAY_AREF(a, i);
Expand All @@ -4291,7 +4296,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
ref_hash("wday"))));
}
else if (k == sym("wnum0")) {
long i;
rb_len_t i;

for (i = 0; i < RARRAY_LEN(a); i++) {
VALUE e = RARRAY_AREF(a, i);
Expand All @@ -4308,7 +4313,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
set_hash("wday", INT2FIX(0));
}
else if (k == sym("wnum1")) {
long i;
rb_len_t i;

for (i = 0; i < RARRAY_LEN(a); i++) {
VALUE e = RARRAY_AREF(a, i);
Expand Down Expand Up @@ -7409,7 +7414,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
{
VALUE vfmt;
const char *fmt;
long len;
rb_len_t len;
char buffer[SMALLBUF], *buf = buffer;
struct tmx tmx;
VALUE str;
Expand Down Expand Up @@ -7482,7 +7487,7 @@ strftimev(const char *fmt, VALUE self,
{
char buffer[SMALLBUF], *buf = buffer;
struct tmx tmx;
long len;
rb_len_t len;
VALUE str;

(*func)(self, &tmx);
Expand Down Expand Up @@ -7645,7 +7650,7 @@ static VALUE
deconstruct_keys(VALUE self, VALUE keys, int is_datetime)
{
VALUE h = rb_hash_new();
long i;
rb_len_t i;

get_d1(self);

Expand Down
45 changes: 26 additions & 19 deletions ext/date/date_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include "ruby.h"
#include "ruby/encoding.h"
#include "ruby/re.h"

#ifndef HAVE_RB_LEN_T
typedef long rb_len_t;
# define LEN2NUM LONG2NUM
# define NUM2LEN NUM2LONG
#endif

#include <ctype.h>

#undef strncasecmp
Expand Down Expand Up @@ -330,7 +337,7 @@ subx(VALUE str, VALUE rep, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))

be = f_begin(m, INT2FIX(0));
en = f_end(m, INT2FIX(0));
f_aset2(str, be, LONG2NUM(NUM2LONG(en) - NUM2LONG(be)), rep);
f_aset2(str, be, LEN2NUM(NUM2LEN(en) - NUM2LEN(be)), rep);
(*cb)(m, hash);
}

Expand Down Expand Up @@ -367,7 +374,7 @@ do { \
#include "zonetab.h"

static int
str_end_with_word(const char *s, long l, const char *w)
str_end_with_word(const char *s, rb_len_t l, const char *w)
{
int n = (int)strlen(w);
if (l <= n || !isspace((unsigned char)s[l - n - 1])) return 0;
Expand All @@ -376,10 +383,10 @@ str_end_with_word(const char *s, long l, const char *w)
return n;
}

static long
shrunk_size(const char *s, long l)
static rb_len_t
shrunk_size(const char *s, rb_len_t l)
{
long i, ni;
rb_len_t i, ni;
int sp = 0;
for (i = ni = 0; i < l; ++i) {
if (!isspace((unsigned char)s[i])) {
Expand All @@ -394,10 +401,10 @@ shrunk_size(const char *s, long l)
return ni < l ? ni : 0;
}

static long
shrink_space(char *d, const char *s, long l)
static rb_len_t
shrink_space(char *d, const char *s, rb_len_t l)
{
long i, ni;
rb_len_t i, ni;
int sp = 0;
for (i = ni = 0; i < l; ++i) {
if (!isspace((unsigned char)s[i])) {
Expand All @@ -416,7 +423,7 @@ VALUE
date_zone_to_diff(VALUE str)
{
VALUE offset = Qnil;
long l = RSTRING_LEN(str);
rb_len_t l = RSTRING_LEN(str);
const char *s = RSTRING_PTR(str);

{
Expand Down Expand Up @@ -444,7 +451,7 @@ date_zone_to_diff(VALUE str)

{
const char *zn = s;
long sl = shrunk_size(s, l);
rb_len_t sl = shrunk_size(s, l);
char shrunk_buff[MAX_WORD_LENGTH]; /* no terminator to be added */
const struct zone *z = 0;

Expand Down Expand Up @@ -630,7 +637,7 @@ parse_time2_cb(VALUE m, VALUE hash)

if (!NIL_P(f))
f = rb_rational_new2(str2num(f),
f_expt(INT2FIX(10), LONG2NUM(RSTRING_LEN(f))));
f_expt(INT2FIX(10), LEN2NUM(RSTRING_LEN(f))));

p = rb_reg_nth_match(5, m);

Expand Down Expand Up @@ -796,7 +803,7 @@ static int
check_year_width(VALUE y)
{
const char *s;
long l;
rb_len_t l;

l = RSTRING_LEN(y);
if (l < 2) return 0;
Expand Down Expand Up @@ -1750,9 +1757,9 @@ parse_mday(VALUE str, VALUE hash)
}

static int
n2i(const char *s, long f, long w)
n2i(const char *s, rb_len_t f, rb_len_t w)
{
long e, i;
rb_len_t e, i;
int v;

e = f + w;
Expand All @@ -1769,7 +1776,7 @@ parse_ddd_cb(VALUE m, VALUE hash)
{
VALUE s1, s2, s3, s4, s5;
const char *cs2, *cs3, *cs5;
long l2, l3, l4, l5;
rb_len_t l2, l3, l4, l5;

s1 = rb_reg_nth_match(1, m);
s2 = rb_reg_nth_match(2, m);
Expand Down Expand Up @@ -1929,7 +1936,7 @@ parse_ddd_cb(VALUE m, VALUE hash)

set_hash("sec_fraction",
rb_rational_new2(str2num(s4),
f_expt(INT2FIX(10), LONG2NUM(l4))));
f_expt(INT2FIX(10), LEN2NUM(l4))));
}
if (!NIL_P(s5)) {
cs5 = RSTRING_PTR(s5);
Expand Down Expand Up @@ -2092,7 +2099,7 @@ parse_wday_and_time(VALUE str, VALUE hash)
static unsigned
have_invalid_char_p(VALUE s)
{
long i;
rb_len_t i;

for (i = 0; i < RSTRING_LEN(s); i++)
if (iscntrl((unsigned char)RSTRING_PTR(s)[i]) &&
Expand All @@ -2112,7 +2119,7 @@ static unsigned
check_class(VALUE s)
{
unsigned flags;
long i;
rb_len_t i;

flags = 0;
for (i = 0; i < RSTRING_LEN(s); i++) {
Expand Down Expand Up @@ -2320,7 +2327,7 @@ sec_fraction(VALUE f)
{
return rb_rational_new2(str2num(f),
f_expt(INT2FIX(10),
LONG2NUM(RSTRING_LEN(f))));
LEN2NUM(RSTRING_LEN(f))));
}

#define SNUM 14
Expand Down
Loading