summaryrefslogtreecommitdiff
path: root/src/fns.c
Commit message (Collapse)AuthorAgeFilesLines
* Special-case symbol and fixnum keys in member, assoc and rassocMattias Engdegård2020-07-081-0/+14
| | | | | | * src/fns.c (Fmember, Fassoc, Frassoc): Delegate to the cheaper Fmemq, Fassq and Frassq for arguments of the appropriate types. (eq_comparable_value): New function.
* MS-Windows fixes as followup to import of Gnulib 'getrandom'Eli Zaretskii2020-06-281-4/+0
| | | | | | | | | | | * nt/mingw-cfg.site (gl_cv_lib_assume_bcrypt): Set to "no" to disable linking against bcrypt.dll. (Bug#42095) * src/gnutls.c (gnutls_rnd) [WINDOWSNT]: Don't define a function pointer, and don't load it from GnuTLS DLL. (w32_gnutls_rnd) [WINDOWSNT]: Delete unused function. * src/fns.c (gnutls_rnd) [WINDOWSNT]: Don't redirect to w32_gnutls_rnd.
* Use getrandom syscall for noncesPaul Eggert2020-06-271-5/+10
| | | | | | | | | | | | | | | | * admin/merge-gnulib (GNULIB_MODULES): Add getrandom. * doc/lispref/text.texi (Format of GnuTLS Cryptography Inputs): Don’t say that iv-auto uses GNUTLS_RND_NONCE. Also, don’t say that it returns the IV’s actual value, as it never has done that. * src/fns.c, src/sysdep.c: Include sys/random.h, for getrandom. * src/fns.c (Fsecure_hash_algorithms): Use getrandom so that this function does not depend on HAVE_GNUTLS3. * src/sysdep.c: Do not include <gnutls/crypto.h>. (random_seed) [HAVE_LRAND48]: Can be long int now. (init_random) [!WINDOWSNT]: Use getrandom syscall instead of opening /dev/urandom, as this works even on GNU/Linux hosts that lack /dev/urandom. Don’t bother with gnutls_rnd as it’s not needed now that we have getrandom.
* Reject attempts to clear pure stringsPaul Eggert2020-05-181-19/+32
| | | | | | * src/fns.c (Ffillarray, Fclear_string): Add CHECK_IMPURE here, to be consistent with Faset etc. (Ffillarray): Prefer memset when the fill is a single byte.
* Pacify GCC 10.1.0Paul Eggert2020-05-111-1/+1
| | | | | | | | | | | | | | | | | Pacify GCC 10.1.0 so that it does not issue false alarms when Emacs is configured with --enable-gcc-warnings. * src/dispnew.c (clear_glyph_row): * src/fns.c (hash_clear): * src/keyboard.c (append_tab_bar_item): * src/lisp.h (vcopy): * src/xfaces.c (get_lface_attributes_no_remap) (Finternal_copy_lisp_face, realize_default_face): * src/xmenu.c (set_frame_menubar): Work around -Warray-bounds false alarm in GCC 10.1.0. * src/intervals.c (copy_properties): Avoid -Wnull-dereference false alarm in GCC 10.1.0. * src/lisp.h (xvector_contents_addr, xvector_contents): New functions, useful for working around GCC bug 95072.
* Merge from origin/emacs-27Glenn Morris2020-05-031-28/+28
|\ | | | | | | | | | | 1f17193e00 Expand file name for remote dirs as well 7a12ab5ea2 Fix project.el commands in "transient" projects 274ec97e3c Make sure alist-related functions say so in their doc
| * Make sure alist-related functions say so in their docEli Zaretskii2020-04-291-28/+28
| | | | | | | | | | * src/fns.c (Fassq, assq_no_quit, Fassoc, assoc_no_quit, Frassq) (Frassoc): Rename argument LIST to ALIST. Doc strings updated.
* | Port recent character.h changes to --with-wide-intPaul Eggert2020-04-171-14/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/fns.c (mapcar1): * src/keymap.c (Fkey_description): * src/syntax.c (scan_lists): Prefer ptrdiff_t to EMACS_INT where either will do; this fixes newly-introduced type errors on --with-wide-int platforms where ptrdiff_t is narrower than EMACS_INT. * src/keymap.c (Fkey_description): Rework for clarity; remove goto. * src/syntax.c (scan_words, Fforward_comment, scan_lists)): Fix unlikely integer overflow problems that can occur on --with-wide-int platforms, and that were caught by the recent character.h changes.
* | Prefer more inline functions in character.hPaul Eggert2020-04-171-34/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/buffer.h (fetch_char_advance, fetch_char_advance_no_check) (buf_next_char_len, next_char_len, buf_prev_char_len) (prev_char_len, inc_both, dec_both): New inline functions, replacing the old character.h macros FETCH_CHAR_ADVANCE, FETCH_CHAR_ADVANCE_NO_CHECK, BUF_INC_POS, INC_POS, BUF_DEC_POS, DEC_POS, INC_BOTH, DEC_BOTH respectively. All callers changed. These new functions all assume buffer primitives and so need to be here rather than in character.h. * src/casefiddle.c (make_char_unibyte): New static function, replacing the old MAKE_CHAR_UNIBYTE macro. All callers changed. (do_casify_unibyte_string): Use SINGLE_BYTE_CHAR_P instead of open-coding it. * src/ccl.c (GET_TRANSLATION_TABLE): New static function, replacing the old macro of the same name. * src/character.c (string_char): Omit 2nd arg. 3rd arg can no longer be NULL. All callers changed. * src/character.h (SINGLE_BYTE_CHAR_P): Move up. (MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE, PREV_CHAR_BOUNDARY) (STRING_CHAR_AND_LENGTH, STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE) (FETCH_STRING_CHAR_ADVANCE_NO_CHECK, FETCH_CHAR_ADVANCE) (FETCH_CHAR_ADVANCE_NO_CHECK, INC_POS, DEC_POS, INC_BOTH) (DEC_BOTH, BUF_INC_POS, BUF_DEC_POS): Remove. (make_char_multibyte): New static function, replacing the old macro MAKE_CHAR_MULTIBYTE. All callers changed. (CHAR_STRING_ADVANCE): Remove; all callers changed to use CHAR_STRING. (NEXT_CHAR_BOUNDARY): Remove; it was unused. (raw_prev_char_len): New inline function, replacing the old PREV_CHAR_BOUNDARY macro. All callers changed. (string_char_and_length): New inline function, replacing the old STRING_CHAR_AND_LENGTH macro. All callers changed. (STRING_CHAR): Rewrite in terms of string_char_and_length. (string_char_advance): New inline function, replacing the old STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_advance): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_as_multibyte_advance): New inline function, replacing the old FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE macro. All callers changed. (fetch_string_char_advance_no_check): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE_NO_CHECK macro. All callers changed. * src/regex-emacs.c (HEAD_ADDR_VSTRING): Remove; no longer used. * src/syntax.c (scan_lists): Use dec_bytepos instead of open-coding it. * src/xdisp.c (string_char_and_length): Rename from string_char_and_length to avoid name conflict with new function in character.h. All callers changed.
* | Prefer inline functions in character.hPaul Eggert2020-04-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In character.h, replace macros with inline functions or enums when this is easy. This improves maintainability and on my platform (Fedora 31 x86-64, gcc -O2) improved CPU performance very slightly (0.3%) on ‘make compile-always’. * src/buffer.h (SANE_TAB_WIDTH, CHARACTER_WIDTH): Move here from character.h, and make them inline functions. Tune CHARACTER_WIDTH so that ASCII_CHAR_WIDTH is no longer needed. (sanitize_tab_width, sanitize_char_width): Move here from character.h. * src/character.h (MAX_CHAR, MAX_UNICODE_CHAR, MAX_1_BYTE_CHAR) (MAX_2_BYTE_CHAR, MAX_3_BYTE_CHAR, MAX_4_BYTE_CHAR) (MAX_5_BYTE_CHAR, MIN_MULTIBYTE_LEADING_CODE) (MAX_MULTIBYTE_LEADING_CODE, MAX_MULTIBYTE_LENGTH): Now enum constants instead of macros. * src/character.h (CHAR_BYTES): Redo to avoid conditional branches. (CHAR_BYTE8_P, BYTE8_TO_CHAR, UNIBYTE_TO_CHAR, CHAR_TO_BYTE8) (CHAR_TO_BYTE_SAFE, CHAR_BYTE8_HEAD_P, CHARACTERP) (CHECK_CHARACTER, CHECK_CHARACTER_CAR, CHECK_CHARACTER_CDR) (CHAR_PRINTABLE_P, CHAR_BYTES, CHAR_LEADING_CODE, BYTE8_STRING) (LEADING_CODE_P, TRAILING_CODE_P, CHAR_HEAD_P) (BYTES_BY_CHAR_HEAD): Now inline functions instead of macros. (ASCII_CHAR_WIDTH): Remove; no longer used. * src/conf_post.h (ATTRIBUTE_PURE): New macro. * src/lisp.h (char_table_ref): Use it, for better inlining. * src/fns.c (base64_decode_1): Add now-necessary casts.
* | Treat out-of-range positions consistentlyPaul Eggert2020-03-271-16/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a position argument to get-byte etc. is an out-of-range integer, treat it the same regardless of whether it is a fixnum or a bignum. * src/buffer.c (fix_position): New function. * src/buffer.c (validate_region): * src/character.c (Fget_byte): * src/coding.c (Ffind_coding_systems_region_internal) (Fcheck_coding_systems_region): * src/composite.c (Ffind_composition_internal): * src/editfns.c (Fposition_bytes, Fchar_after, Fchar_before) (Finsert_buffer_substring, Fcompare_buffer_substrings) (Fnarrow_to_region): * src/fns.c (Fsecure_hash_algorithms): * src/font.c (Finternal_char_font, Ffont_at): * src/fringe.c (Ffringe_bitmaps_at_pos): * src/search.c (search_command): * src/textprop.c (get_char_property_and_overlay): * src/window.c (Fpos_visible_in_window_p): * src/xdisp.c (Fwindow_text_pixel_size): Use it instead of CHECK_FIXNUM_COERCE_MARKER, so that the code is simpler and treats bignums consistently with fixnums. * src/buffer.h (CHECK_FIXNUM_COERCE_MARKER): Define here rather than in lisp.h, and reimplement in terms of fix_position so that it treats bignums consistently with fixnums. * src/lisp.h (CHECK_FIXNUM_COERCE_MARKER): Move to buffer.h. * src/textprop.c (validate_interval_range): Signal with original bounds rather than modified ones.
* | Avoid unlikely load-average bugPaul Eggert2020-02-171-1/+1
| | | | | | | | | | * src/fns.c (Fload_average): Do not crash or return nonsense if the load average exceeds most-positive-fixnum/100 (Bug#39577).
* | * src/fns.c (sxhash_obj): Fix crash on sub-char-tablesStefan Monnier2020-01-181-38/+31
| | | | | | | | | | | | Also, look inside overlays, like `internal_equal`. (internal_equal): Cosmetic tweak.
* | Fix sxhash-equal on bytecodes, markers, etc.Paul Eggert2020-01-071-21/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem reported by Pip Cet (Bug#38912#14). * doc/lispref/objects.texi (Equality Predicates): Document better when ‘equal’ looks inside objects. * doc/lispref/windows.texi (Window Configurations): Don’t say that ‘equal’ looks inside window configurations. * etc/NEWS: Mention the change. * src/fns.c (internal_equal): Do not look inside window configurations. (sxhash_obj): Hash markers, byte-code function objects, char-tables, and font objects consistently with Fequal. * src/window.c (compare_window_configurations): Now static. Remove last argument. Caller changed. * test/lisp/ffap-tests.el (ffap-other-window--bug-25352): Use compare-window-configurations, not ‘equal’. * test/src/fns-tests.el (test-sxhash-equal): New test.
* | Help the compiler inline sxhashPaul Eggert2020-01-071-6/+13
|/ | | | | | | * src/fns.c (sxhash_obj): Rename from sxhash and make it static, so that the compiler can inline it better. (sxhash): New function that does not take a depth arg. All callers changed.
* Update copyright year to 2020Paul Eggert2020-01-011-1/+1
| | | | Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
* Clarify base64 requirements and say what {en,de}code_coding_region doesLars Ingebrigtsen2019-12-241-2/+14
| | | | | | | | | | * src/coding.c (Fencode_coding_region): Clarify what this does. (Fdecode_coding_region): Ditto. * src/fns.c (Fbase64_decode_region): Clarify that this function returns bytes, not text (bug#38587). (Fbase64_encode_region): Clarify that this function takes bytes, not text.
* Allow recursive minibuffers for yes-or-no-p and y-or-n-p (bug#17272 bug#19064)Juri Linkov2019-11-271-2/+5
| | | | | | * lisp/subr.el (y-or-n-p): Let-bind enable-recursive-minibuffers to t. * src/fns.c (Fyes_or_no_p): Specbind Qenable_recursive_minibuffers to Qt.
* Add/fix documentation for widget-applyJuanma Barranquero2019-10-161-0/+1
| | | | | | | * doc/misc/widget.texi (Widget Properties): Document `widget-apply'. * src/fns.c (Fwidget_apply): Document return value (used in many places).
* identity, ignore: Make arg names more consistent with docsJuanma Barranquero2019-10-101-3/+3
| | | | | | | | * lisp/subr.el (ignore): Rename argument IGNORE to ARGUMENTS. * src/fns.c (Fidentity): Rename ARG to ARGUMENT. * doc/lispref/functions.texi (Calling Functions): Fix references.
* * src/fns.c (Flocale_info): Avoid fixnum overflow under ASan.Philipp Stephani2019-10-051-2/+8
|
* Add tests for secure-hash and improve doc string (Bug#37420)Stefan Kangas2019-10-041-2/+7
| | | | | | * src/fns.c (Fsecure_hash_algorithms): Fix typo. (Fsecure_hash): Add algorithm list to doc string. * test/src/fns-tests.el (test-secure-hash): New test.
* * src/fns.c (Fbuffer_hash): Improve doc string.Stefan Kangas2019-09-221-1/+8
|
* Recommend against SHA-1 and MD5 for securityStefan Kangas2019-09-201-2/+9
| | | | | | | | * doc/lispref/text.texi (Checksum/Hash): * src/fns.c (Fmd5, Fsecure_hash): * lisp/subr.el (sha1): Doc fix to recommend against SHA-1 and MD5 for security-related applications, since they are not collision resistant. (Bug#37420)
* Remove obsolete Lint directivesPaul Eggert2019-09-161-3/+0
| | | | | | | | | | | | | Most of the directives were wrong anyway. Apparently traditional lint hasn’t been used to check Emacs for years. * src/callint.c (Finteractive): * src/cm.c (evalcost): * src/emacs.c (main): * src/eval.c (call1, call2, call3, call4, call5, call6, call7, call8): * src/fns.c (concat2, concat3, nconc2): * src/term.c (calculate_ins_del_char_costs): Omit ARGSUSED comments. * src/eval.c (call1): Omit VARARGS comment.
* extern function cleanupPaul Eggert2019-08-241-17/+15
| | | | | | | | | | | | | Most of these functions can be static. A few are unused. * src/coding.c (encode_string_utf_8, decode_string_utf_8): Define only if ENABLE_UTF_8_CONVERTER_TEST, as they're not needed otherwise. * src/coding.c (encode_string_utf_8, decode_string_utf_8): * src/data.c (integer_mod): * src/fns.c (base64_encode_region_1, base64_encode_string_1): * src/ftfont.c (ftfont_get_fc_charset): Now static. * src/sysdep.c (verrprintf): Remove; unused.
* Fix Qunbound-Qnil confusion in clrhash patchPaul Eggert2019-08-221-2/+5
| | | | | | Problem reported by Stefan Monnier. * src/fns.c (hash_clear): Fix typo I introduced in my previous patch here, by setting keys to Qunbound not Qnil.
* Fix clrhash bug when hash table needs rehashingPaul Eggert2019-08-211-16/+12
| | | | | | | | | | | | Problem reported by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2019-08/msg00316.html * src/fns.c (maybe_resize_hash_table): Prefer ASET to gc_aset where either will do. Simplify appending of Qunbound values. Put index_size calculation closer to where it’s needed. (hash_clear): If hash_rehash_needed_p (h), don’t clear the nonexistent hash vector. Use memclear to speed up clearing. * src/lisp.h (HASH_TABLE_SIZE): Check that the size is positive, and tell that to the compiler.
* Don’t hard-loop on cycles in ‘read’ etc.Paul Eggert2019-08-211-3/+6
| | | | | | | | | | | | | | | Problem for ‘read’ reported by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2019-08/msg00316.html * src/fns.c (Frequire): Protect against circular current-load-list. * src/lread.c (Fget_load_suffixes): Protect against circular load-suffixes or load-file-rep-suffixes. (Fload): Protect against circular loads-in-progress. (openp): Protect against circular PATH and SUFFIXES. (build_load_history): Protect against circular load-history or current-load-list. (readevalloop_eager_expand_eval): Protect against circular SUBFORMS. (read1): Protect against circular data. * test/src/lread-tests.el (lread-circular-hash): New test.
* Be more careful about pointers to bignum valsPaul Eggert2019-08-211-11/+11
| | | | | | | | | | | | | | | This uses ‘const’ to be better at catching bugs that mistakenly attempt to modify a bignum value. Lisp bignums are supposed to be immutable. * src/alloc.c (make_pure_bignum): * src/fns.c (sxhash_bignum): Accept Lisp_Object instead of struct Lisp_Bignum *, as that’s simpler now. Caller changed. * src/bignum.h (bignum_val, xbignum_val): New inline functions. Prefer them to &i->value and XBIGNUM (i)->value, since they apply ‘const’ to the result. * src/timefns.c (lisp_to_timespec): Use mpz_t const * to point to a bignum value.
* Debug out-of-range make_fixnum argsPaul Eggert2019-08-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | With --enable-checking, make_fixnum (N) now checks that N is in fixnum range. Suggested by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2019-07/msg00548.html A new function make_ufixnum (N) is for the rare cases where N is intended to be unsigned and is in the range 0..INTMASK. * configure.ac (AC_C_TYPEOF): Add. (HAVE_STATEMENT_EXPRESSIONS): Resurrect this macro. * src/fns.c (Frandom, hashfn_eq, hashfn_equal, hashfn_user_defined): * src/profiler.c (hashfn_profiler): Use make_ufixnum rather than make_fixum, since the argument is an unsigned integer in the range 0..INTMASK rather than a signed integer in the range MOST_NEGATIVE_FIXNUM..MOST_POSITIVE_FIXNUM. Typically this is for hashes. * src/lisp.h (lisp_h_make_fixnum_wrap) [USE_LSB_TAG]: Rename from lisp_h_make_fixnum. (lisp_h_make_fixnum): Redefine in terms of lisp_h_make_fixnum_wrap. Check for fixnum overflow on compilers like GCC that have statement expressions and typeof. (FIXNUM_OVERFLOW_P): Move up. (make_fixnum): Check for fixnum overflow. (make_ufixnum): New function, which checks that the arg fits into 0..INTMASK range.
* Don't dump the `hash` vector if it will need to be recomputed anywayStefan Monnier2019-07-261-7/+8
| | | | | | | | | | | * src/fns.c (hash_table_rehash): Only set `hash` field at the end. (sweep_weak_table): Only set slot of `hash` vector when that vector exists. (Fhash_table_count): No need to hash_rehash_if_needed any more. * src/lisp.h (hash_rehash_needed_p): Test the presence of `hash` instead. * src/pdumper.c (check_hash_table_rehash, dump_hash_table): Set `hash` to nil to indicate that the table needs to be rehashed.
* * src/fns.c: Use `EQ (key, Qunbound)` to check if a slot is in useStefan Monnier2019-07-261-16/+29
| | | | | | | | | | | | | | (make_hash_table): Use Qunbound for the key_and_value table. (maybe_resize_hash_table): Set new key_and_value slots to Qunbound. (hash_table_rehash): Don't bother copying the old table of hashes since we're recomputing it completely. (hash_table_rehash): Use hash_rehash_needed_p more. (hash_put): Add assertion that the slot was indeed considered empty. (hash_remove_from_table, hash_clear, sweep_weak_table): Set empty slot's key to Qunbound. (Fmaphash): Use `EQ (key, Qunbound)` to check if a slot is in use. * src/lisp.h (struct Lisp_Hash_Table): Update comments.
* * src/fns.c (hash_index_size): New function, extracted from make_hash_tableStefan Monnier2019-07-261-18/+15
| | | | | | (make_hash_table, maybe_resize_hash_table): Use it. * src/pdumper.c (check_hash_table_rehash): Use hash_rehash_needed_p.
* * src/fns.c (maybe_resize_hash_table): Obey rehash_size (bug#25743)Stefan Monnier2019-07-261-1/+1
|
* * src/fns.c (hashfn_user_defined): Make sure we always return a fixnum.Stefan Monnier2019-07-231-1/+1
|
* Avoid overexposing fixnums for hash codesPaul Eggert2019-07-221-5/+7
| | | | | | | | | | | | | | Following a suggestion by Stefan Monnier in: https://lists.gnu.org/r/emacs-devel/2019-07/msg00530.html * doc/lispref/hash.texi (Creating Hash, Defining Hash): * src/fns.c (Fsxhash_eq, Fsxhash_eql, Fsxhash_equal, Fmake_hash_table): Don’t insist that hash codes be fixnums, reverting the recent doc changes to the contrary. * src/bytecode.c (exec_byte_code): Special-case only the eq case, as the others aren’t worth tuning now that we treat bignum hashes like fixnums. * src/fns.c (hashfn_user_defined): If the hash code is a bignum, reduce its hash down to a fixnum.
* Do not pdump user-defined hashtabsPaul Eggert2019-07-221-1/+1
| | | | | | * src/pdumper.c (dump_hash_table_stable_p): Signal an error if a hash table has user-defined tests (Bug#36769). * src/fns.c (hashfn_user_defined): Now extern.
* Avoid integer overflow in hash table sizePaul Eggert2019-07-211-6/+13
| | | | | | | | | * src/fns.c (INDEX_SIZE_BOUND): Use a tighter bound. (maybe_resize_hash_table): Avoid integer overflow when checking for hash table size overflow. Fix confusion between INDEX_SIZE_BOUND (which is for the index vector) and hash table size. Fix typo in debugging message when ENABLE_CHECKING.
* Improve doc for hash tablesPaul Eggert2019-07-211-4/+4
| | | | | | | | | | | * doc/lispref/hash.texi (Creating Hash, Defining Hash): * src/fns.c (Fsxhash_eq, Fsxhash_eql, Fsxhash_equal): Say that hashes are fixnums. (Fmake_hash_table): Say that that an integer rehash-size should be a fixnum. * doc/lispref/hash.texi (Defining Hash): Say that hash and comparison functions should be consistent and pure, and should return quickly.
* Tweak recent hash-table fixPaul Eggert2019-07-201-15/+12
| | | | | | | | * src/fns.c (maybe_resize_hash_table): Completely initialize the new ‘next’ vector before allocating more vectors, as this preserves locality a bit better and it’s safer not to leave an uninitialized Lisp object around. Use next_size instead of new_size to compute new index size.
* Fix crash if user test munges hash tablePaul Eggert2019-07-201-19/+55
| | | | | | | | | | | | | | | | | * src/fns.c (restore_mutability) (hash_table_user_defined_call): New functions. (cmpfn_user_defined, hashfn_user_defined): Use them. (make_hash_table, copy_hash_table): Mark new hash table as mutable. (check_mutable_hash_table): New function. (Fclrhash, Fputhash, Fremhash): Use it instead of CHECK_IMPURE. * src/lisp.h (struct hash_table_test): User-defined functions now take pointers to struct Lisp_Hash_Table, not to struct hash_table_test. All uses changed. (struct Lisp_Hash_Table): New member ‘mutable’. * src/pdumper.c (dump_hash_table): Copy it. * test/src/fns-tests.el (test-hash-function-that-mutates-hash-table): New test, which tests for the bug.
* Simplify hashfn/cmpfn calling conventionPaul Eggert2019-07-201-58/+45
| | | | | | | | | | | | | | | | * src/fns.c (cmpfn_eql, cmpfn_equal, cmpfn_user_defined) (hashfn_eq, hashfn_equal, hashfn_eql, hashfn_user_defined): * src/profiler.c (cmpfn_profiler, hashfn_profiler): Use new calling convention where the return value is a fixnum instead of EMACS_UINT. While we’re at it, put the hash table at the end, since that’s a bit simpler and generates better code (at least on the x86-64). All callers changed. * src/fns.c (hash_lookup): Store fixnum rather than EMACS_UINT. All callers changed. (hash_put): Take a fixnum rather than an EMACS_UINT. All callers changed. Remove unnecessary eassert (XUFIXNUM does it). * src/lisp.h (struct hash_table_test): Adjust signatures of cmpfn and hashfn.
* Rename ‘pure’ to ‘purecopy’Paul Eggert2019-07-201-5/+5
| | | | | | * src/lisp.h (struct Lisp_Hash_Table): Rename ‘pure’ member to ‘purecopy’, as the old name was quite confusing (it did not mean the hash table was pure). All uses changed.
* Fix hash table overallocation etc.Paul Eggert2019-07-201-58/+29
| | | | | | | | | | | * src/fns.c (set_hash_key_and_value, set_hash_next) (set_hash_hash, set_hash_index): Remove. All uses removed. (maybe_resize_hash_table): Don’t update h->next until it’s known that all the allocations succeeded, to avoid trashing the hash table if memory is exhausted. Don’t overallocate the other vectors. Don’t output growth message if the hash table didn’t actually grow due to allocation failure. Assume C99 decls after statements.
* ; Add comment to hash_table_rehash (Bug#36447)Stefan Monnier2019-07-141-0/+5
| | | | | | * src/fns.c (hash_table_rehash): Add a comment to explain that hash_table_rehash is not used in "normal" rehashing, but only in the rare case of rehashing on the first access to a preloaded hash-table.
* Avoid returning negative numbers from `hash-table-count'Pip Cet2019-07-131-1/+3
| | | | * src/fns.c (Fhash_table_count): Rehash argument if necessary.
* Avoid interleaving stderr in dump_fingerprintPaul Eggert2019-07-131-5/+14
| | | | | | | | * src/fns.c (hexbuf_digest): New function, containing most of the old make_digest_string. (make_digest_string): Use it. * src/pdumper.c (dump_fingerprint): Rewrite to use a single fprintf call, to avoid interleaving on GNU/Linux.
* plist-get/lax-plist-get doc fixLars Ingebrigtsen2019-07-131-7/+9
| | | | | | * src/fns.c (Fplist_get): Mention that comparison is done with eq (bug#31441). (Flax_plist_get): Refer to plist-get for details.
* Avoid duplicate comparison in describe_map_comparePaul Eggert2019-07-111-5/+15
| | | | | | | | * src/fns.c (string_version_cmp): New function. This has most of the old Fstring_version_lessp, with an assertion to make things a bit clearer. * src/fns.c (Fstring_version_lessp): * src/keymap.c (describe_map_compare): Use it (Bug#33237).