[njs] Removed redefinition of NAN and INFINITY macros.

Valentin Bartenev vbart at nginx.com
Fri Nov 4 15:25:15 UTC 2016


details:   http://hg.nginx.org/njs/rev/bcd4910c5be9
branches:  
changeset: 237:bcd4910c5be9
user:      Valentin Bartenev <vbart at nginx.com>
date:      Fri Nov 04 18:25:55 2016 +0300
description:
Removed redefinition of NAN and INFINITY macros.

diffstat:

 njs/njs_builtin.c       |   2 +-
 njs/njs_date.c          |  98 ++++++++++++++++++++++++------------------------
 njs/njs_lexer_keyword.c |   4 +-
 njs/njs_math.c          |  42 ++++++++++----------
 njs/njs_number.c        |   6 +-
 njs/njs_number.h        |   4 --
 njs/njs_string.c        |  10 ++--
 njs/njs_vm.c            |   8 ++--
 8 files changed, 85 insertions(+), 89 deletions(-)

diffs (730 lines):

diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_builtin.c
--- a/njs/njs_builtin.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_builtin.c	Fri Nov 04 18:25:55 2016 +0300
@@ -93,7 +93,7 @@ njs_builtin_objects_create(njs_vm_t *vm)
 
         { .object =       { .type = NJS_REGEXP } },
 
-        { .date =         { .time = NJS_NAN,
+        { .date =         { .time = NAN,
                             .object = { .type = NJS_DATE } } },
     };
 
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_date.c
--- a/njs/njs_date.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_date.c	Fri Nov 04 18:25:55 2016 +0300
@@ -178,7 +178,7 @@ njs_date_utc(njs_vm_t *vm, njs_value_t *
     nxt_uint_t  i, n;
     int32_t     values[8];
 
-    time = NJS_NAN;
+    time = NAN;
 
     if (nargs > 2) {
         memset(values, 0, 8 * sizeof(int32_t));
@@ -292,7 +292,7 @@ njs_date_parse(njs_vm_t *vm, njs_value_t
         time = njs_date_string_parse(&args[1]);
 
     } else {
-        time = NJS_NAN;
+        time = NAN;
     }
 
     njs_number_set(&vm->retval, time);
@@ -316,7 +316,7 @@ njs_date_string_parse(njs_value_t *date)
     end = p + string.size;
 
     if (nxt_slow_path(p >= end)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (*p == '+') {
@@ -351,14 +351,14 @@ njs_date_string_parse(njs_value_t *date)
 
             next = njs_date_number_parse(&ext, next, end, 2);
             if (nxt_slow_path(next == NULL)) {
-                return NJS_NAN;
+                return NAN;
             }
 
             tm.tm_year = tm.tm_year * 100 + ext;
 
             if (string.start[0] == '-') {
                 if (tm.tm_year == 0) {
-                    return NJS_NAN;
+                    return NAN;
                 }
 
                 tm.tm_year = -tm.tm_year;
@@ -369,7 +369,7 @@ njs_date_string_parse(njs_value_t *date)
             }
 
             if (*next != '-') {
-                return NJS_NAN;
+                return NAN;
             }
         }
 
@@ -377,7 +377,7 @@ njs_date_string_parse(njs_value_t *date)
 
         p = njs_date_number_parse(&tm.tm_mon, next + 1, end, 2);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         tm.tm_mon--;
@@ -387,12 +387,12 @@ njs_date_string_parse(njs_value_t *date)
         }
 
         if (nxt_slow_path(*p != '-')) {
-            return NJS_NAN;
+            return NAN;
         }
 
         p = njs_date_number_parse(&tm.tm_mday, p + 1, end, 2);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         if (p == end) {
@@ -400,12 +400,12 @@ njs_date_string_parse(njs_value_t *date)
         }
 
         if (nxt_slow_path(*p != 'T')) {
-            return NJS_NAN;
+            return NAN;
         }
 
         p = njs_date_time_parse(&tm, p + 1, end);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         if (p == end) {
@@ -413,23 +413,23 @@ njs_date_string_parse(njs_value_t *date)
         }
 
         if (nxt_slow_path(p >= end || *p != '.')) {
-            return NJS_NAN;
+            return NAN;
         }
 
         p = njs_date_number_parse(&ms, p + 1, end, 3);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         if (nxt_slow_path(p >= end || *p != 'Z')) {
-            return NJS_NAN;
+            return NAN;
         }
 
         return njs_timegm(&tm) * 1000 + ms;
     }
 
     if (sign) {
-        return NJS_NAN;
+        return NAN;
     }
 
     week = 1;
@@ -456,17 +456,17 @@ njs_date_string_parse(njs_value_t *date)
         }
 
         if (!week) {
-            return NJS_NAN;
+            return NAN;
         }
 
         p = njs_date_skip_week_day(p, end);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         p = njs_date_skip_spaces(p, end);
         if (nxt_slow_path(p == NULL)) {
-            return NJS_NAN;
+            return NAN;
         }
 
         week = 0;
@@ -489,22 +489,22 @@ njs_date_rfc2822_string_parse(struct tm 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     tm->tm_mon = njs_date_month_parse(p, end);
     if (nxt_slow_path(tm->tm_mon < 0)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     p = njs_date_skip_spaces(p + 3, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     p = njs_date_number_parse(&tm->tm_year, p, end, 4);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     tm->tm_year -= 1900;
@@ -515,7 +515,7 @@ njs_date_rfc2822_string_parse(struct tm 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -524,7 +524,7 @@ njs_date_rfc2822_string_parse(struct tm 
 
     p = njs_date_time_parse(tm, p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -533,7 +533,7 @@ njs_date_rfc2822_string_parse(struct tm 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -541,7 +541,7 @@ njs_date_rfc2822_string_parse(struct tm 
     }
 
     if (nxt_slow_path(p + 2 >= end)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if ((p[0] == 'G' && p[1] == 'M' && p[2] == 'T')
@@ -553,7 +553,7 @@ njs_date_rfc2822_string_parse(struct tm 
         gmtoff = njs_date_gmtoff_parse(p, end);
 
         if (nxt_slow_path(gmtoff == -1)) {
-            return NJS_NAN;
+            return NAN;
         }
     }
 
@@ -572,22 +572,22 @@ njs_date_js_string_parse(struct tm *tm, 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     p = njs_date_number_parse(&tm->tm_mday, p, end, 2);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     p = njs_date_number_parse(&tm->tm_year, p, end, 4);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     tm->tm_year -= 1900;
@@ -598,7 +598,7 @@ njs_date_js_string_parse(struct tm *tm, 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -607,7 +607,7 @@ njs_date_js_string_parse(struct tm *tm, 
 
     p = njs_date_time_parse(tm, p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -616,7 +616,7 @@ njs_date_js_string_parse(struct tm *tm, 
 
     p = njs_date_skip_spaces(p, end);
     if (nxt_slow_path(p == NULL)) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (p == end) {
@@ -632,7 +632,7 @@ njs_date_js_string_parse(struct tm *tm, 
         }
     }
 
-    return NJS_NAN;
+    return NAN;
 
 done:
 
@@ -1391,7 +1391,7 @@ njs_date_prototype_set_time(njs_vm_t *vm
             time = args[1].data.u.number;
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1416,7 +1416,7 @@ njs_date_prototype_set_milliseconds(njs_
             time = (int64_t) (time / 1000) * 1000 + args[1].data.u.number;
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1445,7 +1445,7 @@ njs_date_prototype_set_seconds(njs_vm_t 
             time = (int64_t) (time / 60000) * 60000 + sec * 1000 + ms;
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1484,7 +1484,7 @@ njs_date_prototype_set_minutes(njs_vm_t 
             time = njs_date_time(&tm, ms);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1519,7 +1519,7 @@ njs_date_prototype_set_utc_minutes(njs_v
             time = clock * 1000 + ms;
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1562,7 +1562,7 @@ njs_date_prototype_set_hours(njs_vm_t *v
             time = njs_date_time(&tm, ms);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1598,7 +1598,7 @@ njs_date_prototype_set_utc_hours(njs_vm_
             time = clock * 1000 + ms;
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1630,7 +1630,7 @@ njs_date_prototype_set_date(njs_vm_t *vm
             time = njs_date_time(&tm, (int64_t) time % 1000);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1662,7 +1662,7 @@ njs_date_prototype_set_utc_date(njs_vm_t
             time = njs_date_utc_time(&tm, time);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1698,7 +1698,7 @@ njs_date_prototype_set_month(njs_vm_t *v
             time = njs_date_time(&tm, (int64_t) time % 1000);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1734,7 +1734,7 @@ njs_date_prototype_set_utc_month(njs_vm_
             time = njs_date_utc_time(&tm, time);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1774,7 +1774,7 @@ njs_date_prototype_set_full_year(njs_vm_
             time = njs_date_time(&tm, (int64_t) time % 1000);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1814,7 +1814,7 @@ njs_date_prototype_set_utc_full_year(njs
             time = njs_date_utc_time(&tm, time);
 
         } else {
-            time = NJS_NAN;
+            time = NAN;
         }
     }
 
@@ -1838,7 +1838,7 @@ njs_date_time(struct tm *tm, int64_t ms)
         time = (int64_t) clock * 1000 + ms;
 
     } else {
-        time = NJS_NAN;
+        time = NAN;
     }
 
     return time;
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_lexer_keyword.c
--- a/njs/njs_lexer_keyword.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_lexer_keyword.c	Fri Nov 04 18:25:55 2016 +0300
@@ -38,8 +38,8 @@ static const njs_keyword_t  njs_keywords
     { nxt_string("null"),          NJS_TOKEN_NULL, 0 },
     { nxt_string("false"),         NJS_TOKEN_BOOLEAN, 0 },
     { nxt_string("true"),          NJS_TOKEN_BOOLEAN, 1 },
-    { nxt_string("NaN"),           NJS_TOKEN_NUMBER, NJS_NAN },
-    { nxt_string("Infinity"),      NJS_TOKEN_NUMBER, NJS_INFINITY },
+    { nxt_string("NaN"),           NJS_TOKEN_NUMBER, NAN },
+    { nxt_string("Infinity"),      NJS_TOKEN_NUMBER, INFINITY },
 
     /* Operators. */
 
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_math.c
--- a/njs/njs_math.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_math.c	Fri Nov 04 18:25:55 2016 +0300
@@ -31,7 +31,7 @@ njs_object_math_abs(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, fabs(num));
@@ -50,7 +50,7 @@ njs_object_math_acos(njs_vm_t *vm, njs_v
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, acos(num));
@@ -69,7 +69,7 @@ njs_object_math_asin(njs_vm_t *vm, njs_v
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, asin(num));
@@ -88,7 +88,7 @@ njs_object_math_atan(njs_vm_t *vm, njs_v
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, atan(num));
@@ -103,8 +103,8 @@ njs_object_math_atan2(njs_vm_t *vm, njs_
 {
     double  y, x;
 
-    y = NJS_NAN;
-    x = NJS_NAN;
+    y = NAN;
+    x = NAN;
 
     if (nargs > 1) {
         y = args[1].data.u.number;
@@ -130,7 +130,7 @@ njs_object_math_ceil(njs_vm_t *vm, njs_v
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, ceil(num));
@@ -149,7 +149,7 @@ njs_object_math_cos(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, cos(num));
@@ -168,7 +168,7 @@ njs_object_math_exp(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, exp(num));
@@ -187,7 +187,7 @@ njs_object_math_floor(njs_vm_t *vm, njs_
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, floor(num));
@@ -206,7 +206,7 @@ njs_object_math_log(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, log(num));
@@ -237,7 +237,7 @@ njs_object_math_max(njs_vm_t *vm, njs_va
         }
 
     } else {
-        num = -NJS_INFINITY;
+        num = -INFINITY;
     }
 
     njs_number_set(&vm->retval, num);
@@ -268,7 +268,7 @@ njs_object_math_min(njs_vm_t *vm, njs_va
         }
 
     } else {
-        num = NJS_INFINITY;
+        num = INFINITY;
     }
 
     njs_number_set(&vm->retval, num);
@@ -283,8 +283,8 @@ njs_object_math_pow(njs_vm_t *vm, njs_va
 {
     double  base, exponent;
 
-    base = NJS_NAN;
-    exponent = NJS_NAN;
+    base = NAN;
+    exponent = NAN;
 
     if (nargs > 1) {
         base = args[1].data.u.number;
@@ -324,7 +324,7 @@ njs_object_math_round(njs_vm_t *vm, njs_
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, round(num));
@@ -347,7 +347,7 @@ njs_object_math_sign(njs_vm_t *vm, njs_v
         }
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, num);
@@ -366,7 +366,7 @@ njs_object_math_sin(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, sin(num));
@@ -385,7 +385,7 @@ njs_object_math_sqrt(njs_vm_t *vm, njs_v
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, sqrt(num));
@@ -404,7 +404,7 @@ njs_object_math_tan(njs_vm_t *vm, njs_va
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, tan(num));
@@ -423,7 +423,7 @@ njs_object_math_trunc(njs_vm_t *vm, njs_
         num = args[1].data.u.number;
 
     } else {
-        num = NJS_NAN;
+        num = NAN;
     }
 
     njs_number_set(&vm->retval, trunc(num));
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_number.c
--- a/njs/njs_number.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_number.c	Fri Nov 04 18:25:55 2016 +0300
@@ -59,7 +59,7 @@ njs_value_to_number(njs_value_t *value)
         }
     }
 
-    return NJS_NAN;
+    return NAN;
 }
 
 
@@ -489,7 +489,7 @@ njs_number_parse_int(njs_vm_t *vm, njs_v
     nxt_bool_t         minus;
     njs_string_prop_t  string;
 
-    num = NJS_NAN;
+    num = NAN;
 
     if (nargs > 1) {
         (void) njs_string_prop(&string, &args[1]);
@@ -559,7 +559,7 @@ njs_number_parse_float(njs_vm_t *vm, njs
 {
     double  num;
 
-    num = NJS_NAN;
+    num = NAN;
 
     if (nargs > 1) {
         num = njs_string_to_number(&args[1], 0);
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_number.h
--- a/njs/njs_number.h	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_number.h	Fri Nov 04 18:25:55 2016 +0300
@@ -11,10 +11,6 @@
 #include <math.h>
 
 
-#define NJS_NAN       NAN
-#define NJS_INFINITY  INFINITY
-
-
 #define njs_is_infinity(n)                                                    \
     isinf(n)
 
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_string.c
--- a/njs/njs_string.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_string.c	Fri Nov 04 18:25:55 2016 +0300
@@ -1127,7 +1127,7 @@ njs_string_prototype_char_code_at(njs_vm
         index = args[1].data.u.number;
 
         if (nxt_slow_path(index < 0 || index >= length)) {
-            num = NJS_NAN;
+            num = NAN;
             goto done;
         }
     }
@@ -2921,7 +2921,7 @@ njs_string_to_number(njs_value_t *value,
     }
 
     if (p == end) {
-        return NJS_NAN;
+        return NAN;
     }
 
     if (*p >= '0' && *p <= '9') {
@@ -2929,17 +2929,17 @@ njs_string_to_number(njs_value_t *value,
 
     } else {
         if (p + infinity > end || memcmp(p, "Infinity", infinity) != 0) {
-            return NJS_NAN;
+            return NAN;
         }
 
-        num = NJS_INFINITY;
+        num = INFINITY;
         p += infinity;
     }
 
     if (exact) {
         while (p < end) {
             if (*p != ' ' && *p != '\t') {
-                return NJS_NAN;
+                return NAN;
             }
 
             p++;
diff -r a713275dc4cb -r bcd4910c5be9 njs/njs_vm.c
--- a/njs/njs_vm.c	Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_vm.c	Fri Nov 04 18:25:55 2016 +0300
@@ -116,11 +116,11 @@ void njs_debug(njs_index_t index, njs_va
 
 
 const njs_value_t  njs_value_null =         njs_value(NJS_NULL, 0, 0.0);
-const njs_value_t  njs_value_void =         njs_value(NJS_VOID, 0, NJS_NAN);
+const njs_value_t  njs_value_void =         njs_value(NJS_VOID, 0, NAN);
 const njs_value_t  njs_value_false =        njs_value(NJS_BOOLEAN, 0, 0.0);
 const njs_value_t  njs_value_true =         njs_value(NJS_BOOLEAN, 1, 1.0);
 const njs_value_t  njs_value_zero =         njs_value(NJS_NUMBER, 0, 0.0);
-const njs_value_t  njs_value_nan =          njs_value(NJS_NUMBER, 0, NJS_NAN);
+const njs_value_t  njs_value_nan =          njs_value(NJS_NUMBER, 0, NAN);
 
 
 const njs_value_t  njs_string_empty =       njs_string("");
@@ -2962,7 +2962,7 @@ njs_vmcode_number_primitive(njs_vm_t *vm
     if (nxt_fast_path(ret > 0)) {
 
         if (!njs_is_numeric(value)) {
-            num = NJS_NAN;
+            num = NAN;
 
             if (njs_is_string(value)) {
                 num = njs_string_to_number(value, 1);
@@ -3015,7 +3015,7 @@ njs_vmcode_number_argument(njs_vm_t *vm,
     if (nxt_fast_path(ret > 0)) {
 
         if (!njs_is_numeric(value)) {
-            num = NJS_NAN;
+            num = NAN;
 
             if (njs_is_string(value)) {
                 num = njs_string_to_number(value, 1);



More information about the nginx-devel mailing list