Skip to content

Commit 96d1d13

Browse files
committed
Update timelib to 2015.02
1 parent e4f3fb9 commit 96d1d13

File tree

9 files changed

+264
-356
lines changed

9 files changed

+264
-356
lines changed

ext/date/lib/parse_date.c

Lines changed: 131 additions & 131 deletions
Large diffs are not rendered by default.

ext/date/lib/parse_date.re

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef unsigned char uchar;
110110

111111
#define RET(i) {s->cur = cursor; return i;}
112112

113-
#define timelib_string_free free
113+
#define timelib_string_free timelib_free
114114

115115
#define TIMELIB_HAVE_TIME() { if (s->time->have_time) { add_error(s, "Double time specification"); timelib_string_free(str); return TIMELIB_ERROR; } else { s->time->have_time = 1; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; } }
116116
#define TIMELIB_UNHAVE_TIME() { s->time->have_time = 0; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; }
@@ -322,15 +322,15 @@ uchar *fill(Scanner *s, uchar *cursor){
322322
s->lim -= cnt;
323323
}
324324
if((s->top - s->lim) < BSIZE){
325-
uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar));
325+
uchar *buf = (uchar*) timelib_malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar));
326326
memcpy(buf, s->tok, s->lim - s->tok);
327327
s->tok = buf;
328328
s->ptr = &buf[s->ptr - s->bot];
329329
cursor = &buf[cursor - s->bot];
330330
s->pos = &buf[s->pos - s->bot];
331331
s->lim = &buf[s->lim - s->bot];
332332
s->top = &s->lim[BSIZE];
333-
free(s->bot);
333+
timelib_free(s->bot);
334334
s->bot = buf;
335335
}
336336
if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){
@@ -345,37 +345,37 @@ uchar *fill(Scanner *s, uchar *cursor){
345345
static void add_warning(Scanner *s, char *error)
346346
{
347347
s->errors->warning_count++;
348-
s->errors->warning_messages = realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
348+
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
349349
s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
350350
s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
351-
s->errors->warning_messages[s->errors->warning_count - 1].message = strdup(error);
351+
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
352352
}
353353

354354
static void add_error(Scanner *s, char *error)
355355
{
356356
s->errors->error_count++;
357-
s->errors->error_messages = realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
357+
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
358358
s->errors->error_messages[s->errors->error_count - 1].position = s->tok ? s->tok - s->str : 0;
359359
s->errors->error_messages[s->errors->error_count - 1].character = s->tok ? *s->tok : 0;
360-
s->errors->error_messages[s->errors->error_count - 1].message = strdup(error);
360+
s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error);
361361
}
362362

363363
static void add_pbf_warning(Scanner *s, char *error, char *sptr, char *cptr)
364364
{
365365
s->errors->warning_count++;
366-
s->errors->warning_messages = realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
366+
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
367367
s->errors->warning_messages[s->errors->warning_count - 1].position = cptr - sptr;
368368
s->errors->warning_messages[s->errors->warning_count - 1].character = *cptr;
369-
s->errors->warning_messages[s->errors->warning_count - 1].message = strdup(error);
369+
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
370370
}
371371

372372
static void add_pbf_error(Scanner *s, char *error, char *sptr, char *cptr)
373373
{
374374
s->errors->error_count++;
375-
s->errors->error_messages = realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
375+
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
376376
s->errors->error_messages[s->errors->error_count - 1].position = cptr - sptr;
377377
s->errors->error_messages[s->errors->error_count - 1].character = *cptr;
378-
s->errors->error_messages[s->errors->error_count - 1].message = strdup(error);
378+
s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error);
379379
}
380380

381381
static timelib_sll timelib_meridian(char **ptr, timelib_sll h)
@@ -439,7 +439,7 @@ static timelib_sll timelib_meridian_with_check(char **ptr, timelib_sll h)
439439

440440
static char *timelib_string(Scanner *s)
441441
{
442-
char *tmp = calloc(1, s->cur - s->tok + 1);
442+
char *tmp = timelib_calloc(1, s->cur - s->tok + 1);
443443
memcpy(tmp, s->tok, s->cur - s->tok);
444444

445445
return tmp;
@@ -466,10 +466,10 @@ static timelib_sll timelib_get_nr_ex(char **ptr, int max_length, int *scanned_le
466466
if (scanned_length) {
467467
*scanned_length = end - begin;
468468
}
469-
str = calloc(1, end - begin + 1);
469+
str = timelib_calloc(1, end - begin + 1);
470470
memcpy(str, begin, end - begin);
471471
tmp_nr = strtoll(str, NULL, 10);
472-
free(str);
472+
timelib_free(str);
473473
return tmp_nr;
474474
}
475475

@@ -506,13 +506,13 @@ static double timelib_get_frac_nr(char **ptr, int max_length)
506506
++len;
507507
}
508508
end = *ptr;
509-
str = calloc(1, end - begin + 1);
509+
str = timelib_calloc(1, end - begin + 1);
510510
memcpy(str, begin, end - begin);
511511
if (str[0] == ':') {
512512
str[0] = '.';
513513
}
514514
tmp_nr = strtod(str, NULL);
515-
free(str);
515+
timelib_free(str);
516516
return tmp_nr;
517517
}
518518

@@ -548,7 +548,7 @@ static timelib_sll timelib_lookup_relative_text(char **ptr, int *behavior)
548548
++*ptr;
549549
}
550550
end = *ptr;
551-
word = calloc(1, end - begin + 1);
551+
word = timelib_calloc(1, end - begin + 1);
552552
memcpy(word, begin, end - begin);
553553

554554
for (tp = timelib_reltext_lookup; tp->name; tp++) {
@@ -558,7 +558,7 @@ static timelib_sll timelib_lookup_relative_text(char **ptr, int *behavior)
558558
}
559559
}
560560

561-
free(word);
561+
timelib_free(word);
562562
return value;
563563
}
564564

@@ -581,7 +581,7 @@ static timelib_long timelib_lookup_month(char **ptr)
581581
++*ptr;
582582
}
583583
end = *ptr;
584-
word = calloc(1, end - begin + 1);
584+
word = timelib_calloc(1, end - begin + 1);
585585
memcpy(word, begin, end - begin);
586586

587587
for (tp = timelib_month_lookup; tp->name; tp++) {
@@ -590,7 +590,7 @@ static timelib_long timelib_lookup_month(char **ptr)
590590
}
591591
}
592592

593-
free(word);
593+
timelib_free(word);
594594
return value;
595595
}
596596

@@ -628,7 +628,7 @@ static const timelib_relunit* timelib_lookup_relunit(char **ptr)
628628
++*ptr;
629629
}
630630
end = *ptr;
631-
word = calloc(1, end - begin + 1);
631+
word = timelib_calloc(1, end - begin + 1);
632632
memcpy(word, begin, end - begin);
633633

634634
for (tp = timelib_relunit_lookup; tp->name; tp++) {
@@ -638,7 +638,7 @@ static const timelib_relunit* timelib_lookup_relunit(char **ptr)
638638
}
639639
}
640640

641-
free(word);
641+
timelib_free(word);
642642
return value;
643643
}
644644

@@ -723,7 +723,7 @@ static timelib_long timelib_lookup_abbr(char **ptr, int *dst, char **tz_abbr, in
723723
++*ptr;
724724
}
725725
end = *ptr;
726-
word = calloc(1, end - begin + 1);
726+
word = timelib_calloc(1, end - begin + 1);
727727
memcpy(word, begin, end - begin);
728728

729729
if ((tp = abbr_search(word, -1, 0))) {
@@ -790,7 +790,7 @@ timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_n
790790
found++;
791791
}
792792
}
793-
free(tz_abbr);
793+
timelib_free(tz_abbr);
794794
*tz_not_found = (found == 0);
795795
retval = offset;
796796
}
@@ -803,10 +803,10 @@ timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_n
803803
#define timelib_split_free(arg) { \
804804
int i; \
805805
for (i = 0; i < arg.c; i++) { \
806-
free(arg.v[i]); \
806+
timelib_free(arg.v[i]); \
807807
} \
808808
if (arg.v) { \
809-
free(arg.v); \
809+
timelib_free(arg.v); \
810810
} \
811811
}
812812

@@ -1734,7 +1734,7 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
17341734
char *e = s + len - 1;
17351735

17361736
memset(&in, 0, sizeof(in));
1737-
in.errors = malloc(sizeof(struct timelib_error_container));
1737+
in.errors = timelib_malloc(sizeof(struct timelib_error_container));
17381738
in.errors->warning_count = 0;
17391739
in.errors->warning_messages = NULL;
17401740
in.errors->error_count = 0;
@@ -1762,7 +1762,7 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
17621762
}
17631763
e++;
17641764

1765-
in.str = malloc((e - s) + YYMAXFILL);
1765+
in.str = timelib_malloc((e - s) + YYMAXFILL);
17661766
memset(in.str, 0, (e - s) + YYMAXFILL);
17671767
memcpy(in.str, s, (e - s));
17681768
in.lim = in.str + (e - s) + YYMAXFILL;
@@ -1798,7 +1798,7 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
17981798
add_warning(&in, "The parsed date was invalid");
17991799
}
18001800

1801-
free(in.str);
1801+
timelib_free(in.str);
18021802
if (errors) {
18031803
*errors = in.errors;
18041804
} else {
@@ -1849,7 +1849,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
18491849
int allow_extra = 0;
18501850

18511851
memset(&in, 0, sizeof(in));
1852-
in.errors = malloc(sizeof(struct timelib_error_container));
1852+
in.errors = timelib_malloc(sizeof(struct timelib_error_container));
18531853
in.errors->warning_count = 0;
18541854
in.errors->warning_messages = NULL;
18551855
in.errors->error_count = 0;
@@ -2192,14 +2192,14 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
21922192
if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0;
21932193

21942194
if (!parsed->tz_abbr) {
2195-
parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL;
2195+
parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL;
21962196
}
21972197
if (!parsed->tz_info) {
21982198
parsed->tz_info = now->tz_info ? (!(options & TIMELIB_NO_CLONE) ? timelib_tzinfo_clone(now->tz_info) : now->tz_info) : NULL;
21992199
}
22002200
if (parsed->zone_type == 0 && now->zone_type != 0) {
22012201
parsed->zone_type = now->zone_type;
2202-
/* parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL;
2202+
/* parsed->tz_abbr = now->tz_abbr ? timelib_strdup(now->tz_abbr) : NULL;
22032203
parsed->tz_info = now->tz_info ? timelib_tzinfo_clone(now->tz_info) : NULL;
22042204
*/ parsed->is_localtime = 1;
22052205
}

0 commit comments

Comments
 (0)