Commit graph

50643 commits

Author SHA1 Message Date
Paul Eggert
67ea9485a6 Prefer readlink to lstat in find_emacs_executable
* src/emacs.c (find_emacs_executable): Prefer readlink to lstat
when testing whether a file is a symlink.  This avoids EOVERFLOW
issues.
2025-07-24 22:13:47 -07:00
Paul Eggert
670603533c Fix minor memory leak in find_emacs_executable
* src/emacs.c (find_emacs_executable): Free candidate if unused.
2025-07-24 22:13:47 -07:00
Paul Eggert
e026b57f07 Don’t read before BEG in insert-file-contents
* src/fileio.c (Finsert_file_contents): Don’t sample bytes before BEG.
Give up optimizing if the file size shrinks to less than BEG.
2025-07-23 17:55:15 -07:00
Paul Eggert
4c79154949 Simplify file end finding in insert-file-contents
* src/fileio.c (Finsert_file_contents): Don’t give up finding the
file’s end merely because SEEK_END fails.  Try a small test read
anyway.  This might work in non-POSIX file systems where SEEK_END
is not allowed, and trying is easy and simplifies the code.
2025-07-23 17:55:15 -07:00
Gerd Möllmann
2d1d1f31df NS: Fix build with NSTRACE_ENABLED
* src/nsterm.h (NSTRACE_MSG_NO_DASHES): Use
nstrace_enabled_global.
* src/nsterm.m: ([EmacsView performDragOperation:]): Don't use
an NSString.
2025-07-23 11:59:23 +02:00
Gerd Möllmann
f177537f70 NS: Use different window collection behavior for tooltips (bug#73037)
* src/nsterm.m ([EmacsView updateCollectionBehavior]):
Use NSWindowCollectionBehaviorFullScreenAuxiliary for non-native
tooltips which are not child frames.
2025-07-23 06:26:45 +02:00
Paul Eggert
eb488e1bba insert-file-contents respect END better
This fixes some longstanding bugs, along with bugs recently
introduced as part of fixes for Bug#77315.
* src/fileio.c (Finsert_file_contents): Arrange for END_OFFSET
to never be less than BEG_OFFSET, to simplify the code.
Do not go past END_OFFSET when sampling or optimizing reading.
Avoid a few unnecessary lseeks.
2025-07-21 16:23:18 -07:00
Paul Eggert
8393e469e7 insert-file-contents shrinking Solaris file fix
This is related to recent fixes for Bug#77315.
* src/fileio.c (Finsert_file_contents): Defend against
a file shrinking to be smaller than its initial offset.
This can happen only on platforms like Solaris where
the initial offset can be positive.
2025-07-21 16:23:18 -07:00
Paul Eggert
e879533f4b Refactor insert-file-contents overlap check
* src/fileio.c (Finsert_file_contents):
Simplify and clarify file overlap check.
2025-07-21 16:23:18 -07:00
Paul Eggert
adbae4f92f insert-file-contents refactor xlseek
* src/fileio.c (xlseek): New arg WHENCE.  All uses changed.
This generalizes xlseek and should simplify future changes.
2025-07-21 16:23:18 -07:00
Paul Eggert
d04182d52a Say why quit is captured in insert-file-contents
* src/fileio.c (Finsert_file_contents): Add comment.
2025-07-21 16:23:18 -07:00
Paul Eggert
a8e46f11a8 insert-file-contents read size increase
This increases the max read size from 0.25 to 1 MiB, which is a
bit better for Emacs in my measurements.  The old value was taken
from coreutils, but was for a different purpose.
* src/fileio.c (INSERT_READ_SIZE_MAX): New constant, replacing
IO_BUFSIZE.  All uses changed.
(Finsert_file_contents): Do not use a read buffer that is larger
than INSERT_READ_SIZE_MAX.
2025-07-21 16:23:18 -07:00
Paul Eggert
27e0f0f79b Fix insert-file-contents infloop with unlucky END
This partially reverts 55f41ca3aa,
which was a partial fix for Bug#77315.
* src/fileio.c (Finsert_file_contents): Go back to accepting
partial reads when doing the optimized way when code conversion is
not needed.  This avoids an unlikely bug when END happens to lie
at a buffer boundary, causing an infloop.  For consistency, do the
same when doing code conversion (though there’s no bug in then),
as there’s not a real need for emacs_full_read there either.
2025-07-21 16:23:18 -07:00
Paul Eggert
46314aef87 Refactor by coalescing MAX_RW_COUNT definitions
* src/emacs.c (read_full):
Simplify by assuming MAX_RW_COUNT is defined.
* src/lisp.h (MAX_RW_COUNT): Move here from src/sysdep.c.
* src/pdumper.c (dump_read_all):
Use MAX_RW_COUNT rather than defining our own equivalent.
2025-07-21 16:23:18 -07:00
Paul Eggert
aaf9c5213f insert-file-contents from seekable non-regular
* src/fileio.c (Finsert_file_contents): Be more conservative
when reading from seekable non-regular files when END is given.
The code assumed that in this case, reads would succeed or fail
quickly so there was no need to call internal_condition_case_1.
However, in some cases, e.g., /dev/random, it could take a while.
This fixes a glitch introduced in commit
cb4579ed6b dated 2022-06-11.
2025-07-21 16:23:18 -07:00
Paul Eggert
49ca3a2151 insert-file-contents beware buffer relocation
This fixes a potential (albeit quite unlikely) bug
introduced during recent fixes to Bug#77315.
* src/fileio.c (union read_non_regular.s.inserted):
Bring back this member.
(read_non_regular, Finsert_file_contents): Work in the unlikely
case when internal_condition_case_1 relocates the buffer before
calling read_non_regular.
2025-07-21 16:23:18 -07:00
Paul Eggert
2903b0b92c insert-file-contents 1 KiB seek fix
This improves on recent fixes to Bug#77315.
When sampling the first 1 KiB and last 3 KiB, do not seek before
BEG if given.  Instead, sample starting at BEG, to be consistent
with the non-optimized version.
* src/fileio.c (xlseek): Return POS, for convenience.
(Finsert_file_contents): Sample the first 1 KiB correctly when BEG.
In a CURPOS local, keep track of the input file offset, or for
nonseekable files the number of bytes read, while this value is
important.  This lets us avoid some unnecessary seeks.  Report an
error earlier if the file is not seekable and BEG is nonzero,
to save work and simplify the code.  When sampling, discard less
data, as this is simpler and there’s little point to discarding it.
2025-07-21 16:23:18 -07:00
Paul Eggert
ffe6d33ef4 insert-file-contents seek refactoring
* src/fileio.c (xlseek): New function.
(Finsert_file_contents): Use it instead of doing things by hand.
(write_region): Match diagnostic wording to xlseek’s.
2025-07-21 16:23:17 -07:00
Paul Eggert
5f4b71b0c4 Fix insert-file-contents optimization glitch
This improves on recent fixes to Bug#77315.
* src/fileio.c (Finsert_file_contents): When optimizing
do not seek to 0 if the initial file offset is positive,
as that causes the optimized code to behave differently
from the nonoptimized.
2025-07-21 16:23:17 -07:00
Paul Eggert
1b517a4fe0 insert-file-contents SEEK_END optimization
This improves on recent fixes to Bug#77315.
* src/fileio.c (Finsert_file_contents):
Do not give up on seeking merely because SEEK_END fails.
On some files (/proc/cpuinfo, say) SEEK_END can fail
even though SEEK_SET and SEEK_CUR succeed, and the
code still works in this case.
2025-07-21 16:23:17 -07:00
Paul Eggert
8d83402edc insert-file-contents st_size cleanup
* src/fileio.c (Finsert_file_contents): Store st_size,
not file_size_hint, into current_buffer->modtime_size,
since modtime_size is compared to a later st_size, not
to the actual file size.  Simplify buffer overflow detection
from file size, since this occurred only on regular files.
2025-07-21 16:23:17 -07:00
Mattias Engdegård
f4a9673f61 Speed up unintern, and fix symbol shorthand edge case (bug#79035)
Don't do a full lookup if the argument is a symbol, and only compute the
hash index once.  Fix a bug that occurred when there is another symbol
whose shorthand is equal to the true name of the symbol being removed.

* src/lread.c (Funintern): Rewrite for speed and correctness.
(oblookup_last_bucket_number, oblookup): Remove now unused variable.
* test/src/lread-tests.el (lread-unintern): New test.
2025-07-19 16:48:11 +02:00
Mattias Engdegård
e9deec70da Remove the variable load-convert-to-unibyte
It has been ineffective since 2002.
Suggested by Lynn Winebarger.

* src/lread.c (Fload, readevalloop_1, readevalloop, Feval_buffer)
(Feval_region, syms_of_lread): Remove the variable and its propagation.
* etc/NEWS: Announce.
2025-07-19 15:12:52 +02:00
Alvaro Ramirez
813013691a Add "Send to..." context menu item to mouse.el
* lisp/send-to.el: New package implements sending files/region.

* lisp/mouse.el (context-menu-send-to): Add "Send to..." context menu.

* lisp/term/ns-win.el (ns-send-items): Expose native macOS send API.

* src/nsfns.m (ns-send-items): Implement native macOS sending.

* etc/NEWS: Announce the new feature.
2025-07-19 14:15:55 +02:00
Stefan Monnier
f8b9d80ec6 comp.el: Fix minor corner-case annoyances
* lisp/emacs-lisp/comp.el (comp--native-compile): Avoid `%s`
on objects that may not have names.
* src/data.c (Ffset): Don't compute trampoline for no-op `fset`.
2025-07-17 12:36:57 -04:00
Paul Eggert
15570b7b95 Don’t optimize insert-file-contents for GNU
* src/fileio.c (Finsert_file_contents):
Remove a microoptimization for GNU/Linux and Android.
2025-07-16 23:21:23 -07:00
Paul Eggert
e450a7802c insert-file-contents small gap bug
Problem reported by Zhengyi Fu (Bug#79031).
* src/fileio.c (Finsert_file_contents): Do not read more than
requested, even when the gap is so small that we use a local buffer.
2025-07-16 11:45:23 -07:00
Paul Eggert
92dee45c5e insert-file-contents likely-end memory objects
* src/fileio.c (Finsert_file_contents): Treat memory objects like
regular files when inferring likely end.  Simplify likely end
computation.
2025-07-16 11:45:23 -07:00
Paul Eggert
8a1d368b62 Port insert-file-contents dir behavior to Unix
* src/fileio.c (Finsert_file_contents): Port better to traditional
Unix platforms like Solaris, where in some cases 'read' can
succeed on directories.
2025-07-16 11:45:23 -07:00
Michael Albinus
e4db6aa545 ; * src/xdisp.c: Fix typo. 2025-07-16 08:47:23 +02:00
Paul Eggert
42548c25f7 Fix insert-file-contents overlap check
In commit 61a8ce0280 I mistakenly
focused on overlap in the buffer.  The code also needs to check
for overlap in the inserted file data.
Problem reported by Gerd Möllmann (Bug#79020).
* src/fileio.c (Finsert_file_contents): Prevent overlap in both
the buffer head and tail, and in the inserted file’s head and tail.
Also, shrink the file’s head if the file shrank to be smaller
than its head.
2025-07-15 22:47:16 -07:00
Sean Whitton
a30372f42b ; Fix wording. 2025-07-15 21:58:59 +01:00
Sean Whitton
6ee0093b21 ; Fix recently introduced "ELisp". 2025-07-15 21:57:59 +01:00
Stefan Monnier
c3f3fe136c Add redisplay_counter to catch nested redisplays and abort outer one
The redisplay code is not re-entrant.  To allow running ELisp code
from within redisplay, we have some hacks (e.g. `inhibit-redisplay`)
that try to avoid the resulting breakage.
This commit adds another one of those hacks, which tries
to get closer to the core of the problem, thereby making it "safe"
to override `inhibit-redisplay`, e.g. to debug jit-lock code.

* src/dispextern.h (redisplay_counter): Declare.
* src/xdisp.c (redisplay_counter): Define.
(redisplay_internal) Increment it.
(dsafe__call): Use it, in case `inhibit-redisplay` is overridden.
* src/eval.c (call_debugger): Use it as well to refine the test
we already had.
2025-07-15 13:49:29 -04:00
Po Lu
b2d5e4fe40 Fix the Android port
* src/fileio.c (emacs_full_read): Retype FD param to `emacs_fd'.
(Fcopy_file): Label newsize MAYBE_UNUSED.
2025-07-14 21:41:18 +08:00
Juri Linkov
817f7829f9 * src/xdisp.c (tab-bar-truncate): New variable (bug#78953).
(tab_bar_height): Use it.
2025-07-14 09:43:18 +03:00
Paul Eggert
a8b65860a5 ; Fix indentation. 2025-07-13 21:39:54 -07:00
Paul Eggert
5bce6753e2 Speed up insert-file-contents reads
This change makes insert-file-contents-literally 30% faster on my
platform, when inserting xdisp.c.
* src/fileio.c (READ_BUF_SIZE): Remove, replacing with ...
(IO_BUFSIZE): ... this new constant from Coreutils.
All uses of READ_BUF_SIZE changed to either MAX_ALLOCA or
IO_BUFSIZE.
2025-07-13 21:09:40 -07:00
Paul Eggert
c3f96d20ee Avoid some tiny /proc file reads
* src/fileio.c (union read_non_regular):
New members buf and bufsize replace inserted and trytry.
(read_non_regular): Adjust to this new, simpler interface.
(Finsert_file_contents): If the gap is smaller than read_buf
and we want to read more than the gap, read into read_buf
first, to avoid lots of tiny reads from /proc files.
2025-07-13 21:09:40 -07:00
Paul Eggert
55f41ca3aa insert-file-contents file shrinkage in scanback
* src/fileio.c (emacs_full_read): New function.
(Fcopy_file, Finsert_file_contents): Use it.
(Finsert_file_contents): Check for partial reads when scanning
backwards through the file’s tail, as this indicates the file
shrank while we read it.  Also, use emacs_full_read in other
situations where it’s simpler and should be a bit faster.
2025-07-13 21:09:39 -07:00
Paul Eggert
8ac78986ff int → ptrdiff_t for read results
* src/fileio.c (Finsert_file_contents): Use ptrdiff_t, not int, to
store results returned by emacs_fd_read, which return ptrdiff_t.
This doesn’t fix any bugs since the values happen to fit in int,
but is a bit clearer and may simplify future changes.
2025-07-13 21:09:39 -07:00
Paul Eggert
f4adb56c9a insert-file-contents unexpected end shrinkage
* src/fileio.c (Finsert_file_contents): If the file unexpectedly
shrinks while reading its tail backwards, give up searching for
the match end.
2025-07-13 21:09:39 -07:00
Paul Eggert
c35d09edcf fileio.c comment spelling fix 2025-07-13 21:09:39 -07:00
Paul Eggert
4c4f68be4b insert-file-contents byte vs char confusion
* src/fileio.c (Finsert_file_contents): Use del_range_byte,
not del_range_1, since we are passing byte counts, not
character counts.  Problem reported by Pip Cet (Bug#77315).
2025-07-13 21:09:39 -07:00
Paul Eggert
61a8ce0280 Fix insert-file-contents overlap calculation
* src/fileio.c (Finsert_file_contents): Overlap is impossible, so
omit incorrect overflow adjustments that caused later index
calculations to go off the rails (Bug#77315).  Change a ‘ZV_BYTE’
to ‘same_at_end’ for clarity; they have the same value here.
2025-07-13 21:09:39 -07:00
Paul Eggert
e98da5cc3f insert-file-contents do not rely on st_size
This fix was prompted by Bug#77315.
* src/fileio.c (Finsert_file_contents): Do not rely on st_size for
anything other than a hint about the file size.  Trust only the
file size as revealed by a read that returns 0.
2025-07-13 21:09:39 -07:00
Paul Eggert
de0bb2e059 insert-file-contents file size hint improvement
* src/fileio.c (Finsert_file_contents): When reading yields 0,
update the file size hint to match.  This should improve its
accuracy.
2025-07-13 21:09:39 -07:00
Paul Eggert
aee9b59831 insert-file-contents file end EOF fixes
* src/fileio.c (Finsert_file_contents):
When counting bytes at file end, don’t trust lseek to seek
to the end of the file.  Instead, read a bit after lseeking,
to make sure we get to the end, give up if we don’t get to EOF.
This works around problems on /proc filesystems
where lseek pretends the file is empty.
Update file_size_hint when reaching EOF.
2025-07-13 21:09:39 -07:00
Paul Eggert
56091b6d5c Fix insert-file-contents integer overflows
* src/fileio.c (Finsert_file_contents): Change ‘total’ from
ptrdiff_t to off_t since it might not fit in ptrdiff_t.
Check for overflow when estimating the insertion size.
2025-07-13 21:09:39 -07:00
Paul Eggert
e6c6847973 Remove ineffective overflow check
* src/fileio.c (Finsert_file_contents): Remove check for overflow.
The overflow is not possible, and the check was incorrectly
written and would not have caught it anyway.
2025-07-13 21:09:39 -07:00