diff options
| author | Paul Eggert | 2018-08-27 21:27:50 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-27 21:45:23 -0700 |
| commit | d77d01d22902acdc45c2c7059de4f1b158ab5806 (patch) | |
| tree | 35f2b77594dc43e824852bb29598430945c5e6a4 /src/lisp.h | |
| parent | 9abaf5f3581ecb76f30e8a6e7ee0e9633c133d1c (diff) | |
| download | emacs-d77d01d22902acdc45c2c7059de4f1b158ab5806.tar.gz emacs-d77d01d22902acdc45c2c7059de4f1b158ab5806.zip | |
Improve bignum support for system types
Use bignums when Emacs converts to and from system types like
off_t for file sizes whose values can exceed fixnum range.
Formerly, Emacs sometimes generted floats and sometimes ad-hoc
conses of integers. Emacs still accepts floats and conses for
these system types, in case some stray Lisp code is generating
them, though this usage is obsolescent.
* doc/lispref/files.texi (File Attributes):
* doc/lispref/hash.texi (Defining Hash):
* doc/lispref/nonascii.texi (Character Sets):
* doc/lispref/os.texi (User Identification):
* doc/lispref/processes.texi (System Processes):
* etc/NEWS:
Document changes.
* src/bignum.c (mpz_set_uintmax, make_biguint)
(mpz_set_uintmax_slow, bignum_to_intmax, bignum_to_uintmax):
New functions.
(mpz_set_intmax_slow): Implement via mpz_limbs_write,
to avoid the need for an extra pass through a negative number.
* src/charset.c (Fencode_char):
* src/composite.h (LGLYPH_SET_CODE):
* src/dired.c (file_attributes):
* src/dosfns.c, src/w32.c (list_system_processes)
(system_process_attributes):
* src/editfns.c (init_editfns, Fuser_uid, Fuser_real_uid)
(Fgroup_gid, Fgroup_real_gid, Femacs_pid):
* src/emacs-module.c (check_vec_index):
* src/fns.c (Fsafe_length):
* src/process.c (record_deleted_pid, Fprocess_id):
* src/sysdep.c (list_system_processes, system_process_attributes):
* src/xselect.c (x_own_selection, selection_data_to_lisp_data):
* src/xterm.c (set_wm_state):
* src/inotify.c (inotifyevent_to_event, add_watch)
(inotify_callback):
If an integer is out of fixnum range, use a bignum
instead of converting it to a float or a cons of integers.
* src/coding.c (Fdefine_coding_system_internal):
* src/frame.c (frame_windows_min_size)
(x_set_frame_parameters):
* src/fringe.c (Fdefine_fringe_bitmap):
* src/nsterm.m (mouseDown:):
* src/syntax.c (find_defun_start):
* src/w32fns.c (x_set_undecorated, w32_createwindow)
(w32_wnd_proc, Fx_create_frame, Fx_show_tip)
(w32_console_toggle_lock_key):
* src/w32inevt.c (key_event):
* src/w32proc.c (Fw32_get_locale_info):
Do not mishandle floats by treating their addresses as their
values.
* src/data.c (store_symval_forwarding):
* src/gnutls.c (Fgnutls_error_fatalp, Fgnutls_error_string):
* src/keyboard.c (command_loop_1, make_lispy_event):
* src/lread.c (read_filtered_event, read1)
(substitute_object_recurse):
* src/window.c (Fcoordinates_in_window_p, Fwindow_at)
(window_resize_apply, Fset_window_vscroll):
* src/xdisp.c (handle_single_display_spec, try_scrolling)
(redisplay_window, calc_pixel_width_or_height)
(calc_line_height_property, on_hot_spot_p):
* src/xfaces.c (check_lface_attrs):
* src/xselect.c (x_get_local_selection, cons_to_x_long)
(lisp_data_to_selection_data, clean_local_selection_data)
(x_check_property_data, x_fill_property_data):
(x_send_client_event):
Do not reject bignums.
* src/data.c (INTBIG_TO_LISP, intbig_to_lisp)
(uintbig_to_lisp):
Remove. All uses removed.
* src/data.c (cons_to_unsigned, cons_to_signed):
* src/dbusbind.c (xd_signature, xd_extract_signed)
(xd_extract_unsigned):
* src/dispnew.c (sit_for):
* src/dosfns.c, src/w32.c (system_process_attributes):
* src/editfns.c (Fuser_full_name):
* src/fileio.c (file_offset):
* src/fileio.c (write_region):
* src/font.c (font_unparse_xlfd, font_open_for_lface, Fopen_font):
* src/frame.c (x_set_screen_gamma):
* src/frame.h (NUMVAL, FRAME_PIXEL_X_FROM_CANON_X)
(FRAME_PIXEL_Y_FROM_CANON_Y):
* src/image.c (parse_image_spec, x_edge_detection)
(compute_image_size):
* src/json.c (json_to_lisp):
* src/lcms.c (PARSE_LAB_LIST_FIELD, Flcms_cie_de2000)
(PARSE_XYZ_LIST_FIELD, PARSE_JCH_LIST_FIELD)
(PARSE_JAB_LIST_FIELD, PARSE_VIEW_CONDITION_FLOAT)
(Flcms_temp_to_white_point):
* src/nsimage.m (ns_load_image, setSizeFromSpec):
* src/process.c (Fsignal_process, handle_child_signal):
* src/sysdep.c (system_process_attributes):
* src/xdisp.c (calc_line_height_property):
Handle bignums.
* src/data.c (Fnumber_to_string): Use proper predicate name in
signal if the argument is not a number.
* src/lisp.h (make_uint): New function.
(INT_TO_INTEGER): New macro.
(FIXED_OR_FLOATP, CHECK_FIXNUM_OR_FLOAT)
(CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER, INTEGER_TO_CONS)
(make_fixnum_or_float): Remove; no longer used.
* src/nsfns.m, src/w32fns.c, src/xfns.c (Fx_create_frame):
Reject floating-point min-width or min-height.
* src/process.c (handle_child_signal): Do not worry
about floating-point pids, as they are no longer generated.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/src/lisp.h b/src/lisp.h index 555496bc271..c5b51ba3b35 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -586,6 +586,7 @@ INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, | |||
| 586 | /* Defined in bignum.c. */ | 586 | /* Defined in bignum.c. */ |
| 587 | extern double bignum_to_double (Lisp_Object); | 587 | extern double bignum_to_double (Lisp_Object); |
| 588 | extern Lisp_Object make_bigint (intmax_t); | 588 | extern Lisp_Object make_bigint (intmax_t); |
| 589 | extern Lisp_Object make_biguint (uintmax_t); | ||
| 589 | 590 | ||
| 590 | /* Defined in chartab.c. */ | 591 | /* Defined in chartab.c. */ |
| 591 | extern Lisp_Object char_table_ref (Lisp_Object, int); | 592 | extern Lisp_Object char_table_ref (Lisp_Object, int); |
| @@ -2468,6 +2469,15 @@ make_int (intmax_t n) | |||
| 2468 | { | 2469 | { |
| 2469 | return FIXNUM_OVERFLOW_P (n) ? make_bigint (n) : make_fixnum (n); | 2470 | return FIXNUM_OVERFLOW_P (n) ? make_bigint (n) : make_fixnum (n); |
| 2470 | } | 2471 | } |
| 2472 | INLINE Lisp_Object | ||
| 2473 | make_uint (uintmax_t n) | ||
| 2474 | { | ||
| 2475 | return FIXNUM_OVERFLOW_P (n) ? make_biguint (n) : make_fixnum (n); | ||
| 2476 | } | ||
| 2477 | |||
| 2478 | /* Return a Lisp integer equal to the value of the C integer EXPR. */ | ||
| 2479 | #define INT_TO_INTEGER(expr) \ | ||
| 2480 | (EXPR_SIGNED (expr) ? make_int (expr) : make_uint (expr)) | ||
| 2471 | 2481 | ||
| 2472 | 2482 | ||
| 2473 | /* Forwarding pointer to an int variable. | 2483 | /* Forwarding pointer to an int variable. |
| @@ -2672,11 +2682,6 @@ enum char_bits | |||
| 2672 | /* Data type checking. */ | 2682 | /* Data type checking. */ |
| 2673 | 2683 | ||
| 2674 | INLINE bool | 2684 | INLINE bool |
| 2675 | FIXED_OR_FLOATP (Lisp_Object x) | ||
| 2676 | { | ||
| 2677 | return FIXNUMP (x) || FLOATP (x); | ||
| 2678 | } | ||
| 2679 | INLINE bool | ||
| 2680 | FIXNATP (Lisp_Object x) | 2685 | FIXNATP (Lisp_Object x) |
| 2681 | { | 2686 | { |
| 2682 | return FIXNUMP (x) && 0 <= XFIXNUM (x); | 2687 | return FIXNUMP (x) && 0 <= XFIXNUM (x); |
| @@ -2831,12 +2836,6 @@ XFLOATINT (Lisp_Object n) | |||
| 2831 | } | 2836 | } |
| 2832 | 2837 | ||
| 2833 | INLINE void | 2838 | INLINE void |
| 2834 | CHECK_FIXNUM_OR_FLOAT (Lisp_Object x) | ||
| 2835 | { | ||
| 2836 | CHECK_TYPE (FIXED_OR_FLOATP (x), Qnumberp, x); | ||
| 2837 | } | ||
| 2838 | |||
| 2839 | INLINE void | ||
| 2840 | CHECK_NUMBER (Lisp_Object x) | 2839 | CHECK_NUMBER (Lisp_Object x) |
| 2841 | { | 2840 | { |
| 2842 | CHECK_TYPE (NUMBERP (x), Qnumberp, x); | 2841 | CHECK_TYPE (NUMBERP (x), Qnumberp, x); |
| @@ -2848,14 +2847,6 @@ CHECK_INTEGER (Lisp_Object x) | |||
| 2848 | CHECK_TYPE (INTEGERP (x), Qnumberp, x); | 2847 | CHECK_TYPE (INTEGERP (x), Qnumberp, x); |
| 2849 | } | 2848 | } |
| 2850 | 2849 | ||
| 2851 | #define CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER(x) \ | ||
| 2852 | do { \ | ||
| 2853 | if (MARKERP (x)) \ | ||
| 2854 | XSETFASTINT (x, marker_position (x)); \ | ||
| 2855 | else \ | ||
| 2856 | CHECK_TYPE (FIXED_OR_FLOATP (x), Qnumber_or_marker_p, x); \ | ||
| 2857 | } while (false) | ||
| 2858 | |||
| 2859 | #define CHECK_NUMBER_COERCE_MARKER(x) \ | 2850 | #define CHECK_NUMBER_COERCE_MARKER(x) \ |
| 2860 | do { \ | 2851 | do { \ |
| 2861 | if (MARKERP (x)) \ | 2852 | if (MARKERP (x)) \ |
| @@ -3288,6 +3279,8 @@ set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val) | |||
| 3288 | } | 3279 | } |
| 3289 | 3280 | ||
| 3290 | /* Defined in bignum.c. */ | 3281 | /* Defined in bignum.c. */ |
| 3282 | extern intmax_t bignum_to_intmax (Lisp_Object); | ||
| 3283 | extern uintmax_t bignum_to_uintmax (Lisp_Object); | ||
| 3291 | extern Lisp_Object bignum_to_string (Lisp_Object, int); | 3284 | extern Lisp_Object bignum_to_string (Lisp_Object, int); |
| 3292 | extern Lisp_Object make_bignum_str (char const *, int); | 3285 | extern Lisp_Object make_bignum_str (char const *, int); |
| 3293 | extern Lisp_Object double_to_bignum (double); | 3286 | extern Lisp_Object double_to_bignum (double); |
| @@ -3309,16 +3302,6 @@ enum Arith_Comparison { | |||
| 3309 | extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2, | 3302 | extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2, |
| 3310 | enum Arith_Comparison comparison); | 3303 | enum Arith_Comparison comparison); |
| 3311 | 3304 | ||
| 3312 | /* Convert the integer I to an Emacs representation, either the integer | ||
| 3313 | itself, or a cons of two or three integers, or if all else fails a float. | ||
| 3314 | I should not have side effects. */ | ||
| 3315 | #define INTEGER_TO_CONS(i) \ | ||
| 3316 | (! FIXNUM_OVERFLOW_P (i) \ | ||
| 3317 | ? make_fixnum (i) \ | ||
| 3318 | : EXPR_SIGNED (i) ? intbig_to_lisp (i) : uintbig_to_lisp (i)) | ||
| 3319 | extern Lisp_Object intbig_to_lisp (intmax_t); | ||
| 3320 | extern Lisp_Object uintbig_to_lisp (uintmax_t); | ||
| 3321 | |||
| 3322 | /* Convert the Emacs representation CONS back to an integer of type | 3305 | /* Convert the Emacs representation CONS back to an integer of type |
| 3323 | TYPE, storing the result the variable VAR. Signal an error if CONS | 3306 | TYPE, storing the result the variable VAR. Signal an error if CONS |
| 3324 | is not a valid representation or is out of range for TYPE. */ | 3307 | is not a valid representation or is out of range for TYPE. */ |
| @@ -4473,12 +4456,6 @@ extern void init_system_name (void); | |||
| 4473 | because 'abs' is reserved by the C standard. */ | 4456 | because 'abs' is reserved by the C standard. */ |
| 4474 | #define eabs(x) ((x) < 0 ? -(x) : (x)) | 4457 | #define eabs(x) ((x) < 0 ? -(x) : (x)) |
| 4475 | 4458 | ||
| 4476 | /* Return a fixnum or float, depending on whether the integer VAL fits | ||
| 4477 | in a Lisp fixnum. */ | ||
| 4478 | |||
| 4479 | #define make_fixnum_or_float(val) \ | ||
| 4480 | (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_fixnum (val)) | ||
| 4481 | |||
| 4482 | /* SAFE_ALLOCA normally allocates memory on the stack, but if size is | 4459 | /* SAFE_ALLOCA normally allocates memory on the stack, but if size is |
| 4483 | larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */ | 4460 | larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack. */ |
| 4484 | 4461 | ||