Subject: bug#66313: closed (Re: bug#66313: Acknowledgement (29.1.50; process-mark sometimes does not yield the expected value))

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 07 Oct 2023 15:04:03 +0000

Your bug report

#66313: 29.1.50; process-mark sometimes does not yield the expected value

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
66313: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66313
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#66313: Acknowledgement (29.1.50; process-mark sometimes does not yield the expected value)
From: Eli Zaretskii <[email-masked]>
To: Markus Triska <[email-masked]>
Cc: [email-masked]
Date: Sat, 07 Oct 2023 18:03:27 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Markus Triska <[email-masked]>
> Date: Sat, 07 Oct 2023 16:15:38 +0200
> 
> 
> I have reduced this to the following problem: set-process-buffer
> sometimes unexpectedly changes the position of process-mark.
> 
> For a shorter test case that exhibits the issue, please download
> process-mark.el from:
> 
>     https://www.metalevel.at/ei/process-mark/process-mark.el
> 
> Its contents are:
> 
>    (let ((p (start-process "bash" nil "bash")))
>      (set-marker (process-mark p) (point))
>      (set-process-buffer p (current-buffer))
>      (marker-position (process-mark p)))
> 
>    (message "hello there!")
> 
> Place point after the first form in the file, and evaluate the form with
> C-x C-e.
> 
> The expected result is: 165. It is obtained with Emacs 26.1 and several
> later versions.
> 
> However, with the Emacs version I used to report this problem, the
> result I get is unexpectedly: 192.
> 
> I would greatly appreciate if the previous behaviour could be restored.

I fixed this on the emacs-29 branch, but please note that your code is
quite problematic: the set-marker call associates the process-mark
marker with the current buffer, but the process's buffer is still nil.
So between the 2nd and the 3rd line of your snippet, you have a window
where the process-mark points to a buffer different from the buffer
associated with the process.  You should do this the other way around:
first set the process-buffer, and then update the process-mark
position to a position in that buffer.

So in a nutshell, your code was hitting "undefined behavior", and
expecting it to be bug-for-bug compatible with old versions of Emacs
was not really reasonable.

Subject: 29.1.50; process-mark sometimes does not yield the expected value
From: Markus Triska <[email-masked]>
To: [email-masked]
Date: Mon, 02 Oct 2023 22:00:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

To reproduce this issue, please do the following:

  1) download ediprolog.el with:

     $ wget https://www.metalevel.at/ediprolog/ediprolog.el

  2) download simulans_a.sh with:

     $ wget https://www.metalevel.at/ei/process-mark/simulans_a.sh   

     This shell file will illustrate this issue in lieu of Scryer Prolog.

  3) make simulans_a.sh executable with:

     $ chmod +x simulans_a.sh

  4) create test1.pl and test2.pl, with the following commands:

     $ echo "?- X = a." > test1.pl
     $ echo "?- X = a." > test2.pl

  5) launch Emacs with:

     $ emacs -Q -l ediprolog.el --eval "(add-to-list 'exec-path \".\")" \
         --eval '(setq ediprolog-program "simulans_a.sh")' test1.pl test2.pl

Emacs now shows two windows, test2.pl in the upper window, and
test1.pl in the lower window. Initially, test2.pl is the selected
window, and point is on the query "?- X = a.". Now do:

    M-x ediprolog-dwim RET

As expected, the buffer will now consist of the following text:

    ?- X = a.
    %@    X = a.

Now, switch to the below window (test1.pl) with:

    C-x o

And there, do:

    M-x ediprolog-dwim RET

Unexpectedly, the buffer will consist of the following text:

    ?- X = a.
    %@ 
       X = a.

The newline after %@ is unexpected! The expected buffer content is:

    ?- X = a.
    %@ X = a.

This already illustrates a difference compared to Emacs 26.1, 27.1,
and other versions, which behave as expected.

To see more differences, switch back to the above window (test2.pl):

    C-x o

And move point to the first line (the line of the query) with:

    C-p

And then do:

    M-x ediprolog-dwim RET

Unexpectedly, the buffer will consist of the following text:

    ?- X = a.
    %@ 
    %@    X = a.
       X = a.

The expected text (at this state) is:

    ?- X = a.
    %@    X = a.
    %@    X = a.

Repeat these steps to see more unexpected behaviour. It seems that
process-mark sometimes does not yield the expected position.

ediprolog.el goes to the process-mark in line 431, which reads:

         (goto-char (process-mark ediprolog-process))

In all cases above, the process-mark is expected to yield the value 14
at this point of the program, but it does not always yield this value.

If possible, could you please restore the behaviour that earlier Emacs
versions exhibit in these examples?

Thank you and all the best,
Markus

In GNU Emacs 29.1.50 (build 1, x86_64-apple-darwin18.2.0, X toolkit,
 cairo version 1.17.6, Xaw scroll bars) of 2023-09-14 built on
 mac
Repository revision: f0a89fa1d0e5b380ecadb57052c95b31110c0323
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
System Description:  Mac OS X 10.14.2

Configured using:
 'configure --with-x-toolkit=lucid --without-ns
 CFLAGS=-I/opt/local/include/ LDFLAGS=-L/opt/local/lib
 --with-xpm=ifavailable'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBXML2 MODULES NOTIFY KQUEUE PDUMPER PNG RSVG SQLITE3 THREADS
TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 LUCID
ZLIB