iodine 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of iodine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -2
- data/ext/iodine/fio.c +319 -46
- data/ext/iodine/fio.h +851 -37
- data/ext/iodine/fio_cli.c +17 -16
- data/ext/iodine/fio_json_parser.h +28 -3
- data/ext/iodine/fiobj_ary.c +44 -46
- data/ext/iodine/fiobj_data.c +12 -13
- data/ext/iodine/fiobj_hash.c +28 -27
- data/ext/iodine/fiobj_json.c +40 -33
- data/ext/iodine/fiobj_numbers.c +2 -304
- data/ext/iodine/fiobj_str.c +0 -1
- data/ext/iodine/fiobject.c +268 -38
- data/ext/iodine/iodine_json.c +13 -14
- data/ext/iodine/iodine_store.c +33 -29
- data/iodine.gemspec +1 -3
- data/lib/iodine.rb +2 -2
- data/lib/iodine/json.rb +3 -1
- data/lib/iodine/version.rb +1 -1
- metadata +5 -4
- data/ext/iodine/fio_ary.h +0 -717
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6853939131113d6d1055ae516e38fb0f5ced25fa9fdc6f1915e2fb59cd7af749
|
4
|
+
data.tar.gz: 628c7b663864b8f99a79e6a37ebe26be080e5f4bed537715717c7e2879e1cbaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 133121bf7da250b83f7e4131e68b09cc66bc972a91338ad54e77597c2ed433e8b86be546ce80272414573c386ed043a681c8255fc4316599c1686eb72d2fb144
|
7
|
+
data.tar.gz: e28e559b199684495cbf767cd75983aa51859b0544c3017f314ef848add51c088adf4551d1ab7abe7a4ec331580fbc25c802c1ff0860ae2c437a58864628de9f
|
data/CHANGELOG.md
CHANGED
@@ -6,11 +6,21 @@ Please notice that this change log contains changes for upcoming releases as wel
|
|
6
6
|
|
7
7
|
## Changes:
|
8
8
|
|
9
|
+
#### Change log v.0.7.4
|
10
|
+
|
11
|
+
**Fix**: fixed a missing `static` keyword in the Ruby<=>C storage bridge which caused performance degradation and introduced namespace conflict risks.
|
12
|
+
|
13
|
+
**Fix**: fixed the `on_worker_fork` callback timing, to be performed before forking the process (Puma compatibility).
|
14
|
+
|
15
|
+
**Fix**: fixes to minor issues are included in the facil.io edge update.
|
16
|
+
|
17
|
+
**Optimize**: minor optimization to memory use, included in facil.io edge updates.
|
18
|
+
|
9
19
|
#### Change log v.0.7.3
|
10
20
|
|
11
|
-
**Fix**: (facil.io) updating facil.io fixes a channel name memory leak fixed in facil.io's edge version.
|
21
|
+
**Fix**: (facil.io) updating facil.io fixes a channel name memory leak that was fixed in facil.io's edge version.
|
12
22
|
|
13
|
-
**Updated**: Improved logging for server data, allowing for log silencing.
|
23
|
+
**Updated**: Improved logging for server data, allowing for total log silencing - this doesn't effect HTTP logging, only iodine's core logging system.
|
14
24
|
|
15
25
|
#### Change log v.0.7.2
|
16
26
|
|
data/ext/iodine/fio.c
CHANGED
@@ -3544,6 +3544,79 @@ Section Start Marker
|
|
3544
3544
|
Strings to Numbers
|
3545
3545
|
***************************************************************************** */
|
3546
3546
|
|
3547
|
+
FIO_FUNC inline size_t fio_atol_skip_zero(char **pstr) {
|
3548
|
+
char *const start = *pstr;
|
3549
|
+
while (**pstr == '0') {
|
3550
|
+
++(*pstr);
|
3551
|
+
}
|
3552
|
+
return (size_t)(*pstr - *start);
|
3553
|
+
}
|
3554
|
+
|
3555
|
+
/* consumes any digits in the string (base 2-10), returning their value */
|
3556
|
+
FIO_FUNC inline uint64_t fio_atol_consume(char **pstr, uint8_t base) {
|
3557
|
+
uint64_t result = 0;
|
3558
|
+
const uint64_t limit = UINT64_MAX - (base * base);
|
3559
|
+
while (**pstr >= '0' && **pstr < ('0' + base) && result <= (limit)) {
|
3560
|
+
result = (result * base) + (**pstr - '0');
|
3561
|
+
++(*pstr);
|
3562
|
+
}
|
3563
|
+
return result;
|
3564
|
+
}
|
3565
|
+
|
3566
|
+
/* returns true if there's data to be skipped */
|
3567
|
+
FIO_FUNC inline uint8_t fio_atol_skip_test(char **pstr, uint8_t base) {
|
3568
|
+
return (**pstr >= '0' && **pstr < ('0' + base));
|
3569
|
+
}
|
3570
|
+
|
3571
|
+
/* consumes any digits in the string (base 2-10), returning the count skipped */
|
3572
|
+
FIO_FUNC inline uint64_t fio_atol_skip(char **pstr, uint8_t base) {
|
3573
|
+
uint64_t result = 0;
|
3574
|
+
while (fio_atol_skip_test(pstr, base)) {
|
3575
|
+
++result;
|
3576
|
+
++(*pstr);
|
3577
|
+
}
|
3578
|
+
return result;
|
3579
|
+
}
|
3580
|
+
|
3581
|
+
/* consumes any hex data in the string, returning their value */
|
3582
|
+
FIO_FUNC inline uint64_t fio_atol_consume_hex(char **pstr) {
|
3583
|
+
uint64_t result = 0;
|
3584
|
+
const uint64_t limit = UINT64_MAX - (16 * 16);
|
3585
|
+
for (; result <= limit;) {
|
3586
|
+
uint8_t tmp;
|
3587
|
+
if (**pstr >= '0' && **pstr <= '9')
|
3588
|
+
tmp = **pstr - '0';
|
3589
|
+
else if (**pstr >= 'A' && **pstr <= 'F')
|
3590
|
+
tmp = **pstr - ('A' - 10);
|
3591
|
+
else if (**pstr >= 'a' && **pstr <= 'f')
|
3592
|
+
tmp = **pstr - ('a' - 10);
|
3593
|
+
else
|
3594
|
+
return result;
|
3595
|
+
result = (result << 4) | tmp;
|
3596
|
+
++(*pstr);
|
3597
|
+
}
|
3598
|
+
return result;
|
3599
|
+
}
|
3600
|
+
|
3601
|
+
/* returns true if there's data to be skipped */
|
3602
|
+
FIO_FUNC inline uint8_t fio_atol_skip_hex_test(char **pstr) {
|
3603
|
+
return (**pstr >= '0' && **pstr <= '9') || (**pstr >= 'A' && **pstr <= 'F') ||
|
3604
|
+
(**pstr >= 'a' && **pstr <= 'f');
|
3605
|
+
}
|
3606
|
+
|
3607
|
+
/* consumes any digits in the string (base 2-10), returning the count skipped */
|
3608
|
+
FIO_FUNC inline uint64_t fio_atol_skip_hex(char **pstr) {
|
3609
|
+
uint64_t result = 0;
|
3610
|
+
while (fio_atol_skip_hex_test(pstr)) {
|
3611
|
+
++result;
|
3612
|
+
++(*pstr);
|
3613
|
+
}
|
3614
|
+
return result;
|
3615
|
+
}
|
3616
|
+
|
3617
|
+
/* caches a up to 8*8 */
|
3618
|
+
// static inline fio_atol_pow_10_cache(size_t ex) {}
|
3619
|
+
|
3547
3620
|
/**
|
3548
3621
|
* A helper function that converts between String data to a signed int64_t.
|
3549
3622
|
*
|
@@ -3559,66 +3632,54 @@ int64_t fio_atol(char **pstr) {
|
|
3559
3632
|
char *str = *pstr;
|
3560
3633
|
uint64_t result = 0;
|
3561
3634
|
uint8_t invert = 0;
|
3562
|
-
while (str
|
3635
|
+
while (isspace(*str))
|
3636
|
+
++(str);
|
3637
|
+
if (str[0] == '-') {
|
3563
3638
|
invert ^= 1;
|
3564
3639
|
++str;
|
3640
|
+
} else if (*str == '+') {
|
3641
|
+
++(str);
|
3565
3642
|
}
|
3643
|
+
|
3566
3644
|
if (str[0] == 'B' || str[0] == 'b' ||
|
3567
3645
|
(str[0] == '0' && (str[1] == 'b' || str[1] == 'B'))) {
|
3568
3646
|
/* base 2 */
|
3569
3647
|
if (str[0] == '0')
|
3570
3648
|
str++;
|
3571
3649
|
str++;
|
3650
|
+
fio_atol_skip_zero(&str);
|
3572
3651
|
while (str[0] == '0' || str[0] == '1') {
|
3573
|
-
result = (result << 1) | (str[0]
|
3652
|
+
result = (result << 1) | (str[0] - '0');
|
3574
3653
|
str++;
|
3575
3654
|
}
|
3655
|
+
goto sign; /* no overlow protection, since sign might be embedded */
|
3656
|
+
|
3576
3657
|
} else if (str[0] == 'x' || str[0] == 'X' ||
|
3577
3658
|
(str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))) {
|
3578
3659
|
/* base 16 */
|
3579
|
-
uint8_t tmp;
|
3580
3660
|
if (str[0] == '0')
|
3581
3661
|
str++;
|
3582
3662
|
str++;
|
3583
|
-
|
3584
|
-
|
3585
|
-
|
3586
|
-
|
3587
|
-
|
3588
|
-
else if (str[0] >= 'a' && str[0] <= 'f')
|
3589
|
-
tmp = str[0] - ('a' - 10);
|
3590
|
-
else
|
3591
|
-
goto finish;
|
3592
|
-
result = (result << 4) | tmp;
|
3593
|
-
str++;
|
3594
|
-
}
|
3663
|
+
fio_atol_skip_zero(&str);
|
3664
|
+
result = fio_atol_consume_hex(&str);
|
3665
|
+
if (fio_atol_skip_hex_test(&str)) /* too large for a number */
|
3666
|
+
return 0;
|
3667
|
+
goto sign; /* no overlow protection, since sign might be embedded */
|
3595
3668
|
} else if (str[0] == '0') {
|
3596
|
-
|
3669
|
+
fio_atol_skip_zero(&str);
|
3597
3670
|
/* base 8 */
|
3598
|
-
|
3599
|
-
|
3600
|
-
end++;
|
3601
|
-
if ((uintptr_t)(end - str) > 21) /* TODO: fix too large for a number */
|
3671
|
+
result = fio_atol_consume(&str, 8);
|
3672
|
+
if (fio_atol_skip_test(&str, 8)) /* too large for a number */
|
3602
3673
|
return 0;
|
3603
|
-
|
3604
|
-
while (str < end) {
|
3605
|
-
result = (result * 8) + (str[0] - '0');
|
3606
|
-
str++;
|
3607
|
-
}
|
3608
3674
|
} else {
|
3609
3675
|
/* base 10 */
|
3610
|
-
|
3611
|
-
|
3612
|
-
end++;
|
3613
|
-
if ((uintptr_t)(end - str) > 21) /* too large for a number */
|
3676
|
+
result = fio_atol_consume(&str, 10);
|
3677
|
+
if (fio_atol_skip_test(&str, 10)) /* too large for a number */
|
3614
3678
|
return 0;
|
3615
|
-
|
3616
|
-
while (str < end) {
|
3617
|
-
result = (result * 10) + (str[0] - '0');
|
3618
|
-
str++;
|
3619
|
-
}
|
3620
3679
|
}
|
3621
|
-
|
3680
|
+
if (result & ((uint64_t)1 << 63))
|
3681
|
+
result = INT64_MAX; /* signed overflow protection */
|
3682
|
+
sign:
|
3622
3683
|
if (invert)
|
3623
3684
|
result = 0 - result;
|
3624
3685
|
*pstr = str;
|
@@ -3715,12 +3776,12 @@ size_t fio_ltoa(char *dest, int64_t num, uint8_t base) {
|
|
3715
3776
|
n = n << 8;
|
3716
3777
|
i++;
|
3717
3778
|
}
|
3718
|
-
/* make sure the Hex representation doesn't appear signed. */
|
3779
|
+
/* make sure the Hex representation doesn't appear misleadingly signed. */
|
3719
3780
|
if (i && (n & 0x8000000000000000)) {
|
3720
3781
|
dest[len++] = '0';
|
3721
3782
|
dest[len++] = '0';
|
3722
3783
|
}
|
3723
|
-
/* write the damn thing */
|
3784
|
+
/* write the damn thing, high to low */
|
3724
3785
|
while (i < 8) {
|
3725
3786
|
uint8_t tmp = (n & 0xF000000000000000) >> 60;
|
3726
3787
|
dest[len++] = notation[tmp];
|
@@ -3785,6 +3846,9 @@ zero:
|
|
3785
3846
|
dest[len++] = '0';
|
3786
3847
|
dest[len++] = 'b';
|
3787
3848
|
break;
|
3849
|
+
case 8:
|
3850
|
+
dest[len++] = '0';
|
3851
|
+
break;
|
3788
3852
|
case 16:
|
3789
3853
|
dest[len++] = '0';
|
3790
3854
|
dest[len++] = 'x';
|
@@ -5724,6 +5788,27 @@ Section Start Marker
|
|
5724
5788
|
***************************************************************************** */
|
5725
5789
|
|
5726
5790
|
#if FIO_FORCE_MALLOC
|
5791
|
+
|
5792
|
+
void *fio_malloc(size_t size) { return calloc(size, 1); }
|
5793
|
+
|
5794
|
+
void *fio_calloc(size_t size_per_unit, size_t unit_count) {
|
5795
|
+
return calloc(size_per_unit, unit_count);
|
5796
|
+
}
|
5797
|
+
|
5798
|
+
void fio_free(void *ptr) { free(ptr); }
|
5799
|
+
|
5800
|
+
void *fio_realloc(void *ptr, size_t new_size) {
|
5801
|
+
return realloc((ptr), (new_size));
|
5802
|
+
}
|
5803
|
+
|
5804
|
+
void *fio_realloc2(void *ptr, size_t new_size, size_t copy_length) {
|
5805
|
+
return realloc((ptr), (new_size));
|
5806
|
+
(void)copy_length;
|
5807
|
+
}
|
5808
|
+
|
5809
|
+
void *fio_mmap(size_t size) { return calloc(size, 1); }
|
5810
|
+
|
5811
|
+
void fio_malloc_after_fork(void) {}
|
5727
5812
|
void fio_mem_destroy(void) {}
|
5728
5813
|
void fio_mem_init(void) {}
|
5729
5814
|
|
@@ -7950,10 +8035,11 @@ Testing Memory Allocator
|
|
7950
8035
|
***************************************************************************** */
|
7951
8036
|
|
7952
8037
|
#if FIO_FORCE_MALLOC
|
7953
|
-
#define fio_malloc_test()
|
8038
|
+
#define fio_malloc_test() \
|
8039
|
+
fprintf(stderr, "\n=== SKIPPED facil.io memory allocator (bypassed)\n");
|
7954
8040
|
#else
|
7955
8041
|
void fio_malloc_test(void) {
|
7956
|
-
fprintf(stderr, "=== Testing facil.io memory allocator's system calls\n");
|
8042
|
+
fprintf(stderr, "\n=== Testing facil.io memory allocator's system calls\n");
|
7957
8043
|
char *mem = sys_alloc(FIO_MEMORY_BLOCK_SIZE, 0);
|
7958
8044
|
FIO_ASSERT(mem, "sys_alloc failed to allocate memory!\n");
|
7959
8045
|
FIO_ASSERT(!((uintptr_t)mem & FIO_MEMORY_BLOCK_MASK),
|
@@ -8407,6 +8493,40 @@ static void fio_defer_test(void) {
|
|
8407
8493
|
fprintf(stderr, "\n* passed.\n");
|
8408
8494
|
}
|
8409
8495
|
|
8496
|
+
/* *****************************************************************************
|
8497
|
+
Array data-structure Testing
|
8498
|
+
***************************************************************************** */
|
8499
|
+
|
8500
|
+
typedef struct {
|
8501
|
+
int i;
|
8502
|
+
char c;
|
8503
|
+
} fio_ary_test_type_s;
|
8504
|
+
|
8505
|
+
#define FIO_ARY_NAME fio_i_ary
|
8506
|
+
#define FIO_ARY_TYPE uintptr_t
|
8507
|
+
#include "fio.h"
|
8508
|
+
|
8509
|
+
static intptr_t ary_alloc_counter = 0;
|
8510
|
+
static void copy_s(fio_ary_test_type_s *d, fio_ary_test_type_s *s) {
|
8511
|
+
++ary_alloc_counter;
|
8512
|
+
*d = *s;
|
8513
|
+
}
|
8514
|
+
|
8515
|
+
#define FIO_ARY_NAME fio_s_ary
|
8516
|
+
#define FIO_ARY_TYPE fio_ary_test_type_s
|
8517
|
+
#define FIO_ARY_COPY(dest, src) copy_s(&(dest), &(src))
|
8518
|
+
#define FIO_ARY_COMPARE(dest, src) ((dest).i == (src).i && (dest).c == (src).c)
|
8519
|
+
#define FIO_ARY_DESTROY(obj) (--ary_alloc_counter)
|
8520
|
+
#include "fio.h"
|
8521
|
+
|
8522
|
+
void fio_ary_test(void) {
|
8523
|
+
/* code */
|
8524
|
+
fio_i_ary__test();
|
8525
|
+
fio_s_ary__test();
|
8526
|
+
FIO_ASSERT(!ary_alloc_counter, "array object deallocation error, %ld != 0",
|
8527
|
+
ary_alloc_counter);
|
8528
|
+
}
|
8529
|
+
|
8410
8530
|
/* *****************************************************************************
|
8411
8531
|
Set data-structure Testing
|
8412
8532
|
***************************************************************************** */
|
@@ -9291,6 +9411,7 @@ static void fio_str2u_test(void) {
|
|
9291
9411
|
"fio_u2str16 / fio_str2u16 mismatch %zd != %zd",
|
9292
9412
|
(ssize_t)(fio_str2u16(buffer)), (ssize_t)i);
|
9293
9413
|
}
|
9414
|
+
fprintf(stderr, "* passed.\n");
|
9294
9415
|
}
|
9295
9416
|
|
9296
9417
|
/* *****************************************************************************
|
@@ -9359,6 +9480,7 @@ static void fio_pubsub_test(void) {
|
|
9359
9480
|
fio_data->workers = 0;
|
9360
9481
|
(void)fio_pubsub_test_on_message;
|
9361
9482
|
(void)fio_pubsub_test_on_unsubscribe;
|
9483
|
+
fprintf(stderr, "* passed.\n");
|
9362
9484
|
}
|
9363
9485
|
#else
|
9364
9486
|
#define fio_pubsub_test()
|
@@ -9383,6 +9505,59 @@ static void fio_atol_test(void) {
|
|
9383
9505
|
" Test with make test/optimized for realistic results.\n");
|
9384
9506
|
time_t start, end;
|
9385
9507
|
|
9508
|
+
#define TEST_ATOL(s, n) \
|
9509
|
+
do { \
|
9510
|
+
char *p = (char *)(s); \
|
9511
|
+
int64_t r = fio_atol(&p); \
|
9512
|
+
FIO_ASSERT(r == (n), "fio_atol test error! %s => %zd (not %zd)", \
|
9513
|
+
((char *)(s)), (size_t)r, (size_t)n); \
|
9514
|
+
FIO_ASSERT((s) + strlen((s)) == p, \
|
9515
|
+
"fio_atol test error! %s reading position not at end (%zu)", \
|
9516
|
+
(s), (size_t)(p - (s))); \
|
9517
|
+
char buf[72]; \
|
9518
|
+
buf[fio_ltoa(buf, n, 2)] = 0; \
|
9519
|
+
p = buf; \
|
9520
|
+
FIO_ASSERT(fio_atol(&p) == (n), \
|
9521
|
+
"fio_ltoa base 2 test error! " \
|
9522
|
+
"%s != %s (%zd)", \
|
9523
|
+
buf, ((char *)(s)), (size_t)((p = buf), fio_atol(&p))); \
|
9524
|
+
buf[fio_ltoa(buf, n, 8)] = 0; \
|
9525
|
+
p = buf; \
|
9526
|
+
FIO_ASSERT(fio_atol(&p) == (n), \
|
9527
|
+
"fio_ltoa base 8 test error! " \
|
9528
|
+
"%s != %s (%zd)", \
|
9529
|
+
buf, ((char *)(s)), (size_t)((p = buf), fio_atol(&p))); \
|
9530
|
+
buf[fio_ltoa(buf, n, 10)] = 0; \
|
9531
|
+
p = buf; \
|
9532
|
+
FIO_ASSERT(fio_atol(&p) == (n), \
|
9533
|
+
"fio_ltoa base 10 test error! " \
|
9534
|
+
"%s != %s (%zd)", \
|
9535
|
+
buf, ((char *)(s)), (size_t)((p = buf), fio_atol(&p))); \
|
9536
|
+
buf[fio_ltoa(buf, n, 16)] = 0; \
|
9537
|
+
p = buf; \
|
9538
|
+
FIO_ASSERT(fio_atol(&p) == (n), \
|
9539
|
+
"fio_ltoa base 16 test error! " \
|
9540
|
+
"%s != %s (%zd)", \
|
9541
|
+
buf, ((char *)(s)), (size_t)((p = buf), fio_atol(&p))); \
|
9542
|
+
} while (0)
|
9543
|
+
TEST_ATOL("0x1", 1);
|
9544
|
+
TEST_ATOL("-0x1", -1);
|
9545
|
+
TEST_ATOL("-0xa", -10); /* sign before hex */
|
9546
|
+
TEST_ATOL("0xe5d4c3b2a1908770", -1885667171979196560); /* sign within hex */
|
9547
|
+
TEST_ATOL("0b00000000000011", 3);
|
9548
|
+
TEST_ATOL("-0b00000000000011", -3);
|
9549
|
+
TEST_ATOL("0b0000000000000000000000000000000000000000000000000", 0);
|
9550
|
+
TEST_ATOL("0", 0);
|
9551
|
+
TEST_ATOL("1", 1);
|
9552
|
+
TEST_ATOL("2", 2);
|
9553
|
+
TEST_ATOL("-2", -2);
|
9554
|
+
TEST_ATOL("0000000000000000000000000000000000000000000000042", 34); /* oct */
|
9555
|
+
TEST_ATOL("9223372036854775807", 9223372036854775807LL); /* INT64_MAX */
|
9556
|
+
TEST_ATOL("9223372036854775808",
|
9557
|
+
9223372036854775807LL); /* INT64_MAX overflow protection */
|
9558
|
+
TEST_ATOL("9223372036854775999",
|
9559
|
+
9223372036854775807LL); /* INT64_MAX overflow protection */
|
9560
|
+
|
9386
9561
|
char number_hex[128] = "0xe5d4c3b2a1908770"; /* hex with embedded sign */
|
9387
9562
|
// char number_hex[128] = "-0x1a2b3c4d5e6f7890";
|
9388
9563
|
char number[128] = "-1885667171979196560";
|
@@ -9399,9 +9574,6 @@ static void fio_atol_test(void) {
|
|
9399
9574
|
__asm__ volatile("" ::: "memory");
|
9400
9575
|
}
|
9401
9576
|
end = clock();
|
9402
|
-
FIO_ASSERT(result == expect,
|
9403
|
-
"fio_atol with base 10 returned wrong result (%ld != %ld)", expect,
|
9404
|
-
result);
|
9405
9577
|
fprintf(stderr, "fio_atol base 10 (%ld): %zd CPU cycles\n", result,
|
9406
9578
|
end - start);
|
9407
9579
|
|
@@ -9425,9 +9597,6 @@ static void fio_atol_test(void) {
|
|
9425
9597
|
__asm__ volatile("" ::: "memory");
|
9426
9598
|
}
|
9427
9599
|
end = clock();
|
9428
|
-
FIO_ASSERT(result == expect,
|
9429
|
-
"fio_atol with base 16 returned wrong result (%ld != %ld)", expect,
|
9430
|
-
result);
|
9431
9600
|
fprintf(stderr, "fio_atol base 16 (%ld): %zd CPU cycles\n", result,
|
9432
9601
|
end - start);
|
9433
9602
|
|
@@ -9473,8 +9642,110 @@ static void fio_atol_test(void) {
|
|
9473
9642
|
"base 10 zero should be single char.");
|
9474
9643
|
FIO_ASSERT(memcmp(number, "0", 2) == 0, "base 10 zero should be \"0\" (%s).",
|
9475
9644
|
number);
|
9645
|
+
fprintf(stderr, "* passed.\n");
|
9646
|
+
#undef TEST_ATOL
|
9476
9647
|
}
|
9477
9648
|
|
9649
|
+
/* *****************************************************************************
|
9650
|
+
String 2 Float and Float 2 String (partial) testing
|
9651
|
+
***************************************************************************** */
|
9652
|
+
|
9653
|
+
static void fio_atof_test(void) {
|
9654
|
+
fprintf(stderr, "=== Testing fio_ftoa and fio_ftoa (partial)\n");
|
9655
|
+
#define TEST_DOUBLE(s, d, must) \
|
9656
|
+
do { \
|
9657
|
+
char *p = (char *)(s); \
|
9658
|
+
double r = fio_atof(&p); \
|
9659
|
+
if (r != (d)) { \
|
9660
|
+
FIO_LOG_DEBUG("Double Test Error! %s => %.19g (not %.19g)", \
|
9661
|
+
((char *)(s)), r, d); \
|
9662
|
+
if (must) { \
|
9663
|
+
FIO_ASSERT(0, "double test failed on %s", ((char *)(s))); \
|
9664
|
+
exit(-1); \
|
9665
|
+
} \
|
9666
|
+
} \
|
9667
|
+
} while (0)
|
9668
|
+
/* The numbers were copied from https://github.com/miloyip/rapidjson */
|
9669
|
+
TEST_DOUBLE("0.0", 0.0, 1);
|
9670
|
+
TEST_DOUBLE("-0.0", -0.0, 1);
|
9671
|
+
TEST_DOUBLE("1.0", 1.0, 1);
|
9672
|
+
TEST_DOUBLE("-1.0", -1.0, 1);
|
9673
|
+
TEST_DOUBLE("1.5", 1.5, 1);
|
9674
|
+
TEST_DOUBLE("-1.5", -1.5, 1);
|
9675
|
+
TEST_DOUBLE("3.1416", 3.1416, 1);
|
9676
|
+
TEST_DOUBLE("1E10", 1E10, 1);
|
9677
|
+
TEST_DOUBLE("1e10", 1e10, 1);
|
9678
|
+
TEST_DOUBLE("1E+10", 1E+10, 1);
|
9679
|
+
TEST_DOUBLE("1E-10", 1E-10, 1);
|
9680
|
+
TEST_DOUBLE("-1E10", -1E10, 1);
|
9681
|
+
TEST_DOUBLE("-1e10", -1e10, 1);
|
9682
|
+
TEST_DOUBLE("-1E+10", -1E+10, 1);
|
9683
|
+
TEST_DOUBLE("-1E-10", -1E-10, 1);
|
9684
|
+
TEST_DOUBLE("1.234E+10", 1.234E+10, 1);
|
9685
|
+
TEST_DOUBLE("1.234E-10", 1.234E-10, 1);
|
9686
|
+
TEST_DOUBLE("1.79769e+308", 1.79769e+308, 1);
|
9687
|
+
TEST_DOUBLE("2.22507e-308", 2.22507e-308, 1);
|
9688
|
+
TEST_DOUBLE("-1.79769e+308", -1.79769e+308, 1);
|
9689
|
+
TEST_DOUBLE("-2.22507e-308", -2.22507e-308, 1);
|
9690
|
+
TEST_DOUBLE("4.9406564584124654e-324", 4.9406564584124654e-324, 0);
|
9691
|
+
TEST_DOUBLE("2.2250738585072009e-308", 2.2250738585072009e-308, 0);
|
9692
|
+
TEST_DOUBLE("2.2250738585072014e-308", 2.2250738585072014e-308, 1);
|
9693
|
+
TEST_DOUBLE("1.7976931348623157e+308", 1.7976931348623157e+308, 1);
|
9694
|
+
TEST_DOUBLE("1e-10000", 0.0, 0);
|
9695
|
+
TEST_DOUBLE("18446744073709551616", 18446744073709551616.0, 0);
|
9696
|
+
|
9697
|
+
TEST_DOUBLE("-9223372036854775809", -9223372036854775809.0, 0);
|
9698
|
+
|
9699
|
+
TEST_DOUBLE("0.9868011474609375", 0.9868011474609375, 0);
|
9700
|
+
TEST_DOUBLE("123e34", 123e34, 1);
|
9701
|
+
TEST_DOUBLE("45913141877270640000.0", 45913141877270640000.0, 1);
|
9702
|
+
TEST_DOUBLE("2.2250738585072011e-308", 2.2250738585072011e-308, 0);
|
9703
|
+
TEST_DOUBLE("1e-214748363", 0.0, 1);
|
9704
|
+
TEST_DOUBLE("1e-214748364", 0.0, 1);
|
9705
|
+
TEST_DOUBLE("0.017976931348623157e+310, 1", 1.7976931348623157e+308, 0);
|
9706
|
+
|
9707
|
+
TEST_DOUBLE("2.2250738585072012e-308", 2.2250738585072014e-308, 0);
|
9708
|
+
TEST_DOUBLE("2.22507385850720113605740979670913197593481954635164565e-308",
|
9709
|
+
2.2250738585072014e-308, 0);
|
9710
|
+
|
9711
|
+
TEST_DOUBLE("0.999999999999999944488848768742172978818416595458984375", 1.0,
|
9712
|
+
0);
|
9713
|
+
TEST_DOUBLE("0.999999999999999944488848768742172978818416595458984376", 1.0,
|
9714
|
+
0);
|
9715
|
+
TEST_DOUBLE("1.00000000000000011102230246251565404236316680908203125", 1.0,
|
9716
|
+
0);
|
9717
|
+
TEST_DOUBLE("1.00000000000000011102230246251565404236316680908203124", 1.0,
|
9718
|
+
0);
|
9719
|
+
|
9720
|
+
TEST_DOUBLE("72057594037927928.0", 72057594037927928.0, 0);
|
9721
|
+
TEST_DOUBLE("72057594037927936.0", 72057594037927936.0, 0);
|
9722
|
+
TEST_DOUBLE("72057594037927932.0", 72057594037927936.0, 0);
|
9723
|
+
TEST_DOUBLE("7205759403792793200001e-5", 72057594037927936.0, 0);
|
9724
|
+
|
9725
|
+
TEST_DOUBLE("9223372036854774784.0", 9223372036854774784.0, 0);
|
9726
|
+
TEST_DOUBLE("9223372036854775808.0", 9223372036854775808.0, 0);
|
9727
|
+
TEST_DOUBLE("9223372036854775296.0", 9223372036854775808.0, 0);
|
9728
|
+
TEST_DOUBLE("922337203685477529600001e-5", 9223372036854775808.0, 0);
|
9729
|
+
|
9730
|
+
TEST_DOUBLE("10141204801825834086073718800384",
|
9731
|
+
10141204801825834086073718800384.0, 0);
|
9732
|
+
TEST_DOUBLE("10141204801825835211973625643008",
|
9733
|
+
10141204801825835211973625643008.0, 0);
|
9734
|
+
TEST_DOUBLE("10141204801825834649023672221696",
|
9735
|
+
10141204801825835211973625643008.0, 0);
|
9736
|
+
TEST_DOUBLE("1014120480182583464902367222169600001e-5",
|
9737
|
+
10141204801825835211973625643008.0, 0);
|
9738
|
+
|
9739
|
+
TEST_DOUBLE("5708990770823838890407843763683279797179383808",
|
9740
|
+
5708990770823838890407843763683279797179383808.0, 0);
|
9741
|
+
TEST_DOUBLE("5708990770823839524233143877797980545530986496",
|
9742
|
+
5708990770823839524233143877797980545530986496.0, 0);
|
9743
|
+
TEST_DOUBLE("5708990770823839207320493820740630171355185152",
|
9744
|
+
5708990770823839524233143877797980545530986496.0, 0);
|
9745
|
+
TEST_DOUBLE("5708990770823839207320493820740630171355185152001e-3",
|
9746
|
+
5708990770823839524233143877797980545530986496.0, 0);
|
9747
|
+
fprintf(stderr, "\n* passed.\n");
|
9748
|
+
}
|
9478
9749
|
/* *****************************************************************************
|
9479
9750
|
Run all tests
|
9480
9751
|
***************************************************************************** */
|
@@ -9485,15 +9756,17 @@ void fio_test(void) {
|
|
9485
9756
|
fio_state_callback_test();
|
9486
9757
|
fio_str_test();
|
9487
9758
|
fio_atol_test();
|
9759
|
+
fio_atof_test();
|
9488
9760
|
fio_str2u_test();
|
9489
9761
|
fio_llist_test();
|
9762
|
+
fio_ary_test();
|
9763
|
+
fio_set_test();
|
9490
9764
|
fio_defer_test();
|
9491
9765
|
fio_timer_test();
|
9492
9766
|
fio_poll_test();
|
9493
9767
|
fio_socket_test();
|
9494
9768
|
fio_uuid_link_test();
|
9495
9769
|
fio_cycle_test();
|
9496
|
-
fio_set_test();
|
9497
9770
|
fio_siphash_test();
|
9498
9771
|
fio_sha1_test();
|
9499
9772
|
fio_sha2_test();
|