diff options
| author | Andrea Corallo | 2020-03-29 12:31:24 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-03-29 12:31:24 +0100 |
| commit | 00ee320a620704ae12a1e2104c2d08bf8bbdf0c9 (patch) | |
| tree | 498c59219b572c89e10f9521b54c98896cb52ca9 /src/data.c | |
| parent | 530faee2752c7b316fa21f2ac4d1266d3e7a38e6 (diff) | |
| parent | 76b3bd8cbb9a0a01941d9c1766c054960e4bfd97 (diff) | |
| download | emacs-00ee320a620704ae12a1e2104c2d08bf8bbdf0c9.tar.gz emacs-00ee320a620704ae12a1e2104c2d08bf8bbdf0c9.zip | |
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/data.c b/src/data.c index 2820f647981..b53b8409b59 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2368,6 +2368,24 @@ bool-vector. IDX starts at 0. */) | |||
| 2368 | 2368 | ||
| 2369 | /* Arithmetic functions */ | 2369 | /* Arithmetic functions */ |
| 2370 | 2370 | ||
| 2371 | static Lisp_Object | ||
| 2372 | check_integer_coerce_marker (Lisp_Object x) | ||
| 2373 | { | ||
| 2374 | if (MARKERP (x)) | ||
| 2375 | return make_fixnum (marker_position (x)); | ||
| 2376 | CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); | ||
| 2377 | return x; | ||
| 2378 | } | ||
| 2379 | |||
| 2380 | static Lisp_Object | ||
| 2381 | check_number_coerce_marker (Lisp_Object x) | ||
| 2382 | { | ||
| 2383 | if (MARKERP (x)) | ||
| 2384 | return make_fixnum (marker_position (x)); | ||
| 2385 | CHECK_TYPE (NUMBERP (x), Qnumber_or_marker_p, x); | ||
| 2386 | return x; | ||
| 2387 | } | ||
| 2388 | |||
| 2371 | Lisp_Object | 2389 | Lisp_Object |
| 2372 | arithcompare (Lisp_Object num1, Lisp_Object num2, | 2390 | arithcompare (Lisp_Object num1, Lisp_Object num2, |
| 2373 | enum Arith_Comparison comparison) | 2391 | enum Arith_Comparison comparison) |
| @@ -2376,8 +2394,8 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, | |||
| 2376 | bool lt, eq = true, gt; | 2394 | bool lt, eq = true, gt; |
| 2377 | bool test; | 2395 | bool test; |
| 2378 | 2396 | ||
| 2379 | CHECK_NUMBER_COERCE_MARKER (num1); | 2397 | num1 = check_number_coerce_marker (num1); |
| 2380 | CHECK_NUMBER_COERCE_MARKER (num2); | 2398 | num2 = check_number_coerce_marker (num2); |
| 2381 | 2399 | ||
| 2382 | /* If the comparison is mostly done by comparing two doubles, | 2400 | /* If the comparison is mostly done by comparing two doubles, |
| 2383 | set LT, EQ, and GT to the <, ==, > results of that comparison, | 2401 | set LT, EQ, and GT to the <, ==, > results of that comparison, |
| @@ -2779,9 +2797,7 @@ floatop_arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2779 | argnum++; | 2797 | argnum++; |
| 2780 | if (argnum == nargs) | 2798 | if (argnum == nargs) |
| 2781 | return make_float (accum); | 2799 | return make_float (accum); |
| 2782 | Lisp_Object val = args[argnum]; | 2800 | next = XFLOATINT (check_number_coerce_marker (args[argnum])); |
| 2783 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2784 | next = XFLOATINT (val); | ||
| 2785 | } | 2801 | } |
| 2786 | } | 2802 | } |
| 2787 | 2803 | ||
| @@ -2843,8 +2859,7 @@ bignum_arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2843 | argnum++; | 2859 | argnum++; |
| 2844 | if (argnum == nargs) | 2860 | if (argnum == nargs) |
| 2845 | return make_integer_mpz (); | 2861 | return make_integer_mpz (); |
| 2846 | val = args[argnum]; | 2862 | val = check_number_coerce_marker (args[argnum]); |
| 2847 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2848 | if (FLOATP (val)) | 2863 | if (FLOATP (val)) |
| 2849 | return float_arith_driver (code, nargs, args, argnum, | 2864 | return float_arith_driver (code, nargs, args, argnum, |
| 2850 | mpz_get_d_rounded (*accum), val); | 2865 | mpz_get_d_rounded (*accum), val); |
| @@ -2873,8 +2888,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2873 | argnum++; | 2888 | argnum++; |
| 2874 | if (argnum == nargs) | 2889 | if (argnum == nargs) |
| 2875 | return make_int (accum); | 2890 | return make_int (accum); |
| 2876 | val = args[argnum]; | 2891 | val = check_number_coerce_marker (args[argnum]); |
| 2877 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2878 | 2892 | ||
| 2879 | /* Set NEXT to the next value if it fits, else exit the loop. */ | 2893 | /* Set NEXT to the next value if it fits, else exit the loop. */ |
| 2880 | intmax_t next; | 2894 | intmax_t next; |
| @@ -2921,8 +2935,7 @@ usage: (+ &rest NUMBERS-OR-MARKERS) */) | |||
| 2921 | { | 2935 | { |
| 2922 | if (nargs == 0) | 2936 | if (nargs == 0) |
| 2923 | return make_fixnum (0); | 2937 | return make_fixnum (0); |
| 2924 | Lisp_Object a = args[0]; | 2938 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2925 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2926 | return nargs == 1 ? a : arith_driver (Aadd, nargs, args, a); | 2939 | return nargs == 1 ? a : arith_driver (Aadd, nargs, args, a); |
| 2927 | } | 2940 | } |
| 2928 | 2941 | ||
| @@ -2935,8 +2948,7 @@ usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) | |||
| 2935 | { | 2948 | { |
| 2936 | if (nargs == 0) | 2949 | if (nargs == 0) |
| 2937 | return make_fixnum (0); | 2950 | return make_fixnum (0); |
| 2938 | Lisp_Object a = args[0]; | 2951 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2939 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2940 | if (nargs == 1) | 2952 | if (nargs == 1) |
| 2941 | { | 2953 | { |
| 2942 | if (FIXNUMP (a)) | 2954 | if (FIXNUMP (a)) |
| @@ -2956,8 +2968,7 @@ usage: (* &rest NUMBERS-OR-MARKERS) */) | |||
| 2956 | { | 2968 | { |
| 2957 | if (nargs == 0) | 2969 | if (nargs == 0) |
| 2958 | return make_fixnum (1); | 2970 | return make_fixnum (1); |
| 2959 | Lisp_Object a = args[0]; | 2971 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2960 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2961 | return nargs == 1 ? a : arith_driver (Amult, nargs, args, a); | 2972 | return nargs == 1 ? a : arith_driver (Amult, nargs, args, a); |
| 2962 | } | 2973 | } |
| 2963 | 2974 | ||
| @@ -2969,8 +2980,7 @@ The arguments must be numbers or markers. | |||
| 2969 | usage: (/ NUMBER &rest DIVISORS) */) | 2980 | usage: (/ NUMBER &rest DIVISORS) */) |
| 2970 | (ptrdiff_t nargs, Lisp_Object *args) | 2981 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2971 | { | 2982 | { |
| 2972 | Lisp_Object a = args[0]; | 2983 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2973 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2974 | if (nargs == 1) | 2984 | if (nargs == 1) |
| 2975 | { | 2985 | { |
| 2976 | if (FIXNUMP (a)) | 2986 | if (FIXNUMP (a)) |
| @@ -3052,10 +3062,10 @@ integer_remainder (Lisp_Object num, Lisp_Object den, bool modulo) | |||
| 3052 | DEFUN ("%", Frem, Srem, 2, 2, 0, | 3062 | DEFUN ("%", Frem, Srem, 2, 2, 0, |
| 3053 | doc: /* Return remainder of X divided by Y. | 3063 | doc: /* Return remainder of X divided by Y. |
| 3054 | Both must be integers or markers. */) | 3064 | Both must be integers or markers. */) |
| 3055 | (register Lisp_Object x, Lisp_Object y) | 3065 | (Lisp_Object x, Lisp_Object y) |
| 3056 | { | 3066 | { |
| 3057 | CHECK_INTEGER_COERCE_MARKER (x); | 3067 | x = check_integer_coerce_marker (x); |
| 3058 | CHECK_INTEGER_COERCE_MARKER (y); | 3068 | y = check_integer_coerce_marker (y); |
| 3059 | return integer_remainder (x, y, false); | 3069 | return integer_remainder (x, y, false); |
| 3060 | } | 3070 | } |
| 3061 | 3071 | ||
| @@ -3065,8 +3075,8 @@ The result falls between zero (inclusive) and Y (exclusive). | |||
| 3065 | Both X and Y must be numbers or markers. */) | 3075 | Both X and Y must be numbers or markers. */) |
| 3066 | (Lisp_Object x, Lisp_Object y) | 3076 | (Lisp_Object x, Lisp_Object y) |
| 3067 | { | 3077 | { |
| 3068 | CHECK_NUMBER_COERCE_MARKER (x); | 3078 | x = check_number_coerce_marker (x); |
| 3069 | CHECK_NUMBER_COERCE_MARKER (y); | 3079 | y = check_number_coerce_marker (y); |
| 3070 | if (FLOATP (x) || FLOATP (y)) | 3080 | if (FLOATP (x) || FLOATP (y)) |
| 3071 | return fmod_float (x, y); | 3081 | return fmod_float (x, y); |
| 3072 | return integer_remainder (x, y, true); | 3082 | return integer_remainder (x, y, true); |
| @@ -3076,12 +3086,10 @@ static Lisp_Object | |||
| 3076 | minmax_driver (ptrdiff_t nargs, Lisp_Object *args, | 3086 | minmax_driver (ptrdiff_t nargs, Lisp_Object *args, |
| 3077 | enum Arith_Comparison comparison) | 3087 | enum Arith_Comparison comparison) |
| 3078 | { | 3088 | { |
| 3079 | Lisp_Object accum = args[0]; | 3089 | Lisp_Object accum = check_number_coerce_marker (args[0]); |
| 3080 | CHECK_NUMBER_COERCE_MARKER (accum); | ||
| 3081 | for (ptrdiff_t argnum = 1; argnum < nargs; argnum++) | 3090 | for (ptrdiff_t argnum = 1; argnum < nargs; argnum++) |
| 3082 | { | 3091 | { |
| 3083 | Lisp_Object val = args[argnum]; | 3092 | Lisp_Object val = check_number_coerce_marker (args[argnum]); |
| 3084 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 3085 | if (!NILP (arithcompare (val, accum, comparison))) | 3093 | if (!NILP (arithcompare (val, accum, comparison))) |
| 3086 | accum = val; | 3094 | accum = val; |
| 3087 | else if (FLOATP (val) && isnan (XFLOAT_DATA (val))) | 3095 | else if (FLOATP (val) && isnan (XFLOAT_DATA (val))) |
| @@ -3116,8 +3124,7 @@ usage: (logand &rest INTS-OR-MARKERS) */) | |||
| 3116 | { | 3124 | { |
| 3117 | if (nargs == 0) | 3125 | if (nargs == 0) |
| 3118 | return make_fixnum (-1); | 3126 | return make_fixnum (-1); |
| 3119 | Lisp_Object a = args[0]; | 3127 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3120 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3121 | return nargs == 1 ? a : arith_driver (Alogand, nargs, args, a); | 3128 | return nargs == 1 ? a : arith_driver (Alogand, nargs, args, a); |
| 3122 | } | 3129 | } |
| 3123 | 3130 | ||
| @@ -3129,8 +3136,7 @@ usage: (logior &rest INTS-OR-MARKERS) */) | |||
| 3129 | { | 3136 | { |
| 3130 | if (nargs == 0) | 3137 | if (nargs == 0) |
| 3131 | return make_fixnum (0); | 3138 | return make_fixnum (0); |
| 3132 | Lisp_Object a = args[0]; | 3139 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3133 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3134 | return nargs == 1 ? a : arith_driver (Alogior, nargs, args, a); | 3140 | return nargs == 1 ? a : arith_driver (Alogior, nargs, args, a); |
| 3135 | } | 3141 | } |
| 3136 | 3142 | ||
| @@ -3142,8 +3148,7 @@ usage: (logxor &rest INTS-OR-MARKERS) */) | |||
| 3142 | { | 3148 | { |
| 3143 | if (nargs == 0) | 3149 | if (nargs == 0) |
| 3144 | return make_fixnum (0); | 3150 | return make_fixnum (0); |
| 3145 | Lisp_Object a = args[0]; | 3151 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3146 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3147 | return nargs == 1 ? a : arith_driver (Alogxor, nargs, args, a); | 3152 | return nargs == 1 ? a : arith_driver (Alogxor, nargs, args, a); |
| 3148 | } | 3153 | } |
| 3149 | 3154 | ||
| @@ -3262,9 +3267,9 @@ expt_integer (Lisp_Object x, Lisp_Object y) | |||
| 3262 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, | 3267 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, |
| 3263 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. | 3268 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. |
| 3264 | Markers are converted to integers. */) | 3269 | Markers are converted to integers. */) |
| 3265 | (register Lisp_Object number) | 3270 | (Lisp_Object number) |
| 3266 | { | 3271 | { |
| 3267 | CHECK_NUMBER_COERCE_MARKER (number); | 3272 | number = check_number_coerce_marker (number); |
| 3268 | 3273 | ||
| 3269 | if (FIXNUMP (number)) | 3274 | if (FIXNUMP (number)) |
| 3270 | return make_int (XFIXNUM (number) + 1); | 3275 | return make_int (XFIXNUM (number) + 1); |
| @@ -3277,9 +3282,9 @@ Markers are converted to integers. */) | |||
| 3277 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, | 3282 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, |
| 3278 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. | 3283 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. |
| 3279 | Markers are converted to integers. */) | 3284 | Markers are converted to integers. */) |
| 3280 | (register Lisp_Object number) | 3285 | (Lisp_Object number) |
| 3281 | { | 3286 | { |
| 3282 | CHECK_NUMBER_COERCE_MARKER (number); | 3287 | number = check_number_coerce_marker (number); |
| 3283 | 3288 | ||
| 3284 | if (FIXNUMP (number)) | 3289 | if (FIXNUMP (number)) |
| 3285 | return make_int (XFIXNUM (number) - 1); | 3290 | return make_int (XFIXNUM (number) - 1); |