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/dbusbind.c | |
| 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/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index fe92d3997bd..47346a7d4d4 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -378,7 +378,7 @@ xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) | |||
| 378 | case DBUS_TYPE_INT32: | 378 | case DBUS_TYPE_INT32: |
| 379 | case DBUS_TYPE_INT64: | 379 | case DBUS_TYPE_INT64: |
| 380 | case DBUS_TYPE_DOUBLE: | 380 | case DBUS_TYPE_DOUBLE: |
| 381 | CHECK_FIXNUM_OR_FLOAT (object); | 381 | CHECK_NUMBER (object); |
| 382 | sprintf (signature, "%c", dtype); | 382 | sprintf (signature, "%c", dtype); |
| 383 | break; | 383 | break; |
| 384 | 384 | ||
| @@ -519,13 +519,13 @@ xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) | |||
| 519 | static intmax_t | 519 | static intmax_t |
| 520 | xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | 520 | xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) |
| 521 | { | 521 | { |
| 522 | CHECK_FIXNUM_OR_FLOAT (x); | 522 | CHECK_NUMBER (x); |
| 523 | if (FIXNUMP (x)) | 523 | if (FIXNUMP (x)) |
| 524 | { | 524 | { |
| 525 | if (lo <= XFIXNUM (x) && XFIXNUM (x) <= hi) | 525 | if (lo <= XFIXNUM (x) && XFIXNUM (x) <= hi) |
| 526 | return XFIXNUM (x); | 526 | return XFIXNUM (x); |
| 527 | } | 527 | } |
| 528 | else | 528 | else if (FLOATP (x)) |
| 529 | { | 529 | { |
| 530 | double d = XFLOAT_DATA (x); | 530 | double d = XFLOAT_DATA (x); |
| 531 | if (lo <= d && d < 1.0 + hi) | 531 | if (lo <= d && d < 1.0 + hi) |
| @@ -535,25 +535,30 @@ xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | |||
| 535 | return n; | 535 | return n; |
| 536 | } | 536 | } |
| 537 | } | 537 | } |
| 538 | else if (! (MOST_NEGATIVE_FIXNUM <= lo && hi <= MOST_POSITIVE_FIXNUM)) | ||
| 539 | { | ||
| 540 | intmax_t i = bignum_to_intmax (x); | ||
| 541 | if (i != 0 && lo <= i && i <= hi) | ||
| 542 | return i; | ||
| 543 | } | ||
| 544 | |||
| 538 | if (xd_in_read_queued_messages) | 545 | if (xd_in_read_queued_messages) |
| 539 | Fthrow (Qdbus_error, Qnil); | 546 | Fthrow (Qdbus_error, Qnil); |
| 540 | else | 547 | else |
| 541 | args_out_of_range_3 (x, | 548 | args_out_of_range_3 (x, INT_TO_INTEGER (lo), INT_TO_INTEGER (hi)); |
| 542 | make_fixnum_or_float (lo), | ||
| 543 | make_fixnum_or_float (hi)); | ||
| 544 | } | 549 | } |
| 545 | 550 | ||
| 546 | /* Convert X to an unsigned integer with bounds 0 and HI. */ | 551 | /* Convert X to an unsigned integer with bounds 0 and HI. */ |
| 547 | static uintmax_t | 552 | static uintmax_t |
| 548 | xd_extract_unsigned (Lisp_Object x, uintmax_t hi) | 553 | xd_extract_unsigned (Lisp_Object x, uintmax_t hi) |
| 549 | { | 554 | { |
| 550 | CHECK_FIXNUM_OR_FLOAT (x); | 555 | CHECK_NUMBER (x); |
| 551 | if (FIXNUMP (x)) | 556 | if (FIXNUMP (x)) |
| 552 | { | 557 | { |
| 553 | if (0 <= XFIXNUM (x) && XFIXNUM (x) <= hi) | 558 | if (0 <= XFIXNUM (x) && XFIXNUM (x) <= hi) |
| 554 | return XFIXNUM (x); | 559 | return XFIXNUM (x); |
| 555 | } | 560 | } |
| 556 | else | 561 | else if (FLOATP (x)) |
| 557 | { | 562 | { |
| 558 | double d = XFLOAT_DATA (x); | 563 | double d = XFLOAT_DATA (x); |
| 559 | if (0 <= d && d < 1.0 + hi) | 564 | if (0 <= d && d < 1.0 + hi) |
| @@ -563,10 +568,17 @@ xd_extract_unsigned (Lisp_Object x, uintmax_t hi) | |||
| 563 | return n; | 568 | return n; |
| 564 | } | 569 | } |
| 565 | } | 570 | } |
| 571 | else if (! (hi <= MOST_POSITIVE_FIXNUM)) | ||
| 572 | { | ||
| 573 | uintmax_t i = bignum_to_uintmax (x); | ||
| 574 | if (i != 0 && i <= hi) | ||
| 575 | return i; | ||
| 576 | } | ||
| 577 | |||
| 566 | if (xd_in_read_queued_messages) | 578 | if (xd_in_read_queued_messages) |
| 567 | Fthrow (Qdbus_error, Qnil); | 579 | Fthrow (Qdbus_error, Qnil); |
| 568 | else | 580 | else |
| 569 | args_out_of_range_3 (x, make_fixnum (0), make_fixnum_or_float (hi)); | 581 | args_out_of_range_3 (x, make_fixnum (0), INT_TO_INTEGER (hi)); |
| 570 | } | 582 | } |
| 571 | 583 | ||
| 572 | /* Append C value, extracted from Lisp OBJECT, to iteration ITER. | 584 | /* Append C value, extracted from Lisp OBJECT, to iteration ITER. |
| @@ -848,7 +860,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) | |||
| 848 | dbus_message_iter_get_basic (iter, &val); | 860 | dbus_message_iter_get_basic (iter, &val); |
| 849 | pval = val; | 861 | pval = val; |
| 850 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); | 862 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); |
| 851 | return make_fixnum_or_float (val); | 863 | return INT_TO_INTEGER (val); |
| 852 | } | 864 | } |
| 853 | 865 | ||
| 854 | case DBUS_TYPE_UINT32: | 866 | case DBUS_TYPE_UINT32: |
| @@ -861,7 +873,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) | |||
| 861 | dbus_message_iter_get_basic (iter, &val); | 873 | dbus_message_iter_get_basic (iter, &val); |
| 862 | pval = val; | 874 | pval = val; |
| 863 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); | 875 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); |
| 864 | return make_fixnum_or_float (val); | 876 | return INT_TO_INTEGER (val); |
| 865 | } | 877 | } |
| 866 | 878 | ||
| 867 | case DBUS_TYPE_INT64: | 879 | case DBUS_TYPE_INT64: |
| @@ -871,7 +883,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) | |||
| 871 | dbus_message_iter_get_basic (iter, &val); | 883 | dbus_message_iter_get_basic (iter, &val); |
| 872 | pval = val; | 884 | pval = val; |
| 873 | XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); | 885 | XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); |
| 874 | return make_fixnum_or_float (val); | 886 | return INT_TO_INTEGER (val); |
| 875 | } | 887 | } |
| 876 | 888 | ||
| 877 | case DBUS_TYPE_UINT64: | 889 | case DBUS_TYPE_UINT64: |
| @@ -881,7 +893,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) | |||
| 881 | dbus_message_iter_get_basic (iter, &val); | 893 | dbus_message_iter_get_basic (iter, &val); |
| 882 | pval = val; | 894 | pval = val; |
| 883 | XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); | 895 | XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); |
| 884 | return make_fixnum_or_float (val); | 896 | return INT_TO_INTEGER (val); |
| 885 | } | 897 | } |
| 886 | 898 | ||
| 887 | case DBUS_TYPE_DOUBLE: | 899 | case DBUS_TYPE_DOUBLE: |
| @@ -1454,7 +1466,7 @@ usage: (dbus-message-internal &rest REST) */) | |||
| 1454 | 1466 | ||
| 1455 | /* The result is the key in Vdbus_registered_objects_table. */ | 1467 | /* The result is the key in Vdbus_registered_objects_table. */ |
| 1456 | serial = dbus_message_get_serial (dmessage); | 1468 | serial = dbus_message_get_serial (dmessage); |
| 1457 | result = list3 (QCserial, bus, make_fixnum_or_float (serial)); | 1469 | result = list3 (QCserial, bus, INT_TO_INTEGER (serial)); |
| 1458 | 1470 | ||
| 1459 | /* Create a hash table entry. */ | 1471 | /* Create a hash table entry. */ |
| 1460 | Fputhash (result, handler, Vdbus_registered_objects_table); | 1472 | Fputhash (result, handler, Vdbus_registered_objects_table); |
| @@ -1541,7 +1553,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1541 | || (mtype == DBUS_MESSAGE_TYPE_ERROR)) | 1553 | || (mtype == DBUS_MESSAGE_TYPE_ERROR)) |
| 1542 | { | 1554 | { |
| 1543 | /* Search for a registered function of the message. */ | 1555 | /* Search for a registered function of the message. */ |
| 1544 | key = list3 (QCserial, bus, make_fixnum_or_float (serial)); | 1556 | key = list3 (QCserial, bus, INT_TO_INTEGER (serial)); |
| 1545 | value = Fgethash (key, Vdbus_registered_objects_table, Qnil); | 1557 | value = Fgethash (key, Vdbus_registered_objects_table, Qnil); |
| 1546 | 1558 | ||
| 1547 | /* There shall be exactly one entry. Construct an event. */ | 1559 | /* There shall be exactly one entry. Construct an event. */ |
| @@ -1608,7 +1620,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1608 | event.arg); | 1620 | event.arg); |
| 1609 | event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), | 1621 | event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), |
| 1610 | event.arg); | 1622 | event.arg); |
| 1611 | event.arg = Fcons (make_fixnum_or_float (serial), event.arg); | 1623 | event.arg = Fcons (INT_TO_INTEGER (serial), event.arg); |
| 1612 | event.arg = Fcons (make_fixnum (mtype), event.arg); | 1624 | event.arg = Fcons (make_fixnum (mtype), event.arg); |
| 1613 | 1625 | ||
| 1614 | /* Add the bus symbol to the event. */ | 1626 | /* Add the bus symbol to the event. */ |